Skip to content

Commit

Permalink
[refactor] 메소드 분리 (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarlgnszx committed Nov 18, 2024
1 parent 75c32fc commit 8b3c339
Showing 1 changed file with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundMain;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.UserActiveInfo;
import org.sopt.app.application.playground.dto.PostWithMemberInfo;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.exception.UnauthorizedException;
import org.sopt.app.common.response.ErrorCode;
Expand Down Expand Up @@ -202,33 +203,39 @@ public List<RecentPostsResponse> getRecentPosts(String playgroundToken) {
}

public List<RecentPostsResponse> getRecentPostsWithMemberInfo(String playgroundToken) {
final Map<String, String> accessToken = createAuthorizationHeaderByUserPlaygroundToken(playgroundToken);
List<RecentPostsResponse> recentPosts = getRecentPosts(playgroundToken);

for (RecentPostsResponse post : recentPosts) {
Long postId = post.getId();
PlayGroundPostDetailResponse postDetail = playgroundClient.getPlayGroundPostDetail(accessToken, postId);
if (postDetail.member() != null) {
String profileImage = postDetail.member().profileImage();
String name = postDetail.member().name();
post.setProfileImage(profileImage);
post.setName(name);
} else if (postDetail.anonymousProfile() != null) {
String profileImage = postDetail.anonymousProfile().profileImgUrl();
String name = postDetail.anonymousProfile().nickname();
post.setProfileImage(profileImage);
post.setName(name);
}

}
return recentPosts;
return getPostsWithMemberInfo(playgroundToken, recentPosts);
}

public List<EmploymentPostResponse> getPlaygroundEmploymentPost(String accessToken) {
Map<String, String> requestHeader = createAuthorizationHeaderByUserPlaygroundToken(accessToken);
PlayGroundEmploymentResponse postInfo = playgroundClient.getPlaygroundEmploymentPost(requestHeader,16,10,0);
return postInfo.posts().stream()
.map(EmploymentPostResponse::of)
.collect(Collectors.toList());
.map(EmploymentPostResponse::of).toList();
}

public List<EmploymentPostResponse> getPlaygroundEmploymentPostWithMemberInfo(String playgroundToken) {
List<EmploymentPostResponse> employmentPosts = getPlaygroundEmploymentPost(playgroundToken);
return getPostsWithMemberInfo(playgroundToken, employmentPosts);
}

private <T extends PostWithMemberInfo> void addMemberInfoToPost(T post, PlayGroundPostDetailResponse postDetail) {
if (postDetail.member() != null) {
post.setProfileImage(postDetail.member().profileImage());
post.setName(postDetail.member().name());
} else if (postDetail.anonymousProfile() != null) {
post.setProfileImage(postDetail.anonymousProfile().profileImgUrl());
post.setName(postDetail.anonymousProfile().nickname());
}
}

private <T extends PostWithMemberInfo> List<T> getPostsWithMemberInfo(String playgroundToken, List<T> posts) {
final Map<String, String> accessToken = createAuthorizationHeaderByUserPlaygroundToken(playgroundToken);
for (T post : posts) {
Long postId = post.getId();
PlayGroundPostDetailResponse postDetail = playgroundClient.getPlayGroundPostDetail(accessToken, postId);
addMemberInfoToPost(post, postDetail);
}
return posts;
}
}

0 comments on commit 8b3c339

Please sign in to comment.