diff --git a/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java index 57a124c8..0b5e8c3f 100755 --- a/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java @@ -4,6 +4,7 @@ import static org.sopt.app.application.playground.PlaygroundHeaderCreator.createDefaultHeader; import io.jsonwebtoken.ExpiredJwtException; +import jakarta.persistence.EntityNotFoundException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -19,6 +20,7 @@ import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; import org.sopt.app.application.playground.dto.PlayGroundEmploymentResponse; import org.sopt.app.application.playground.dto.PlayGroundPostCategory; +import org.sopt.app.application.playground.dto.PlayGroundPostDetailResponse; import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPost; import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPostResponse; import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.ActiveUserIds; @@ -29,6 +31,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; @@ -199,12 +202,41 @@ public List getRecentPosts(String playgroundToken) { .join(); } } + + public List getRecentPostsWithMemberInfo(String playgroundToken) { + List recentPosts = getRecentPosts(playgroundToken); + return getPostsWithMemberInfo(playgroundToken, recentPosts); + } public List getPlaygroundEmploymentPost(String accessToken) { Map 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 getPlaygroundEmploymentPostWithMemberInfo(String playgroundToken) { + List employmentPosts = getPlaygroundEmploymentPost(playgroundToken); + return getPostsWithMemberInfo(playgroundToken, employmentPosts); + } + + private T addMemberInfoToPost(T post, PlayGroundPostDetailResponse postDetail) { + 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()); + } + throw new EntityNotFoundException("Member not found"); + } + + private List getPostsWithMemberInfo(String playgroundToken, List posts) { + final Map accessToken = createAuthorizationHeaderByUserPlaygroundToken(playgroundToken); + List mutablePosts = new ArrayList<>(); + for (T post : posts) { + Long postId = post.getId(); + PlayGroundPostDetailResponse postDetail = playgroundClient.getPlayGroundPostDetail(accessToken, postId); + mutablePosts.add(addMemberInfoToPost(post, postDetail)); + } + return mutablePosts; } } diff --git a/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java b/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java index 66edf17c..4cfd98f5 100755 --- a/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java +++ b/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java @@ -8,6 +8,7 @@ import java.util.Map; import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; import org.sopt.app.application.playground.dto.PlayGroundEmploymentResponse; +import org.sopt.app.application.playground.dto.PlayGroundPostDetailResponse; import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPostResponse; import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.ActiveUserIds; import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.OwnPlaygroundProfile; @@ -61,4 +62,8 @@ PlayGroundEmploymentResponse getPlaygroundEmploymentPost(@HeaderMap Map headers, + @Param Long postId); } diff --git a/src/main/java/org/sopt/app/application/playground/dto/PlayGroundPostDetailResponse.java b/src/main/java/org/sopt/app/application/playground/dto/PlayGroundPostDetailResponse.java new file mode 100644 index 00000000..94f48aec --- /dev/null +++ b/src/main/java/org/sopt/app/application/playground/dto/PlayGroundPostDetailResponse.java @@ -0,0 +1,18 @@ +package org.sopt.app.application.playground.dto; + +public record PlayGroundPostDetailResponse( + Member member, AnonymousProfile anonymousProfile +) { + public record Member( + String name, + String profileImage + ) { + } + + public record AnonymousProfile( + String nickname, + String profileImgUrl + ) { + } + +} \ No newline at end of file diff --git a/src/main/java/org/sopt/app/application/playground/dto/PostWithMemberInfo.java b/src/main/java/org/sopt/app/application/playground/dto/PostWithMemberInfo.java new file mode 100644 index 00000000..c55859c0 --- /dev/null +++ b/src/main/java/org/sopt/app/application/playground/dto/PostWithMemberInfo.java @@ -0,0 +1,6 @@ +package org.sopt.app.application.playground.dto; + +public interface PostWithMemberInfo { + Object withMemberDetail(String name, String profileImage); + Long getId(); +} \ No newline at end of file diff --git a/src/main/java/org/sopt/app/facade/HomeFacade.java b/src/main/java/org/sopt/app/facade/HomeFacade.java index 34d8e6ff..1902adc1 100755 --- a/src/main/java/org/sopt/app/facade/HomeFacade.java +++ b/src/main/java/org/sopt/app/facade/HomeFacade.java @@ -73,18 +73,11 @@ private boolean isServiceVisibleToUser(AppServiceInfo appServiceInfo, User user) } public List getRecentPosts(User user) { - return playgroundAuthService.getRecentPosts(user.getPlaygroundToken()).stream() - .map(post -> RecentPostsResponse.builder() - .id(post.getId()) - .title(post.getTitle()) - .category(post.getCategory()) - .isHotPost(post.isHotPost()) - .build() - ).toList(); + return playgroundAuthService.getRecentPostsWithMemberInfo(user.getPlaygroundToken()); } public List getHomeEmploymentPost(User user) { - return playgroundAuthService.getPlaygroundEmploymentPost(user.getPlaygroundToken()); + return playgroundAuthService.getPlaygroundEmploymentPostWithMemberInfo(user.getPlaygroundToken()); } } diff --git a/src/main/java/org/sopt/app/presentation/home/HomeController.java b/src/main/java/org/sopt/app/presentation/home/HomeController.java index 21159809..8729ba33 100644 --- a/src/main/java/org/sopt/app/presentation/home/HomeController.java +++ b/src/main/java/org/sopt/app/presentation/home/HomeController.java @@ -56,7 +56,7 @@ public ResponseEntity> getAppService( } - @Operation(summary = "최근 채용탭 10개 조회") + @Operation(summary = "최근 게시물 카테고리별 조회") @ApiResponses({ @ApiResponse(responseCode = "200", description = "success"), @ApiResponse(responseCode = "401", description = "token error", content = @Content), @@ -70,6 +70,7 @@ public ResponseEntity> getRecentPost( homeFacade.getRecentPosts(user)); } + @Operation(summary = "최근 채용탭 10개 조회") @ApiResponses({ @ApiResponse(responseCode = "200", description = "success"), @ApiResponse(responseCode = "401", description = "token error", content = @Content), diff --git a/src/main/java/org/sopt/app/presentation/home/response/EmploymentPostResponse.java b/src/main/java/org/sopt/app/presentation/home/response/EmploymentPostResponse.java index 5630b159..6f1c01e0 100644 --- a/src/main/java/org/sopt/app/presentation/home/response/EmploymentPostResponse.java +++ b/src/main/java/org/sopt/app/presentation/home/response/EmploymentPostResponse.java @@ -1,18 +1,25 @@ package org.sopt.app.presentation.home.response; import java.util.List; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import org.sopt.app.application.playground.dto.PlayGroundEmploymentResponse.EmploymentPost; +import org.sopt.app.application.playground.dto.PostWithMemberInfo; @Getter @Builder -public class EmploymentPostResponse { - private final Long id; - private final String categoryName; - private final String title; - private final String content; - private final List images; +@AllArgsConstructor +@NoArgsConstructor +public class EmploymentPostResponse implements PostWithMemberInfo { + private Long id; + private String categoryName; + private String profileImage; + private String name; + private String title; + private String content; + private List images; public static EmploymentPostResponse of(EmploymentPost employmentPost) { return EmploymentPostResponse.builder() @@ -23,4 +30,16 @@ public static EmploymentPostResponse of(EmploymentPost employmentPost) { .images(employmentPost.images()) .build(); } + + public EmploymentPostResponse withMemberDetail(String name, String profileImage) { + return EmploymentPostResponse.builder() + .id(this.id) + .categoryName(this.categoryName) + .name(name) + .profileImage(profileImage) + .title(this.title) + .content(this.content) + .images(this.images) + .build(); + } } \ No newline at end of file diff --git a/src/main/java/org/sopt/app/presentation/home/response/RecentPostsResponse.java b/src/main/java/org/sopt/app/presentation/home/response/RecentPostsResponse.java index d6dbcf83..207f85f3 100644 --- a/src/main/java/org/sopt/app/presentation/home/response/RecentPostsResponse.java +++ b/src/main/java/org/sopt/app/presentation/home/response/RecentPostsResponse.java @@ -2,21 +2,25 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPostResponse; +import org.sopt.app.application.playground.dto.PostWithMemberInfo; -@Data @Builder -@NoArgsConstructor @AllArgsConstructor -public class RecentPostsResponse { +@Getter +@NoArgsConstructor +public class RecentPostsResponse implements PostWithMemberInfo { private Long id; private String title; + private String profileImage; + private String name; private String category; private String content; - private boolean isHotPost; - + private Boolean isHotPost; + + public static RecentPostsResponse of(PlaygroundPostResponse playgroundPostResponse) { return RecentPostsResponse.builder() .id(playgroundPostResponse.postId()) @@ -26,4 +30,17 @@ public static RecentPostsResponse of(PlaygroundPostResponse playgroundPostRespon .isHotPost(true) .build(); } + + public RecentPostsResponse withMemberDetail(String name, String profileImage) { + return RecentPostsResponse.builder() + .id(this.id) + .title(this.title) + .profileImage(profileImage) + .name(name) + .category(this.category) + .content(this.content) + .isHotPost(this.isHotPost) + .build(); + } + } \ No newline at end of file