From 6f7847fa324b2621d29af76293749f3ad2e39291 Mon Sep 17 00:00:00 2001 From: hanyMK Date: Fri, 15 Dec 2023 00:12:00 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EC=A7=A7=EC=9D=80=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=9C=A0=EB=AC=B4=20?= =?UTF-8?q?uri=EC=88=98=EC=A0=95#152?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reviewLike/controller/ShortReviewLikeController.java | 8 ++++---- .../domain/reviewLike/service/ShortReviewLikeService.java | 2 +- .../reviewLike/service/ShortReviewLikeServiceImpl.java | 4 ++-- 3 files changed, 7 insertions(+), 7 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 6e6e937a..2039ec76 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 + @GetMapping("/{shortReviewId}") public ResponseEntity getLike( - @RequestBody @Valid ShortReviewLikeReq req, - @LoginUser AuthUser user + @PathVariable("shortReviewId") Long shortReviewId, + @LoginUser AuthUser user ){ //TODO: 좋아요한 리뷰인지 확인 - return ResponseEntity.ok(shortReviewLikeService.checkReviewLike(req, user.getId())); + return ResponseEntity.ok(shortReviewLikeService.checkReviewLike(shortReviewId, 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 40aeb08c..cfff1d75 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(ShortReviewLikeReq req, Long memberId); + IsLikeRes checkReviewLike(Long shortReviewId, 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 925b0295..6eb27912 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(ShortReviewLikeReq req, Long memberId) { - Optional optionalLike = getShortReviewLike(memberId, req.getShortReviewId()); + public IsLikeRes checkReviewLike(Long shortReviewId, Long memberId) { + Optional optionalLike = getShortReviewLike(memberId, shortReviewId); return IsLikeRes .builder() .isLike(optionalLike.isPresent()) From 6f9b2b5e30719720c225db0dbb7429e30e398275 Mon Sep 17 00:00:00 2001 From: hanyMK Date: Fri, 15 Dec 2023 00:12:24 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=EC=A7=A7=EC=9D=80=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=9C=A0=EB=AC=B4=20?= =?UTF-8?q?=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20=EC=88=98=EC=A0=95=20#152?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShortReviewLikeControllerTest.java | 26 +++++-------------- .../service/ShortReviewLikeServiceTest.java | 4 +-- 2 files changed, 8 insertions(+), 22 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 0a450824..1df95100 100644 --- a/src/test/java/io/oduck/api/e2e/shortReviewLike/ShortReviewLikeControllerTest.java +++ b/src/test/java/io/oduck/api/e2e/shortReviewLike/ShortReviewLikeControllerTest.java @@ -155,20 +155,14 @@ class CheckLike{ @WithCustomMockMember(id = 1L, email = "john", password = "Qwer!234", role = Role.MEMBER) void checkShortReviewLike() throws Exception{ //given - ShortReviewLikeReq req = ShortReviewLikeReq - .builder() - .shortReviewId(1L) - .build(); - - String content = gson.toJson(req); + Long shortReviewId = 1L; //when ResultActions actions = mockMvc.perform( - get(BASE_URL) + get(BASE_URL + "/{shortReviewId}", shortReviewId) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .header(HttpHeaders.COOKIE, "oDuckio.sid={SESSION_VALUE}") - .content(content)); + .header(HttpHeaders.COOKIE, "oDuckio.sid={SESSION_VALUE}")); //then actions @@ -177,16 +171,9 @@ void checkShortReviewLike() throws Exception{ .andDo(document("likes/shortReview/checkLike/success", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - requestHeaders( - headerWithName(HttpHeaders.COOKIE) - .attributes(field("constraints", "oDuckio.sid={SESSION_VALUE}")) - .description("Header Cookie, 세션 쿠키") - ), - requestFields(attributes(key("title").value("Fields for shortReviewLike creation")), - fieldWithPath("shortReviewId") - .type(JsonFieldType.NUMBER) - .attributes(field("constraints", "짧은 리뷰 아이디, NotNull, Min(1)")) - .description("짧은 리뷰 좋아요를 등록할 리뷰 고유 식별 번호")), + pathParameters( + parameterWithName("shortReviewId") + .description("짧은 리뷰 식별자")), responseFields( fieldWithPath("isLike") .type(JsonFieldType.BOOLEAN) @@ -195,5 +182,4 @@ void checkShortReviewLike() throws Exception{ ); } } - } \ No newline at end of file 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 ed5d1ee4..5d391532 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,7 +103,7 @@ class CheckLike{ void checkShortReviewLikeTrue(){ given(shortReviewLikeRepository.findByMemberIdAndShortReviewId(member.getId(), shortReview.getId())).willReturn(Optional.of(shortReviewLike)); - IsLikeRes isLikeRes = shortReviewLikeService.checkReviewLike(req, member.getId()); + IsLikeRes isLikeRes = shortReviewLikeService.checkReviewLike(shortReview.getId(), member.getId()); assertNotNull(isLikeRes); assertTrue(isLikeRes.getIsLike()); @@ -114,7 +114,7 @@ void checkShortReviewLikeTrue(){ void checkShortReviewLikeFalse(){ given(shortReviewLikeRepository.findByMemberIdAndShortReviewId(member.getId(), shortReview.getId())).willReturn(Optional.empty()); - IsLikeRes isLikeRes = shortReviewLikeService.checkReviewLike(req, member.getId()); + IsLikeRes isLikeRes = shortReviewLikeService.checkReviewLike(shortReview.getId(), member.getId()); assertNotNull(isLikeRes); assertFalse(isLikeRes.getIsLike()); From a7641dcf3a295a0f71a0e5b0011c7db41043ddf0 Mon Sep 17 00:00:00 2001 From: hanyMK Date: Fri, 15 Dec 2023 00:12:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EC=A7=A7=EC=9D=80=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=9C=A0=EB=AC=B4=20?= =?UTF-8?q?=EC=9D=B8=EA=B0=80=20=EC=B6=94=EA=B0=80=20#152?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/oduck/api/global/security/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/oduck/api/global/security/config/SecurityConfig.java b/src/main/java/io/oduck/api/global/security/config/SecurityConfig.java index 5658fd2d..e19858bc 100644 --- a/src/main/java/io/oduck/api/global/security/config/SecurityConfig.java +++ b/src/main/java/io/oduck/api/global/security/config/SecurityConfig.java @@ -93,6 +93,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers(HttpMethod.PATCH, "/attraction-points/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name()) .requestMatchers(HttpMethod.DELETE, "/attraction-points/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name()) .requestMatchers(HttpMethod.PUT, "/likes/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name()) + .requestMatchers(HttpMethod.GET, "/likes/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name()) .requestMatchers(HttpMethod.POST, "/likes/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name()) .requestMatchers(HttpMethod.PATCH, "/likes/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name()) .requestMatchers(HttpMethod.DELETE, "/likes/**").hasAnyAuthority(Role.MEMBER.name(), Role.ADMIN.name())