diff --git a/src/main/java/com/back/domain/profile/dto/ProfileResponseDto.java b/src/main/java/com/back/domain/profile/dto/ProfileResponseDto.java index 998f38f2..765f1738 100644 --- a/src/main/java/com/back/domain/profile/dto/ProfileResponseDto.java +++ b/src/main/java/com/back/domain/profile/dto/ProfileResponseDto.java @@ -23,11 +23,13 @@ public class ProfileResponseDto { private Long myPostCount; private Long myCommentCount; private Long myLikedPostCount; + private Long myKeepCount; public static ProfileResponseDto of(User user, long myPostCount, long myCommentCount, - long myLikedPostCount) { + long myLikedPostCount, + long myKeepCount) { // 신규 사용자는 기본 5%로 시작하도록 뷰 레벨에서 기본값 적용 Double percent = user.getAbvDegree(); if (percent == null) percent = 5.0; @@ -45,6 +47,7 @@ public static ProfileResponseDto of(User user, .myPostCount(myPostCount) .myCommentCount(myCommentCount) .myLikedPostCount(myLikedPostCount) + .myKeepCount(myKeepCount) .build(); } } diff --git a/src/main/java/com/back/domain/profile/service/ProfileService.java b/src/main/java/com/back/domain/profile/service/ProfileService.java index 314f9f7d..ee569183 100644 --- a/src/main/java/com/back/domain/profile/service/ProfileService.java +++ b/src/main/java/com/back/domain/profile/service/ProfileService.java @@ -1,5 +1,7 @@ package com.back.domain.profile.service; +import com.back.domain.mybar.enums.KeepStatus; +import com.back.domain.mybar.repository.MyBarRepository; import com.back.domain.profile.dto.ProfileResponseDto; import com.back.domain.profile.dto.ProfileUpdateRequestDto; import com.back.domain.user.entity.User; @@ -20,10 +22,10 @@ public class ProfileService { private final UserRepository userRepository; private final ProfileQueryRepository profileQueryRepository; + private final MyBarRepository myBarRepository; - // 내 프로필 요약 조회 - // - 카운트 3종(내 글/내 댓글/내가 좋아요한 글) 조회 후 - // - DTO 정적 팩토리(of)로 레벨/라벨 계산과 함께 응답 조립 + // 프로필 요약 조회 + // - 카운트 4종(글/댓글/내가 좋아요한 글/킵한 칵테일) 조회 후 DTO 팩토리(of)로 레벨/라벨 계산까지 함께 응답 조립 @Transactional(readOnly = true) public ProfileResponseDto getProfile(Long id) { User user = userRepository.findById(id).orElseThrow(() -> new ServiceException(404, "사용자를 찾을 수 없습니다.")); @@ -31,17 +33,19 @@ public ProfileResponseDto getProfile(Long id) { long postCount = profileQueryRepository.countMyPosts(user.getId(), PostStatus.DELETED); long commentCount = profileQueryRepository.countMyComments(user.getId(), CommentStatus.DELETED); long likedPostCount = profileQueryRepository.countMyLikedPosts(user.getId(), PostLikeStatus.LIKE); + long keepCount = myBarRepository.countByUser_IdAndStatus(user.getId(), KeepStatus.ACTIVE); return ProfileResponseDto.of( user, postCount, commentCount, - likedPostCount + likedPostCount, + keepCount ); } // 프로필 수정 (닉네임) - // - 길이/중복 검사 후 반영, 이후 최신 프로필 다시 조회 + // - 길이/중복 검증 반영, 이후 최신 프로필 다시 조회 @Transactional public ProfileResponseDto updateProfile(Long id, ProfileUpdateRequestDto profileUpdateRequestDto) { User user = userRepository.findById(id).orElseThrow(() -> new ServiceException(404, "사용자를 찾을 수 없습니다.")); @@ -63,4 +67,4 @@ public ProfileResponseDto updateProfile(Long id, ProfileUpdateRequestDto profile return getProfile(id); } -} +} \ No newline at end of file diff --git a/src/test/java/com/back/domain/profile/controller/ProfileControllerTest.java b/src/test/java/com/back/domain/profile/controller/ProfileControllerTest.java index b5cf92fe..2e780377 100644 --- a/src/test/java/com/back/domain/profile/controller/ProfileControllerTest.java +++ b/src/test/java/com/back/domain/profile/controller/ProfileControllerTest.java @@ -110,6 +110,7 @@ void getProfile_success() throws Exception { .myPostCount(7L) .myCommentCount(14L) .myLikedPostCount(5L) + .myKeepCount(9L) .build(); given(profileService.getProfile(principal.getId())).willReturn(responseDto); @@ -128,7 +129,8 @@ void getProfile_success() throws Exception { .andExpect(jsonPath("$.data.abvLabel").value("12.5%")) .andExpect(jsonPath("$.data.myPostCount").value(7)) .andExpect(jsonPath("$.data.myCommentCount").value(14)) - .andExpect(jsonPath("$.data.myLikedPostCount").value(5)); + .andExpect(jsonPath("$.data.myLikedPostCount").value(5)) + .andExpect(jsonPath("$.data.myKeepCount").value(9)); verify(profileService).getProfile(principal.getId()); } @@ -144,11 +146,12 @@ void patchNickname_success() throws Exception { .nickname("newNick") .email(principal.getEmail()) .abvDegree(20.0) - .abvLevel(3) + .abvLevel(4) .abvLabel("20.0%") .myPostCount(11L) .myCommentCount(8L) .myLikedPostCount(3L) + .myKeepCount(15L) .build(); given(profileService.updateProfile(eq(principal.getId()), any(ProfileUpdateRequestDto.class))) @@ -162,7 +165,8 @@ void patchNickname_success() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value(200)) .andExpect(jsonPath("$.message").value("success")) - .andExpect(jsonPath("$.data.nickname").value("newNick")); + .andExpect(jsonPath("$.data.nickname").value("newNick")) + .andExpect(jsonPath("$.data.myKeepCount").value(15)); ArgumentCaptor captor = ArgumentCaptor.forClass(ProfileUpdateRequestDto.class); verify(profileService).updateProfile(eq(principal.getId()), captor.capture());