From 452272e8045a94f0b0a916353fce84a699ade8cb Mon Sep 17 00:00:00 2001 From: hanyMK Date: Sat, 2 Dec 2023 00:11:28 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20shortReviewId=20DTO=EB=A1=9C=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=A0=84=EB=8B=AC=20=20#132?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reviewLike/controller/ShortReviewLikeController.java | 6 +++--- .../domain/reviewLike/service/ShortReviewLikeService.java | 2 +- .../reviewLike/service/ShortReviewLikeServiceImpl.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/oduck/api/domain/reviewLike/controller/ShortReviewLikeController.java b/src/main/java/io/oduck/api/domain/reviewLike/controller/ShortReviewLikeController.java index ea57c5a1..6e6e937a 100644 --- a/src/main/java/io/oduck/api/domain/reviewLike/controller/ShortReviewLikeController.java +++ b/src/main/java/io/oduck/api/domain/reviewLike/controller/ShortReviewLikeController.java @@ -37,13 +37,13 @@ public ResponseEntity postLike( return ResponseEntity.status(postLike ? HttpStatus.CREATED : HttpStatus.NO_CONTENT).build(); } - @GetMapping("/{shortReviewId}") + @GetMapping public ResponseEntity getLike( - @PathVariable Long shortReviewId, + @RequestBody @Valid ShortReviewLikeReq req, @LoginUser AuthUser user ){ //TODO: 좋아요한 리뷰인지 확인 - return ResponseEntity.ok(shortReviewLikeService.checkReviewLike(shortReviewId, user.getId())); + return ResponseEntity.ok(shortReviewLikeService.checkReviewLike(req, user.getId())); } } \ No newline at end of file diff --git a/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeService.java b/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeService.java index fa5c69c0..40aeb08c 100644 --- a/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeService.java +++ b/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeService.java @@ -10,6 +10,6 @@ public interface ShortReviewLikeService { Boolean postLike(Long memberId, ShortReviewLikeReq likeRes); //리뷰 좋아요 유무 - IsLikeRes checkReviewLike(Long likeId, Long memberId); + IsLikeRes checkReviewLike(ShortReviewLikeReq req, Long memberId); } diff --git a/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeServiceImpl.java b/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeServiceImpl.java index 6eb27912..925b0295 100644 --- a/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeServiceImpl.java +++ b/src/main/java/io/oduck/api/domain/reviewLike/service/ShortReviewLikeServiceImpl.java @@ -48,8 +48,8 @@ public Boolean postLike(Long memberId, ShortReviewLikeReq likeRes) { } @Override - public IsLikeRes checkReviewLike(Long shortReviewId, Long memberId) { - Optional optionalLike = getShortReviewLike(memberId, shortReviewId); + public IsLikeRes checkReviewLike(ShortReviewLikeReq req, Long memberId) { + Optional optionalLike = getShortReviewLike(memberId, req.getShortReviewId()); return IsLikeRes .builder() .isLike(optionalLike.isPresent()) From b33a22aa1185b55a922b1726d9298ee14308a35f Mon Sep 17 00:00:00 2001 From: hanyMK Date: Sat, 2 Dec 2023 00:13:07 +0900 Subject: [PATCH 2/4] =?UTF-8?q?test:=20shortReviewId=20DTO=EB=A1=9C=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=A0=84=EB=8B=AC=20=20#132?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShortReviewLikeControllerTest.java | 21 ++++++++++++------- .../service/ShortReviewLikeServiceTest.java | 12 +++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/test/java/io/oduck/api/e2e/shortReviewLike/ShortReviewLikeControllerTest.java b/src/test/java/io/oduck/api/e2e/shortReviewLike/ShortReviewLikeControllerTest.java index e66efc39..0a450824 100644 --- a/src/test/java/io/oduck/api/e2e/shortReviewLike/ShortReviewLikeControllerTest.java +++ b/src/test/java/io/oduck/api/e2e/shortReviewLike/ShortReviewLikeControllerTest.java @@ -155,14 +155,20 @@ class CheckLike{ @WithCustomMockMember(id = 1L, email = "john", password = "Qwer!234", role = Role.MEMBER) void checkShortReviewLike() throws Exception{ //given - Long shortReviewId = 1L; + ShortReviewLikeReq req = ShortReviewLikeReq + .builder() + .shortReviewId(1L) + .build(); + + String content = gson.toJson(req); //when ResultActions actions = mockMvc.perform( - get(BASE_URL + "/{shortReviewId}", shortReviewId) + get(BASE_URL) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .header(HttpHeaders.COOKIE, "oDuckio.sid={SESSION_VALUE}")); + .header(HttpHeaders.COOKIE, "oDuckio.sid={SESSION_VALUE}") + .content(content)); //then actions @@ -176,10 +182,11 @@ void checkShortReviewLike() throws Exception{ .attributes(field("constraints", "oDuckio.sid={SESSION_VALUE}")) .description("Header Cookie, 세션 쿠키") ), - pathParameters( - parameterWithName("shortReviewId") - .description("짧은 리뷰 고유 식별자") - ), + requestFields(attributes(key("title").value("Fields for shortReviewLike creation")), + fieldWithPath("shortReviewId") + .type(JsonFieldType.NUMBER) + .attributes(field("constraints", "짧은 리뷰 아이디, NotNull, Min(1)")) + .description("짧은 리뷰 좋아요를 등록할 리뷰 고유 식별 번호")), responseFields( fieldWithPath("isLike") .type(JsonFieldType.BOOLEAN) diff --git a/src/test/java/io/oduck/api/unit/shortReviewLike/service/ShortReviewLikeServiceTest.java b/src/test/java/io/oduck/api/unit/shortReviewLike/service/ShortReviewLikeServiceTest.java index 9f2c6721..ed5d1ee4 100644 --- a/src/test/java/io/oduck/api/unit/shortReviewLike/service/ShortReviewLikeServiceTest.java +++ b/src/test/java/io/oduck/api/unit/shortReviewLike/service/ShortReviewLikeServiceTest.java @@ -103,10 +103,10 @@ class CheckLike{ void checkShortReviewLikeTrue(){ given(shortReviewLikeRepository.findByMemberIdAndShortReviewId(member.getId(), shortReview.getId())).willReturn(Optional.of(shortReviewLike)); - IsLikeRes hasLikeRes = shortReviewLikeService.checkReviewLike(shortReview.getId(), member.getId()); + IsLikeRes isLikeRes = shortReviewLikeService.checkReviewLike(req, member.getId()); - assertNotNull(hasLikeRes); - assertTrue(hasLikeRes.getIsLike()); + assertNotNull(isLikeRes); + assertTrue(isLikeRes.getIsLike()); } @Test @@ -114,10 +114,10 @@ void checkShortReviewLikeTrue(){ void checkShortReviewLikeFalse(){ given(shortReviewLikeRepository.findByMemberIdAndShortReviewId(member.getId(), shortReview.getId())).willReturn(Optional.empty()); - IsLikeRes hasLikeRes = shortReviewLikeService.checkReviewLike(shortReview.getId(), member.getId()); + IsLikeRes isLikeRes = shortReviewLikeService.checkReviewLike(req, member.getId()); - assertNotNull(hasLikeRes); - assertFalse(hasLikeRes.getIsLike()); + assertNotNull(isLikeRes); + assertFalse(isLikeRes.getIsLike()); } } } From e84249c515be854d5d52d6ecbc81c350a454f520 Mon Sep 17 00:00:00 2001 From: hanyMK Date: Mon, 4 Dec 2023 01:14:09 +0900 Subject: [PATCH 3/4] =?UTF-8?q?cleanup:=20isLike=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20=20#132?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/oduck/api/domain/review/dto/ShortReviewResDto.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/io/oduck/api/domain/review/dto/ShortReviewResDto.java b/src/main/java/io/oduck/api/domain/review/dto/ShortReviewResDto.java index d61cfda1..2ae3164f 100644 --- a/src/main/java/io/oduck/api/domain/review/dto/ShortReviewResDto.java +++ b/src/main/java/io/oduck/api/domain/review/dto/ShortReviewResDto.java @@ -27,7 +27,6 @@ public static class ShortReviewRes implements EntityBased { private Integer score; private String content; private Boolean isSpoiler; - private Boolean isLike; @Builder.Default private Long likeCount = 0L; private LocalDateTime createdAt; @@ -35,8 +34,6 @@ public static class ShortReviewRes implements EntityBased { //카운트가 없으면 hasLike false @Builder public static ShortReviewRes of(ShortReviewDsl shortReviewDsl) { - Boolean isLike = shortReviewDsl.getLikeCount() != null; - Long likeCount = isLike ? shortReviewDsl.getLikeCount() : 0L; return ShortReviewRes .builder() .reviewId(shortReviewDsl.getReviewId()) @@ -46,8 +43,7 @@ public static ShortReviewRes of(ShortReviewDsl shortReviewDsl) { .score(shortReviewDsl.getScore()) .content(shortReviewDsl.getContent()) .isSpoiler(shortReviewDsl.getIsSpoiler()) - .isLike(isLike) - .likeCount(likeCount) + .likeCount(shortReviewDsl.getLikeCount()) .createdAt(shortReviewDsl.getCreatedAt()) .build(); } From 23cf42d4df86f0163edab442126cc3633c72bcc0 Mon Sep 17 00:00:00 2001 From: hanyMK Date: Mon, 4 Dec 2023 01:14:38 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20isLike=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20=20#132?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/e2e/shortReview/ShortReviewControllerTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/test/java/io/oduck/api/e2e/shortReview/ShortReviewControllerTest.java b/src/test/java/io/oduck/api/e2e/shortReview/ShortReviewControllerTest.java index b97104af..5f99acde 100644 --- a/src/test/java/io/oduck/api/e2e/shortReview/ShortReviewControllerTest.java +++ b/src/test/java/io/oduck/api/e2e/shortReview/ShortReviewControllerTest.java @@ -142,7 +142,6 @@ void getShortReviews() throws Exception{ .andExpect(jsonPath("$.items[0].score").exists()) .andExpect(jsonPath("$.items[0].content").exists()) .andExpect(jsonPath("$.items[0].isSpoiler").exists()) - .andExpect(jsonPath("$.items[0].isLike").exists()) .andExpect(jsonPath("$.items[0].likeCount").exists()) .andExpect(jsonPath("$.items[0].createdAt").exists()) .andExpect(jsonPath("$.size").exists()) @@ -197,9 +196,6 @@ void getShortReviews() throws Exception{ fieldWithPath("items[].isSpoiler") .type(JsonFieldType.BOOLEAN) .description("스포일러 유무"), - fieldWithPath("items[].isLike") - .type(JsonFieldType.BOOLEAN) - .description("짧은 리뷰 좋아요 유무"), fieldWithPath("items[].likeCount") .type(JsonFieldType.NUMBER) .description("짧은 리뷰 좋아요 수"), @@ -253,7 +249,6 @@ void getShortReviewsWithCursor() throws Exception{ .andExpect(jsonPath("$.items[0].score").exists()) .andExpect(jsonPath("$.items[0].content").exists()) .andExpect(jsonPath("$.items[0].isSpoiler").exists()) - .andExpect(jsonPath("$.items[0].isLike").exists()) .andExpect(jsonPath("$.items[0].likeCount").exists()) .andExpect(jsonPath("$.items[0].createdAt").exists()) .andExpect(jsonPath("$.size").exists()) @@ -308,9 +303,6 @@ void getShortReviewsWithCursor() throws Exception{ fieldWithPath("items[].isSpoiler") .type(JsonFieldType.BOOLEAN) .description("스포일러 유무"), - fieldWithPath("items[].isLike") - .type(JsonFieldType.BOOLEAN) - .description("짧은 리뷰 좋아요 유무"), fieldWithPath("items[].likeCount") .type(JsonFieldType.NUMBER) .description("짧은 리뷰 좋아요 수"),