Skip to content

Commit

Permalink
[feat] 생성자에 link값 받도록 추가 - #478
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarlgnszx committed Jan 30, 2025
1 parent 3d74498 commit 23c6acf
Showing 1 changed file with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,29 @@ private String convertPlaygroundWebPageUrl(Long postId) {
return playgroundWebPageUrl + "/?feed=" + postId;
}

private String convertCoffeeChatWebPageUrl(Long memberId) {
return playgroundWebPageUrl + "/coffeechat/" + memberId;
}

public boolean isCurrentGeneration(Long generation) {
return generation.equals(currentGeneration);
}

public List<RecentPostsResponse> getRecentPosts(String playgroundToken) {
final Map<String, String> accessToken = createAuthorizationHeaderByUserPlaygroundToken(playgroundToken);
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
List<PlayGroundPostCategory> categories = List.of(PlayGroundPostCategory.SOPT_ACTIVITY, PlayGroundPostCategory.FREE, PlayGroundPostCategory.PART);
CompletableFuture<RecentPostsResponse> hotPostFuture = CompletableFuture.supplyAsync(() ->
RecentPostsResponse.of(playgroundClient.getPlaygroundHotPost(accessToken)), executor);
List<PlayGroundPostCategory> categories = List.of(PlayGroundPostCategory.SOPT_ACTIVITY,
PlayGroundPostCategory.FREE, PlayGroundPostCategory.PART);
CompletableFuture<RecentPostsResponse> hotPostFuture = CompletableFuture.supplyAsync(
() -> playgroundClient.getPlaygroundHotPost(accessToken), executor)
.thenApply(post -> RecentPostsResponse.of(post, convertPlaygroundWebPageUrl(post.postId())));
List<CompletableFuture<RecentPostsResponse>> categoryFutures = categories.stream()
.map(category -> CompletableFuture.supplyAsync(() -> playgroundClient.getRecentPosts(accessToken, category.getDisplayName()), executor))
.toList();
.map(category -> CompletableFuture.supplyAsync(
() -> playgroundClient.getRecentPosts(accessToken, category.getDisplayName()), executor)
.thenApply(post -> {
post.setLink(convertPlaygroundWebPageUrl(post.getId()));
return post;
})).toList();
List<CompletableFuture<RecentPostsResponse>> allFutures = new ArrayList<>(categoryFutures);
allFutures.addFirst(hotPostFuture);
CompletableFuture<Void> allOf = CompletableFuture.allOf(allFutures.toArray(new CompletableFuture[0]));
Expand All @@ -214,22 +224,20 @@ public List<RecentPostsResponse> getRecentPostsWithMemberInfo(String playgroundT

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

public List<CoffeeChatResponse> getCoffeeChatList(String accessToken) {
Map<String, String> headers = PlaygroundHeaderCreator.createAuthorizationHeaderByUserPlaygroundToken(accessToken);
Map<String, String> headers = PlaygroundHeaderCreator.createAuthorizationHeaderByUserPlaygroundToken(
accessToken);
return playgroundClient.getCoffeeChatList(headers).coffeeChatList().stream()
.filter(member -> !member.isBlind())
.map(i -> CoffeeChatResponse.of(i, getCurrentActivity(i)))
.toList();
.map(member -> CoffeeChatResponse.of(member, getCurrentActivity(member), convertCoffeeChatWebPageUrl(member.memberId()))).toList();
}



public List<EmploymentPostResponse> getPlaygroundEmploymentPostWithMemberInfo(String playgroundToken) {
List<EmploymentPostResponse> employmentPosts = getPlaygroundEmploymentPost(playgroundToken);
return getPostsWithMemberInfo(playgroundToken, employmentPosts);
Expand All @@ -239,7 +247,8 @@ private <T extends PostWithMemberInfo> T addMemberInfoToPost(T post, PlayGroundP
if (postDetail.member() != null) {
return (T) post.withMemberDetail(postDetail.member().name(), postDetail.member().profileImage());
} else if (postDetail.anonymousProfile() != null) {
return (T) post.withMemberDetail(postDetail.anonymousProfile().nickname(), postDetail.anonymousProfile().profileImgUrl());
return (T) post.withMemberDetail(postDetail.anonymousProfile().nickname(),
postDetail.anonymousProfile().profileImgUrl());
}
throw new EntityNotFoundException("Member not found");
}
Expand All @@ -261,9 +270,11 @@ private String getCurrentActivity(PlayGroundCoffeeChatResponse playGroundCoffeeC
.findFirst()
.orElse(null);
}

public int getUserSoptLevel(User user) {
final Map<String, String> accessToken = createAuthorizationHeaderByUserPlaygroundToken(user.getPlaygroundToken());
return playgroundClient.getPlayGroundUserSoptLevel(accessToken,user.getPlaygroundId()).soptProjectCount();
final Map<String, String> accessToken = createAuthorizationHeaderByUserPlaygroundToken(
user.getPlaygroundToken());
return playgroundClient.getPlayGroundUserSoptLevel(accessToken, user.getPlaygroundId()).soptProjectCount();
}

public PlaygroundProfile getPlayGroundProfile(String accessToken) {
Expand Down

0 comments on commit 23c6acf

Please sign in to comment.