Skip to content
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 @@ -139,6 +139,10 @@ public VerificationDetailResponseDto toDetailDto(
boolean canEdit,
boolean canDelete,
boolean canSelectComment,
boolean isLiked,
long likeCount,
boolean isScrapped,
long scrapCount,
boolean canWriteComment,
Long adoptedCommentId
) {
Expand Down Expand Up @@ -190,6 +194,10 @@ public VerificationDetailResponseDto toDetailDto(
.canEdit(canEdit)
.canDelete(canDelete)
.canSelectComment(canSelectComment)
.isLiked(isLiked)
.likeCount(likeCount)
.isScrapped(isScrapped)
.scrapCount(scrapCount)
.canWriteComment(canWriteComment)
.adoptedCommentId(adoptedCommentId)
.showResolvedBadge(verification.getIsResolved())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hrr.backend.domain.user.entity.enums.UserLevel;
import com.hrr.backend.domain.verification.entity.enums.VerificationPostType;
import com.hrr.backend.domain.verification.entity.enums.VerificationStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -47,6 +48,18 @@ public class VerificationDetailResponseDto {
private Boolean canDelete;
private Boolean canSelectComment;

@Schema(description = "현재 로그인 사용자의 좋아요 여부", example = "true")
private Boolean isLiked;

@Schema(description = "인증 게시글 좋아요 개수", example = "12")
private Long likeCount;

@Schema(description = "현재 로그인 사용자의 스크랩 여부", example = "false")
private Boolean isScrapped;

@Schema(description = "인증 게시글 스크랩 개수", example = "5")
private Long scrapCount;

//프론트가 받기 쉽게
private boolean canWriteComment;
private Long adoptedCommentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ INSERT IGNORE INTO verification_like (user_id, verification_id, created_at, upda
void insertIgnore(@Param("userId") Long userId, @Param("verificationId") Long verificationId);

void deleteByUserIdAndVerificationId(Long userId, Long verificationId);

boolean existsByUserIdAndVerificationId(Long userId, Long verificationId);

long countByVerificationId(Long verificationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ INSERT IGNORE INTO verification_scrap (user_id, verification_id, created_at, upd

void deleteByUserIdAndVerificationId(Long userId, Long verificationId);

boolean existsByUserIdAndVerificationId(Long userId, Long verificationId);

long countByVerificationId(Long verificationId);

@Query("""
SELECT v FROM VerificationScrap vs
JOIN vs.verification v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ public VerificationDetailResponseDto getVerificationDetail(
&& Boolean.TRUE.equals(verification.getIsQuestion())
&& !isResolved;

boolean isLiked = false;
boolean isScrapped = false;
if (currentUserId != null) {
isLiked = verificationLikeRepository.existsByUserIdAndVerificationId(currentUserId, verificationId);
isScrapped = verificationScrapRepository.existsByUserIdAndVerificationId(currentUserId, verificationId);
}
long likeCount = verificationLikeRepository.countByVerificationId(verificationId);
long scrapCount = verificationScrapRepository.countByVerificationId(verificationId);

boolean canWriteComment = false;
if (currentUserId != null) {
Long challengeId = verification.getRoundRecord().getRound().getChallenge().getId();
Expand Down Expand Up @@ -472,6 +481,10 @@ public VerificationDetailResponseDto getVerificationDetail(
canEdit,
canDelete,
canSelectComment,
isLiked,
likeCount,
isScrapped,
scrapCount,
canWriteComment,
adoptedCommentId
);
Expand Down Expand Up @@ -579,6 +592,11 @@ public VerificationDetailResponseDto updateVerification(Long verificationId, Lon
.findFirst()
.orElse(null);

boolean isLiked = verificationLikeRepository.existsByUserIdAndVerificationId(currentUserId, verificationId);
boolean isScrapped = verificationScrapRepository.existsByUserIdAndVerificationId(currentUserId, verificationId);
long likeCount = verificationLikeRepository.countByVerificationId(verificationId);
long scrapCount = verificationScrapRepository.countByVerificationId(verificationId);

boolean canWriteComment = false;
if (currentUserId != null) {
Long challengeId = verification.getRoundRecord().getRound().getChallenge().getId();
Expand All @@ -597,6 +615,10 @@ public VerificationDetailResponseDto updateVerification(Long verificationId, Lon
canEdit,
canDelete,
canSelectComment,
isLiked,
likeCount,
isScrapped,
scrapCount,
canWriteComment,
adoptedCommentId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -185,21 +185,36 @@ void getVerificationDetail_Success_CanWriteComment() {
given(commentService.getComments(anyLong(), any(), any(Pageable.class)))
.willReturn(mockComments);

given(verificationLikeRepository.existsByUserIdAndVerificationId(currentUserId, verificationId))
.willReturn(true);
given(verificationScrapRepository.existsByUserIdAndVerificationId(currentUserId, verificationId))
.willReturn(false);
given(verificationLikeRepository.countByVerificationId(verificationId))
.willReturn(3L);
given(verificationScrapRepository.countByVerificationId(verificationId))
.willReturn(2L);

// 5. Converter Mock (인자 8개 맞춤, canWriteComment=true 예상)
VerificationDetailResponseDto expectedDto = VerificationDetailResponseDto.builder()
.verificationId(verificationId)
.canWriteComment(true)
.likeCount(3L)
.scrapCount(2L)
.build();

given(verificationConverter.toDetailDto(
any(Verification.class), // 1. Verification
any(CommentListResponseDto.class), // 2. CommentListResponseDto
anyBoolean(), // 3. isLiked
anyBoolean(), // 3. isMine
anyBoolean(), // 4. canEdit
anyBoolean(), // 5. canDelete
anyBoolean(), // 6. canReport
anyBoolean(), // 7. canWriteComment (핵심 검증 대상)
any() // 8. currentUser (User 객체 혹은 null)
anyBoolean(), // 6. canSelectComment
eq(true), // 7. isLiked
eq(3L), // 8. likeCount
eq(false), // 9. isScrapped
eq(2L), // 10. scrapCount
anyBoolean(), // 11. canWriteComment
any() // 12. adoptedCommentId
)).willReturn(expectedDto);

// when
Expand All @@ -209,6 +224,8 @@ void getVerificationDetail_Success_CanWriteComment() {
assertThat(result).isNotNull();
assertThat(result.getVerificationId()).isEqualTo(verificationId);
assertThat(result.isCanWriteComment()).isTrue();
assertThat(result.getLikeCount()).isEqualTo(3L);
assertThat(result.getScrapCount()).isEqualTo(2L);
}

@Test
Expand Down Expand Up @@ -242,9 +259,10 @@ void getVerificationDetail_Success_CannotWriteComment() {
.canWriteComment(false)
.build();

// Converter Mock 부분도 인자 개수 8개로 맞춤
// Converter Mock 부분도 인자 개수에 맞춤
given(verificationConverter.toDetailDto(
any(), any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(),
anyBoolean(), anyLong(), anyBoolean(), anyLong(),
eq(false), // canWriteComment = false 예상
any()
)).willReturn(expectedDto);
Expand Down