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 60bca7b4..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; @@ -219,23 +220,23 @@ public List getPlaygroundEmploymentPostWithMemberInfo(St return getPostsWithMemberInfo(playgroundToken, employmentPosts); } - private void addMemberInfoToPost(T post, PlayGroundPostDetailResponse postDetail) { + private T addMemberInfoToPost(T post, PlayGroundPostDetailResponse postDetail) { if (postDetail.member() != null) { - post.setProfileImage(postDetail.member().profileImage()); - post.setName(postDetail.member().name()); + return (T) post.withMemberDetail(postDetail.member().name(), postDetail.member().profileImage()); } else if (postDetail.anonymousProfile() != null) { - post.setProfileImage(postDetail.anonymousProfile().profileImgUrl()); - post.setName(postDetail.anonymousProfile().nickname()); + 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); - addMemberInfoToPost(post, postDetail); + mutablePosts.add(addMemberInfoToPost(post, postDetail)); } - return posts; + return mutablePosts; } } 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 index 9d67e559..c55859c0 100644 --- a/src/main/java/org/sopt/app/application/playground/dto/PostWithMemberInfo.java +++ b/src/main/java/org/sopt/app/application/playground/dto/PostWithMemberInfo.java @@ -1,7 +1,6 @@ package org.sopt.app.application.playground.dto; public interface PostWithMemberInfo { - void setProfileImage(String profileImage); - void setName(String name); + Object withMemberDetail(String name, String profileImage); Long getId(); } \ No newline at end of file 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 204248c4..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,21 +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 +@AllArgsConstructor +@NoArgsConstructor public class EmploymentPostResponse implements PostWithMemberInfo { - private final Long id; - private final String categoryName; + private Long id; + private String categoryName; private String profileImage; private String name; - private final String title; - private final String content; - private final List images; + private String title; + private String content; + private List images; public static EmploymentPostResponse of(EmploymentPost employmentPost) { return EmploymentPostResponse.builder() @@ -27,13 +31,15 @@ public static EmploymentPostResponse of(EmploymentPost employmentPost) { .build(); } - @Override - public void setProfileImage(String profileImage) { - this.profileImage = profileImage; - } - - @Override - public void setName(String name) { - this.name = name; + 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 871a82ad..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 @@ -4,16 +4,14 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPostResponse; import org.sopt.app.application.playground.dto.PostWithMemberInfo; @Builder -@NoArgsConstructor @AllArgsConstructor @Getter +@NoArgsConstructor public class RecentPostsResponse implements PostWithMemberInfo { - @Setter private Long id; private String title; private String profileImage; @@ -21,7 +19,8 @@ public class RecentPostsResponse implements PostWithMemberInfo { private String category; private String content; private Boolean isHotPost; - + + public static RecentPostsResponse of(PlaygroundPostResponse playgroundPostResponse) { return RecentPostsResponse.builder() .id(playgroundPostResponse.postId()) @@ -32,13 +31,16 @@ public static RecentPostsResponse of(PlaygroundPostResponse playgroundPostRespon .build(); } - @Override - public void setProfileImage(String profileImage) { - this.profileImage = profileImage; + 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(); } - @Override - public void setName(String name) { - this.name = name; - } } \ No newline at end of file