Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

짧은 리뷰 좋아요shortReviewId DTO로 요청 전달 #132 #137

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ 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;

//카운트가 없으면 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())
Expand All @@ -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();
}
Expand Down
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("/{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()));
}

}
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(Long likeId, Long memberId);
IsLikeRes checkReviewLike(ShortReviewLikeReq req, 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(Long shortReviewId, Long memberId) {
Optional<ShortReviewLike> optionalLike = getShortReviewLike(memberId, shortReviewId);
public IsLikeRes checkReviewLike(ShortReviewLikeReq req, Long memberId) {
Optional<ShortReviewLike> optionalLike = getShortReviewLike(memberId, req.getShortReviewId());
return IsLikeRes
.builder()
.isLike(optionalLike.isPresent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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("짧은 리뷰 좋아요 수"),
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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("짧은 리뷰 좋아요 수"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ 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
@DisplayName("짧은 리뷰 좋아요 없을 시 false")
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());
}
}
}