From 98f27babd7e6c400480b02440284dbadfceba08f Mon Sep 17 00:00:00 2001 From: kkang_h00n Date: Fri, 11 Jul 2025 22:26:43 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Refactor:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swyp/team5/greening/post/service/PostQueryService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/swyp/team5/greening/post/service/PostQueryService.java b/src/main/java/swyp/team5/greening/post/service/PostQueryService.java index 76410d8..f8f9453 100644 --- a/src/main/java/swyp/team5/greening/post/service/PostQueryService.java +++ b/src/main/java/swyp/team5/greening/post/service/PostQueryService.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.Objects; +import java.util.stream.Stream; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -44,7 +45,7 @@ public FindPostResponseDto findPost(Long postId, Long userId) { // 홈 화면 게시글 @Transactional(readOnly = true) public List findLatestPostByCategory(Long userId) { - return List.of(1L, 2L, 3L).stream() + return Stream.of(1L, 2L, 3L) .flatMap(categoryId -> postQueryRepository.findTop6TodayByCategoryWithUserName(userId, categoryId) .stream()) From 7970484a8f32ad614d41e140f54a264dd6622432 Mon Sep 17 00:00:00 2001 From: kkang_h00n Date: Sat, 12 Jul 2025 10:34:04 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Refactor:=20=ED=99=88=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EB=AC=BC=20=EC=A1=B0=ED=9A=8C=20API=20=EC=8A=A4=ED=8E=99=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team5/greening/post/controller/PostController.java | 6 ++---- .../post/domain/repository/PostQueryRepository.java | 5 +---- .../post/dto/response/FindPostPreviewResponseDto.java | 3 +-- .../post/infrastructure/PostJpaQueryRepository.java | 10 +++------- .../team5/greening/post/service/PostQueryService.java | 4 ++-- .../greening/post/controller/PostControllerTest.java | 4 ---- 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/main/java/swyp/team5/greening/post/controller/PostController.java b/src/main/java/swyp/team5/greening/post/controller/PostController.java index bbd0663..2f86682 100644 --- a/src/main/java/swyp/team5/greening/post/controller/PostController.java +++ b/src/main/java/swyp/team5/greening/post/controller/PostController.java @@ -85,10 +85,8 @@ public void deletePost( @Operation(summary = "홈 화면 게시글 미리보기 (카테고리 별 각 6개씩)") @GetMapping("/home") @ResponseStatus(HttpStatus.OK) - public ApiResponseDto> getLatestPosts( - @OptionalLogIn Long userId - ) { - return ApiResponseDto.of(postQueryService.findLatestPostByCategory(userId)); + public ApiResponseDto> getLatestPosts() { + return ApiResponseDto.of(postQueryService.findLatestPostByCategory()); } @Operation(summary = "카테고리별 게시글 목록 조회 (pageNumber는 1부터 시작)") diff --git a/src/main/java/swyp/team5/greening/post/domain/repository/PostQueryRepository.java b/src/main/java/swyp/team5/greening/post/domain/repository/PostQueryRepository.java index a31b6a9..0f7d631 100644 --- a/src/main/java/swyp/team5/greening/post/domain/repository/PostQueryRepository.java +++ b/src/main/java/swyp/team5/greening/post/domain/repository/PostQueryRepository.java @@ -17,10 +17,7 @@ Optional findPost( Long userId ); - List findTop6TodayByCategoryWithUserName( - Long loginUserId, - Long categoryId - ); + List findTop6TodayByCategoryWithUserName(Long categoryId); Page findAllByCategoryWithUserName( Long loginUserId, diff --git a/src/main/java/swyp/team5/greening/post/dto/response/FindPostPreviewResponseDto.java b/src/main/java/swyp/team5/greening/post/dto/response/FindPostPreviewResponseDto.java index 7a587b1..e6afe77 100644 --- a/src/main/java/swyp/team5/greening/post/dto/response/FindPostPreviewResponseDto.java +++ b/src/main/java/swyp/team5/greening/post/dto/response/FindPostPreviewResponseDto.java @@ -12,8 +12,7 @@ public record FindPostPreviewResponseDto( Long likeCount, Long commentCount, LocalDateTime createdAt, - LocalDateTime lastModifiedAt, - boolean isLike + LocalDateTime lastModifiedAt ) { } diff --git a/src/main/java/swyp/team5/greening/post/infrastructure/PostJpaQueryRepository.java b/src/main/java/swyp/team5/greening/post/infrastructure/PostJpaQueryRepository.java index 885223d..1a03b10 100644 --- a/src/main/java/swyp/team5/greening/post/infrastructure/PostJpaQueryRepository.java +++ b/src/main/java/swyp/team5/greening/post/infrastructure/PostJpaQueryRepository.java @@ -39,25 +39,21 @@ Optional findPost( @Override @Query(""" SELECT new swyp.team5.greening.post.dto.response.FindPostPreviewResponseDto( - post.id, post.categoryId, post.userId, user.userName, post.title, c.content, - post.likeCount, post.commentCount, post.createdAt, post.updatedAt, - case when likes.id is not null then true else false end) + post.id, post.categoryId, post.userId, user.userName, post.title, + case when c.type = 'IMAGE' then '이미지' else c.content end, + post.likeCount, post.commentCount, post.createdAt, post.updatedAt) FROM Post post INNER JOIN User user ON user.id = post.userId LEFT JOIN PostContent c ON c.post = post AND c.sequence = 1 - LEFT JOIN Like likes - ON likes.postId = post.id - AND likes.userId = :loginUserId WHERE post.categoryId = :categoryId AND post.state = 'IN_PROGRESS' ORDER BY post.likeCount DESC LIMIT 6 """) List findTop6TodayByCategoryWithUserName( - @Param("loginUserId") Long loginUserId, @Param("categoryId") Long categoryId ); diff --git a/src/main/java/swyp/team5/greening/post/service/PostQueryService.java b/src/main/java/swyp/team5/greening/post/service/PostQueryService.java index f8f9453..b702763 100644 --- a/src/main/java/swyp/team5/greening/post/service/PostQueryService.java +++ b/src/main/java/swyp/team5/greening/post/service/PostQueryService.java @@ -44,10 +44,10 @@ public FindPostResponseDto findPost(Long postId, Long userId) { // 홈 화면 게시글 @Transactional(readOnly = true) - public List findLatestPostByCategory(Long userId) { + public List findLatestPostByCategory() { return Stream.of(1L, 2L, 3L) .flatMap(categoryId -> - postQueryRepository.findTop6TodayByCategoryWithUserName(userId, categoryId) + postQueryRepository.findTop6TodayByCategoryWithUserName(categoryId) .stream()) .toList(); } diff --git a/src/test/java/swyp/team5/greening/post/controller/PostControllerTest.java b/src/test/java/swyp/team5/greening/post/controller/PostControllerTest.java index 025035b..4f2cd9e 100644 --- a/src/test/java/swyp/team5/greening/post/controller/PostControllerTest.java +++ b/src/test/java/swyp/team5/greening/post/controller/PostControllerTest.java @@ -246,10 +246,8 @@ void getLatestPosts() throws Exception { mockMvc.perform(get("/api/posts/home")) .andExpect(jsonPath("$.data.size()").value(2)) .andExpect(jsonPath("$.data[0].postId").value(post.getId())) - .andExpect(jsonPath("$.data[0].isLike").value(false)) .andExpect(jsonPath("$.data[0].userId").value(loginUser.getId())) .andExpect(jsonPath("$.data[1].postId").value(anotherPost.getId())) - .andExpect(jsonPath("$.data[1].isLike").value(false)) .andExpect(jsonPath("$.data[1].userId").value(anotherUser.getId())); } @@ -260,10 +258,8 @@ void getLatestPosts2() throws Exception { .header(HttpHeaders.AUTHORIZATION, accessToken)) .andExpect(jsonPath("$.data.size()").value(2)) .andExpect(jsonPath("$.data[0].postId").value(post.getId())) - .andExpect(jsonPath("$.data[0].isLike").value(false)) .andExpect(jsonPath("$.data[0].userId").value(loginUser.getId())) .andExpect(jsonPath("$.data[1].postId").value(anotherPost.getId())) - .andExpect(jsonPath("$.data[1].isLike").value(true)) .andExpect(jsonPath("$.data[1].userId").value(anotherUser.getId())); } From fcd472ea0469a61da995524f21298a524db9664d Mon Sep 17 00:00:00 2001 From: kkang_h00n Date: Sat, 12 Jul 2025 10:34:17 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20=ED=85=8C=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../greening/petPlant/domain/entity/DailyRecordContent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/swyp/team5/greening/petPlant/domain/entity/DailyRecordContent.java b/src/main/java/swyp/team5/greening/petPlant/domain/entity/DailyRecordContent.java index 810def8..6894459 100644 --- a/src/main/java/swyp/team5/greening/petPlant/domain/entity/DailyRecordContent.java +++ b/src/main/java/swyp/team5/greening/petPlant/domain/entity/DailyRecordContent.java @@ -18,7 +18,7 @@ @Getter @Entity -@Table(name = "daily_record_contets") +@Table(name = "daily_record_contents") @NoArgsConstructor public class DailyRecordContent extends BaseTimeEntity {