From 87623db4e7c2f9f93885615679cfd33d8a424b28 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Mon, 20 May 2024 22:18:09 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:sparkles:=20Feat:=20=EC=9D=B8=EA=B8=B0=20?= =?UTF-8?q?=EC=82=AC=EC=9E=A5=EB=8B=98=20=ED=94=BC=EB=93=9C=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/TheGoods/converter/.gitkeep | 0 .../repository/post/PostRepository.java | 7 ++- .../PostService/PostCommandService.java | 2 - .../PostService/PostCommandServiceImpl.java | 30 +++++---- .../service/PostService/PostQueryService.java | 5 +- .../PostService/PostQueryServiceImpl.java | 9 ++- .../web/controller/PostController.java | 63 +++++++++---------- .../web/dto/post/PostResponseDto.java | 49 +++++---------- 8 files changed, 77 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/com/umc/TheGoods/converter/.gitkeep diff --git a/src/main/java/com/umc/TheGoods/converter/.gitkeep b/src/main/java/com/umc/TheGoods/converter/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/com/umc/TheGoods/repository/post/PostRepository.java b/src/main/java/com/umc/TheGoods/repository/post/PostRepository.java index f54e5fac..fd9b720e 100644 --- a/src/main/java/com/umc/TheGoods/repository/post/PostRepository.java +++ b/src/main/java/com/umc/TheGoods/repository/post/PostRepository.java @@ -5,8 +5,9 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import java.util.List; + public interface PostRepository extends JpaRepository { - //Page getPostsOrderByLikes(Pageable pageable); @Modifying(clearAutomatically = true) @Query("UPDATE Post p SET p.likesCount = p.likesCount +1 WHERE p.id= :postId") @@ -16,5 +17,7 @@ public interface PostRepository extends JpaRepository { @Query("update Post p SET p.likesCount = p.likesCount -1 WHERE p.id= :postId") void updateUnlikeCount(Long postId); - + @Modifying(clearAutomatically = true) + @Query("SELECT p FROM Post p ORDER BY p.likesCount DESC") + List findAllByOrderByLikesCountDesc(); } diff --git a/src/main/java/com/umc/TheGoods/service/PostService/PostCommandService.java b/src/main/java/com/umc/TheGoods/service/PostService/PostCommandService.java index 422c4baa..2ae5c0c5 100644 --- a/src/main/java/com/umc/TheGoods/service/PostService/PostCommandService.java +++ b/src/main/java/com/umc/TheGoods/service/PostService/PostCommandService.java @@ -26,6 +26,4 @@ public interface PostCommandService { void updateComment(Member member, Long postId, Long commentId, PostRequestDto.UpdateCommentDTO request); void likeComment(Member member, Long commentId); - - } diff --git a/src/main/java/com/umc/TheGoods/service/PostService/PostCommandServiceImpl.java b/src/main/java/com/umc/TheGoods/service/PostService/PostCommandServiceImpl.java index 5c4632c3..30c6f4fa 100644 --- a/src/main/java/com/umc/TheGoods/service/PostService/PostCommandServiceImpl.java +++ b/src/main/java/com/umc/TheGoods/service/PostService/PostCommandServiceImpl.java @@ -43,30 +43,30 @@ public class PostCommandServiceImpl implements PostCommandService { @Override public void follow(Long followingId, Member follower) { - if(followingId.equals(follower.getId())){ + if (followingId.equals(follower.getId())) { throw new PostHandler(ErrorStatus.POST_SELF_FOLLOW); } - Optional check = followRepository.findByFollowingIdAndFollowerId(followingId,follower.getId()); - if(!check.isEmpty()){ + Optional check = followRepository.findByFollowingIdAndFollowerId(followingId, follower.getId()); + if (!check.isEmpty()) { throw new PostHandler(ErrorStatus.POST_ALREADY_FOLLOW); } - Member following = memberRepository.findById(followingId).orElseThrow(()->new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - Follow follow = PostConverter.toFollow(follower,following); + Member following = memberRepository.findById(followingId).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + Follow follow = PostConverter.toFollow(follower, following); followRepository.save(follow); } @Override public void deleteFollow(Long followingId, Long followerId) { - Follow follow = followRepository.findByFollowingIdAndFollowerId(followingId,followerId).orElseThrow(() -> new PostHandler(ErrorStatus.POST_FOLLOW_NOT_FOUND)); + Follow follow = followRepository.findByFollowingIdAndFollowerId(followingId, followerId).orElseThrow(() -> new PostHandler(ErrorStatus.POST_FOLLOW_NOT_FOUND)); followRepository.delete(follow); } @Override public void registerPost(Member member, String content, List multipartFileList) { - Post post = PostConverter.toPost(member,content); + Post post = PostConverter.toPost(member, content); postRepository.save(post); if (multipartFileList != null) { @@ -84,7 +84,7 @@ public void registerPost(Member member, String content, List mult } @Override - public void updatePost(Member member,Long postId, String content, List multipartFileList) { + public void updatePost(Member member, Long postId, String content, List multipartFileList) { Post post = postRepository.findById(postId).orElseThrow(() -> new PostHandler(ErrorStatus.POST_NOT_FOUND)); post.updatePost(content); @@ -104,7 +104,6 @@ public void updatePost(Member member,Long postId, String content, List new PostHandler(ErrorStatus.POST_NOT_FOUND)); Optional postLike = postLikeRepository.findByMember_IdAndPost_Id(member.getId(), postId); - if(postLike.isPresent()) { + if (postLike.isPresent()) { if (post.getLikesCount() > 0) { postRepository.updateUnlikeCount(postId); } postLikeRepository.delete(postLike.get()); - }else { + } else { postRepository.updateLikeCount(post.getId()); postLikeRepository.save(PostConverter.toPostLike(member, post)); @@ -154,7 +153,7 @@ public void uploadComment(Member member, Long postId, PostRequestDto.CommentDTO public void updateComment(Member member, Long postId, Long commentId, PostRequestDto.UpdateCommentDTO request) { Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new PostHandler(ErrorStatus.POST_COMMENT_NOT_FOUND)); - if(!comment.getMember().equals(member)){ + if (!comment.getMember().equals(member)) { throw new PostHandler(ErrorStatus.POST_COMMENT_NOT_UPDATE); } @@ -169,15 +168,14 @@ public void likeComment(Member member, Long commentId) { Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new PostHandler(ErrorStatus.POST_COMMENT_NOT_FOUND)); Optional commentLike = commentLikeRepository.findByMember_IdAndComment_Id(member.getId(), commentId); - if(commentLike.isPresent()){ - if(comment.getLikesCount() > 0){ + if (commentLike.isPresent()) { + if (comment.getLikesCount() > 0) { commentRepository.updateUnlikeCount(commentId); } commentLikeRepository.delete(commentLike.get()); - }else { + } else { commentRepository.updateLikeCount(commentId); commentLikeRepository.save(PostConverter.toCommentLike(member, comment)); } } - } diff --git a/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java b/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java index 76b828cb..76382c4f 100644 --- a/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java +++ b/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java @@ -5,5 +5,8 @@ import java.util.List; public interface PostQueryService { - List getPostsOrderByLike(); + + static List getAllPostsSortedByLikes() { + return null; + } } diff --git a/src/main/java/com/umc/TheGoods/service/PostService/PostQueryServiceImpl.java b/src/main/java/com/umc/TheGoods/service/PostService/PostQueryServiceImpl.java index 1b15b550..01768ce0 100644 --- a/src/main/java/com/umc/TheGoods/service/PostService/PostQueryServiceImpl.java +++ b/src/main/java/com/umc/TheGoods/service/PostService/PostQueryServiceImpl.java @@ -1,5 +1,6 @@ package com.umc.TheGoods.service.PostService; +import com.umc.TheGoods.domain.community.Post; import com.umc.TheGoods.repository.post.PostRepository; import com.umc.TheGoods.web.dto.post.PostResponseDto; import lombok.RequiredArgsConstructor; @@ -8,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.stream.Collectors; @Slf4j @Service @@ -18,7 +20,10 @@ public class PostQueryServiceImpl implements PostQueryService { private final PostRepository postRepository; @Override - public List getPostsOrderByLike() { - return null; + public List getAllPostsSortedByLikes() { + List posts = postRepository.findAllByOrderByLikesCountDesc(); + return posts.stream() + .map(PostResponseDto::new) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/umc/TheGoods/web/controller/PostController.java b/src/main/java/com/umc/TheGoods/web/controller/PostController.java index 95a32c49..2fe544ed 100644 --- a/src/main/java/com/umc/TheGoods/web/controller/PostController.java +++ b/src/main/java/com/umc/TheGoods/web/controller/PostController.java @@ -4,7 +4,6 @@ import com.umc.TheGoods.apiPayload.code.status.ErrorStatus; import com.umc.TheGoods.apiPayload.code.status.SuccessStatus; import com.umc.TheGoods.apiPayload.exception.handler.MemberHandler; -import com.umc.TheGoods.domain.member.Auth; import com.umc.TheGoods.domain.member.Member; import com.umc.TheGoods.service.MemberService.MemberQueryService; import com.umc.TheGoods.service.PostService.PostCommandService; @@ -15,7 +14,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import net.bytebuddy.build.Plugin; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -32,26 +30,33 @@ public class PostController { private final MemberQueryService memberQueryService; final PostCommandService postCommandService; - @GetMapping("/popular") - @Operation(summary = "인기 사장님 피드 전체 조회 API", description = "포스트의 기본 디폴트 정렬로, 좋아요 순으로 내림차순 정렬합니다. \n\n") + @GetMapping("/") + @Operation(summary = "인기 사장님 피드 전체 조회 API", description = "포스트의 기본 디폴트 정렬로, 좋아요 순으로 내림차순 정렬합니다.") @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON404", description = "Fail, 이미 존재하는 이름입니다.") + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON404", description = "Fail, 실패") }) - public ApiResponse posts(@RequestParam("like") boolean like) { - return ApiResponse.onSuccess((PostResponseDto.PostListViewDto) queryService.getPostsOrderByLike()); + public ApiResponse getPostByLikes() { + List posts = PostQueryService.getAllPostsSortedByLikes(); + return ApiResponse.of(SuccessStatus.POST_GET_SUCCESS, new PostResponseDto.PostListViewDto(posts)); } - @GetMapping("/follow") + @GetMapping("/following/all") @Operation(summary = "팔로잉 중인 피드 전체 조회 API") public ApiResponse following(@RequestParam("like") boolean like) { return null; } + @GetMapping("/{postId}") + @Operation(summary = "피드 상세 조회 API", description = "조회 하고자 하는 postId 값이 필요합니다.") + public ApiResponse post(@PathVariable Long postId) { + return null; + } + @PostMapping("/follow/{followingId}") @Operation(summary = "팔로우 API", description = "팔로우 하려는 사람의 id를 request로 주시면 됩니다.") public ApiResponse follow(Authentication authentication, - @PathVariable(name = "followingId") Long followingId){ + @PathVariable(name = "followingId") Long followingId) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); //팔로우 기능 @@ -63,17 +68,12 @@ public ApiResponse follow(Authentication authentication, @PostMapping("/follow/{followingId}/delete") @Operation(summary = "팔로우 취소 API", description = "팔로우 취소하려는 사람의 id를 request로 주시면 됩니다.") public ApiResponse deleteFollow(Authentication authentication, - @PathVariable(name = "followingId") Long followingId){ + @PathVariable(name = "followingId") Long followingId) { Long memberId = Long.valueOf(authentication.getName().toString()); //팔로우 취소 기능 - postCommandService.deleteFollow(followingId,memberId); - return ApiResponse.of(SuccessStatus.POST_DELETE_FOLLOW_SUCCESS,null); - } - - @GetMapping("/{postId}") - public ApiResponse post(@PathVariable Long postId) { - return null; + postCommandService.deleteFollow(followingId, memberId); + return ApiResponse.of(SuccessStatus.POST_DELETE_FOLLOW_SUCCESS, null); } @PostMapping("/") @@ -82,7 +82,7 @@ public ApiResponse registerPost(@RequestPart(value = "content") String conten @RequestPart(value = "postImgList", required = false) List postImgList, Authentication authentication) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - postCommandService.registerPost(member,content,postImgList); + postCommandService.registerPost(member, content, postImgList); return ApiResponse.of(SuccessStatus.POST_UPLOAD_SUCCESS, null); } @@ -94,9 +94,9 @@ public ApiResponse updatePost(@PathVariable(name @RequestPart(value = "postImgList", required = false) List postImgList, Authentication authentication) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - postCommandService.updatePost(member,postId, content,postImgList); + postCommandService.updatePost(member, postId, content, postImgList); - return ApiResponse.of(SuccessStatus.POST_UPDATE_SUCCESS,null); + return ApiResponse.of(SuccessStatus.POST_UPDATE_SUCCESS, null); } @DeleteMapping("/{postId}") @@ -104,7 +104,7 @@ public ApiResponse updatePost(@PathVariable(name public ApiResponse deletePost(@PathVariable(name = "postId") Long postId, Authentication authentication) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - postCommandService.deletePost(member,postId); + postCommandService.deletePost(member, postId); return ApiResponse.of(SuccessStatus.POST_DELETE_SUCCESS, null); } @@ -112,40 +112,39 @@ public ApiResponse deletePost(@PathVariable(name @PostMapping("/{postId}/likes") @Operation(summary = "피드 좋아요 API", description = "postId: 좋아요 누를 피드 id, 한번 누르면 좋아요 두번 누르면 좋아요 취소") public ApiResponse likePost(@PathVariable(name = "postId") Long postId, - Authentication authentication){ + Authentication authentication) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); postCommandService.likePost(member, postId); - return ApiResponse.of(SuccessStatus.POST_LIKE_SUCCESS,null); + return ApiResponse.of(SuccessStatus.POST_LIKE_SUCCESS, null); } @PostMapping("/comment/{commentId}/likes") @Operation(summary = "댓글 좋아요 API", description = "commentId: 좋아요 누를 댓글 id, 한번 누르면 좋아요 두번 누르면 좋아요 취소") public ApiResponse likeComment(@PathVariable(name = "commentId") Long commentId, - Authentication authentication){ + Authentication authentication) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); postCommandService.likeComment(member, commentId); return ApiResponse.of(SuccessStatus.POST_COMMENT_LIKE_SUCCESS, null); } - @PostMapping("/{postId}/comment") @Operation(summary = "피드 댓글 등록 API", description = "parentId: 댓글인 경우 null 대댓글이라면 작성하려는 댓글 id," + - "postId: 댓글 등록할 피드, content: 댓글 내용 ") + "postId: 댓글 등록할 피드, content: 댓글 내용 ") public ApiResponse uploadComment(@PathVariable(name = "postId") Long postId, Authentication authentication, - @RequestBody PostRequestDto.CommentDTO request){ + @RequestBody PostRequestDto.CommentDTO request) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - postCommandService.uploadComment(member,postId, request); + postCommandService.uploadComment(member, postId, request); - return ApiResponse.of(SuccessStatus.POST_COMMENT_SUCCESS,null); + return ApiResponse.of(SuccessStatus.POST_COMMENT_SUCCESS, null); } @PutMapping("/{postId}/comment/{commentId}") @Operation(summary = "피드 댓글 수정 API", description = "postId: 댓글 수정할 피드, commentId : 수정할 댓글, content: 댓글 내용") - public ApiResponse updateComment(@PathVariable(name ="postId") Long postId, - @PathVariable(name ="commentId") Long commentId, + public ApiResponse updateComment(@PathVariable(name = "postId") Long postId, + @PathVariable(name = "commentId") Long commentId, @RequestBody PostRequestDto.UpdateCommentDTO requet, Authentication authentication) { Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); @@ -156,6 +155,4 @@ public ApiResponse updateComment(@PathVariable(name ="postId") Long postId, } - - } diff --git a/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java b/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java index 19bf3d46..78892e8d 100644 --- a/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java +++ b/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java @@ -1,47 +1,32 @@ package com.umc.TheGoods.web.dto.post; -import com.umc.TheGoods.domain.images.PostImg; -import lombok.AllArgsConstructor; -import lombok.Builder; +import com.umc.TheGoods.domain.community.Post; import lombok.Getter; -import lombok.NoArgsConstructor; -import java.time.LocalDateTime; import java.util.List; +@Getter public class PostResponseDto { + private final Long id; + private final String content; + private final Long viewCount; + private final Integer likesCount; + private final Long memberId; - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class PostViewDto { - Long id; - String title; - String content; - LocalDateTime createdDate; - LocalDateTime updatedDate; - Integer likes; - List images; - Long writerId; + public PostResponseDto(Post post) { + this.id = post.getId(); + this.content = post.getContent(); + this.viewCount = post.getViewCount(); + this.likesCount = post.getLikesCount(); + this.memberId = post.getMember().getId(); } - @Builder @Getter - @NoArgsConstructor - @AllArgsConstructor public static class PostListViewDto { - Integer offset; - Integer size; - List posts; - } + private final List posts; - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class PostStatusDto { - Long postId; - String status; + public PostListViewDto(List posts) { + this.posts = posts; + } } } From cd9378a84b0a35e08b6ee63d526eb0cd636689c4 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Mon, 20 May 2024 22:18:48 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:sparkles:=20Feat:=20=ED=94=BC=EB=93=9C=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C(=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94=EC=88=9C)=20=EC=9D=91=EB=8B=B5=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TheGoods/apiPayload/code/status/SuccessStatus.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/umc/TheGoods/apiPayload/code/status/SuccessStatus.java b/src/main/java/com/umc/TheGoods/apiPayload/code/status/SuccessStatus.java index 670af41e..fa4807b9 100644 --- a/src/main/java/com/umc/TheGoods/apiPayload/code/status/SuccessStatus.java +++ b/src/main/java/com/umc/TheGoods/apiPayload/code/status/SuccessStatus.java @@ -14,7 +14,7 @@ public enum SuccessStatus implements BaseCode { //Member MEMBER_DELETE_SUCCESS(HttpStatus.OK, "MEMBER2001", "회원 탈퇴 성공입니다."), MEMBER_NOTIFICATION_UPDATE(HttpStatus.OK, "MEMBER2002", "회원 알림 변경 성공입니다."), - MEMBER_ACCOUNT_UPDATE(HttpStatus.OK,"MEMBER2003", "회원 계좌 변경 성공입니다."), + MEMBER_ACCOUNT_UPDATE(HttpStatus.OK, "MEMBER2003", "회원 계좌 변경 성공입니다."), MEMBER_ACCOUNT_DELETE(HttpStatus.OK, "MEMBER2004", "회원 계좌 삭제 성공입니다."), MEMBER_ADDRESS_DELETE(HttpStatus.OK, "MEMBER2005", "회원 배송지 삭제 성공입니다."), MEMBER_CUSTOM_INFO_UPDATE(HttpStatus.OK, "MEMBER2006", "회원 맞춤 정보 변경 성공입니다."), @@ -32,11 +32,12 @@ public enum SuccessStatus implements BaseCode { POST_LIKE_SUCCESS(HttpStatus.OK, "POST2006", "포스트 좋아요 성공입니다."), POST_DELETE_LIKE_SUCCESS(HttpStatus.OK, "POST2007", "포스트 좋아요 취소 성공입니다."), POST_COMMENT_SUCCESS(HttpStatus.OK, "POST2008", "포스트 댓글 달기 성공입니다."), - POST_DELETE_COMMENT_SUCCESS(HttpStatus.OK,"POST2009", "포스트 댓글 삭제 성공입니다."), + POST_DELETE_COMMENT_SUCCESS(HttpStatus.OK, "POST2009", "포스트 댓글 삭제 성공입니다."), POST_UPDATE_COMMENT_SUCCESS(HttpStatus.OK, "POST2010", "포스트 댓글 수정 성공입니다."), POST_COMMENT_LIKE_SUCCESS(HttpStatus.OK, "POST2011", "포스트 댓글 좋아요 성공입니다."), - POST_DELETE_COMMENT_LIKE_SUCCESS(HttpStatus.OK,"POST2012", "포스트 댓글 좋아요 취소 성공입니다.") - ; + POST_DELETE_COMMENT_LIKE_SUCCESS(HttpStatus.OK, "POST2012", "포스트 댓글 좋아요 취소 성공입니다."), + POST_GET_SUCCESS(HttpStatus.OK, "POST2013", "포스트 좋아요순 전체 조회 성공입니다."); + private final HttpStatus httpStatus; private final String code; From 5e842e40b50edb6607a5956ed7f148602e259a11 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Mon, 20 May 2024 22:28:23 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:recycle:=20Refactor:=20=EC=9D=B8=EA=B8=B0?= =?UTF-8?q?=20=EC=82=AC=EC=9E=A5=EB=8B=98=20=ED=94=BC=EB=93=9C=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/TheGoods/service/PostService/PostQueryService.java | 4 +--- .../java/com/umc/TheGoods/web/controller/PostController.java | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java b/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java index 76382c4f..41d5cf5f 100644 --- a/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java +++ b/src/main/java/com/umc/TheGoods/service/PostService/PostQueryService.java @@ -6,7 +6,5 @@ public interface PostQueryService { - static List getAllPostsSortedByLikes() { - return null; - } + List getAllPostsSortedByLikes(); } diff --git a/src/main/java/com/umc/TheGoods/web/controller/PostController.java b/src/main/java/com/umc/TheGoods/web/controller/PostController.java index 2fe544ed..f78e12cc 100644 --- a/src/main/java/com/umc/TheGoods/web/controller/PostController.java +++ b/src/main/java/com/umc/TheGoods/web/controller/PostController.java @@ -8,6 +8,7 @@ import com.umc.TheGoods.service.MemberService.MemberQueryService; import com.umc.TheGoods.service.PostService.PostCommandService; import com.umc.TheGoods.service.PostService.PostQueryService; +import com.umc.TheGoods.service.PostService.PostQueryServiceImpl; import com.umc.TheGoods.web.dto.post.PostRequestDto; import com.umc.TheGoods.web.dto.post.PostResponseDto; import io.swagger.v3.oas.annotations.Operation; @@ -29,6 +30,7 @@ public class PostController { final PostQueryService queryService; private final MemberQueryService memberQueryService; final PostCommandService postCommandService; + private final PostQueryServiceImpl postQueryServiceImpl; @GetMapping("/") @Operation(summary = "인기 사장님 피드 전체 조회 API", description = "포스트의 기본 디폴트 정렬로, 좋아요 순으로 내림차순 정렬합니다.") @@ -37,7 +39,8 @@ public class PostController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON404", description = "Fail, 실패") }) public ApiResponse getPostByLikes() { - List posts = PostQueryService.getAllPostsSortedByLikes(); + PostQueryService postQueryService = postQueryServiceImpl; + List posts = postQueryService.getAllPostsSortedByLikes(); return ApiResponse.of(SuccessStatus.POST_GET_SUCCESS, new PostResponseDto.PostListViewDto(posts)); } From fb5a63d71c065cac8a902a918d8614cd079df4b2 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Mon, 20 May 2024 22:28:41 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:recycle:=20Refactor:=20PostResponseDto=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/dto/post/PostResponseDto.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java b/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java index 78892e8d..801138d3 100644 --- a/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java +++ b/src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java @@ -1,8 +1,13 @@ package com.umc.TheGoods.web.dto.post; import com.umc.TheGoods.domain.community.Post; +import com.umc.TheGoods.domain.images.PostImg; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; +import java.time.LocalDateTime; import java.util.List; @Getter @@ -29,4 +34,28 @@ public PostListViewDto(List posts) { this.posts = posts; } } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PostViewDto { + Long id; + String title; + String content; + LocalDateTime createdDate; + LocalDateTime updatedDate; + Integer likes; + List images; + Long writerId; + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PostStatusDto { + Long postId; + String status; + } } From a455705e3a7632a26ef7481a9aad327e599a6459 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Mon, 20 May 2024 23:40:03 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:recycle:=20Refactor:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/TheGoods/web/controller/PostController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/umc/TheGoods/web/controller/PostController.java b/src/main/java/com/umc/TheGoods/web/controller/PostController.java index f78e12cc..9ad2958c 100644 --- a/src/main/java/com/umc/TheGoods/web/controller/PostController.java +++ b/src/main/java/com/umc/TheGoods/web/controller/PostController.java @@ -8,7 +8,6 @@ import com.umc.TheGoods.service.MemberService.MemberQueryService; import com.umc.TheGoods.service.PostService.PostCommandService; import com.umc.TheGoods.service.PostService.PostQueryService; -import com.umc.TheGoods.service.PostService.PostQueryServiceImpl; import com.umc.TheGoods.web.dto.post.PostRequestDto; import com.umc.TheGoods.web.dto.post.PostResponseDto; import io.swagger.v3.oas.annotations.Operation; @@ -27,10 +26,9 @@ @Tag(name = "Post", description = "포스트 관련된 API 입니다.") public class PostController { - final PostQueryService queryService; + private final PostQueryService postQueryService; private final MemberQueryService memberQueryService; final PostCommandService postCommandService; - private final PostQueryServiceImpl postQueryServiceImpl; @GetMapping("/") @Operation(summary = "인기 사장님 피드 전체 조회 API", description = "포스트의 기본 디폴트 정렬로, 좋아요 순으로 내림차순 정렬합니다.") @@ -39,7 +37,6 @@ public class PostController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON404", description = "Fail, 실패") }) public ApiResponse getPostByLikes() { - PostQueryService postQueryService = postQueryServiceImpl; List posts = postQueryService.getAllPostsSortedByLikes(); return ApiResponse.of(SuccessStatus.POST_GET_SUCCESS, new PostResponseDto.PostListViewDto(posts)); }