Skip to content

Commit

Permalink
Merge pull request #155 from oduck-team/feature/152
Browse files Browse the repository at this point in the history
짧은 리뷰 좋아요 유무 uri변경 #152
  • Loading branch information
hanyMK authored Dec 15, 2023
2 parents 5f292a1 + a7641dc commit 6610cc8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public Boolean postLike(Long memberId, ShortReviewLikeReq likeRes) {
}

@Override
public IsLikeRes checkReviewLike(ShortReviewLikeReq req, Long memberId) {
Optional<ShortReviewLike> optionalLike = getShortReviewLike(memberId, req.getShortReviewId());
public IsLikeRes checkReviewLike(Long shortReviewId, Long memberId) {
Optional<ShortReviewLike> optionalLike = getShortReviewLike(memberId, shortReviewId);
return IsLikeRes
.builder()
.isLike(optionalLike.isPresent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -195,5 +182,4 @@ void checkShortReviewLike() throws Exception{
);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 6610cc8

Please sign in to comment.