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()) 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()) 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());