Skip to content

Commit

Permalink
[refactor] 생성자 추가 (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarlgnszx committed Nov 14, 2024
1 parent 2e7faf7 commit b0bccee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,10 @@ public List<RecentPostsResponse> getRecentPosts(String playgroundToken) {
final Map<String, String> accessToken = createAuthorizationHeaderByUserPlaygroundToken(playgroundToken);
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
List<String> categories = List.of("SOPT 활동", "자유", "파트");

CompletableFuture<RecentPostsResponse> hotPostFuture = CompletableFuture.supplyAsync(() -> {
PlaygroundPostResponse hotpost = playgroundClient.getPlaygroundHotPost(accessToken);
return RecentPostsResponse.builder()
.category("HOT")
.isHotPost(true)
.content(hotpost.content())
.title(hotpost.title())
.id(hotpost.postId())
.build();
}, executor);
CompletableFuture<RecentPostsResponse> hotPostFuture = CompletableFuture.supplyAsync(() ->
RecentPostsResponse.of(playgroundClient.getPlaygroundHotPost(accessToken)), executor);
List<CompletableFuture<RecentPostsResponse>> categoryFutures = categories.stream()
.map(category -> CompletableFuture.supplyAsync(() -> {
RecentPostsResponse recentPosts = playgroundClient.getRecentPosts(accessToken, category);
return recentPosts;
}, executor))
.map(category -> CompletableFuture.supplyAsync(() -> playgroundClient.getRecentPosts(accessToken, category), executor))
.toList();
List<CompletableFuture<RecentPostsResponse>> allFutures = new ArrayList<>(categoryFutures);
allFutures.addFirst(hotPostFuture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPostResponse;

@Data
@Builder
Expand All @@ -15,4 +16,14 @@ public class RecentPostsResponse {
private String category;
private String content;
private boolean isHotPost;

public static RecentPostsResponse of(PlaygroundPostResponse playgroundPostResponse) {
return RecentPostsResponse.builder()
.id(playgroundPostResponse.postId())
.title(playgroundPostResponse.title())
.category("HOT")
.content(playgroundPostResponse.content())
.isHotPost(true)
.build();
}
}

0 comments on commit b0bccee

Please sign in to comment.