Skip to content

Commit 01893ab

Browse files
authored
[feat] 프로필 상단 카드 요약에 '킵한 칵테일 수' 집계 구현 #210 (#217)
* Revert "chore: initData용 이미지 추가" This reverts commit ef30eef. * . * feat: ProfileResponseDto에 나의 킵(Keep) 카운트 필드 추가 * feat: ProfileService에 킵 카운트 로직 통합 및 MyBarRepository 의존성 추가 사용자 프로필 요약 정보에 '내가 킵한(저장한)' 아이템의 수를 포함하도록 ProfileService를 수정 * test: ProfileControllerTest에서 킵 카운트 검증 추가 및 DTO 빌더 업데이트 프로필 조회 API 응답 DTO에 'myKeepCount' 필드가 추가됨에 따라, 컨트롤러 테스트를 업데이트
1 parent cd22572 commit 01893ab

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/main/java/com/back/domain/profile/dto/ProfileResponseDto.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ public class ProfileResponseDto {
2323
private Long myPostCount;
2424
private Long myCommentCount;
2525
private Long myLikedPostCount;
26+
private Long myKeepCount;
2627

2728
public static ProfileResponseDto of(User user,
2829
long myPostCount,
2930
long myCommentCount,
30-
long myLikedPostCount) {
31+
long myLikedPostCount,
32+
long myKeepCount) {
3133
// 신규 사용자는 기본 5%로 시작하도록 뷰 레벨에서 기본값 적용
3234
Double percent = user.getAbvDegree();
3335
if (percent == null) percent = 5.0;
@@ -45,6 +47,7 @@ public static ProfileResponseDto of(User user,
4547
.myPostCount(myPostCount)
4648
.myCommentCount(myCommentCount)
4749
.myLikedPostCount(myLikedPostCount)
50+
.myKeepCount(myKeepCount)
4851
.build();
4952
}
5053
}

src/main/java/com/back/domain/profile/service/ProfileService.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.back.domain.profile.service;
22

3+
import com.back.domain.mybar.enums.KeepStatus;
4+
import com.back.domain.mybar.repository.MyBarRepository;
35
import com.back.domain.profile.dto.ProfileResponseDto;
46
import com.back.domain.profile.dto.ProfileUpdateRequestDto;
57
import com.back.domain.user.entity.User;
@@ -20,28 +22,30 @@ public class ProfileService {
2022

2123
private final UserRepository userRepository;
2224
private final ProfileQueryRepository profileQueryRepository;
25+
private final MyBarRepository myBarRepository;
2326

24-
// 내 프로필 요약 조회
25-
// - 카운트 3종(내 글/내 댓글/내가 좋아요한 글) 조회 후
26-
// - DTO 정적 팩토리(of)로 레벨/라벨 계산과 함께 응답 조립
27+
// 프로필 요약 조회
28+
// - 카운트 4종(글/댓글/내가 좋아요한 글/킵한 칵테일) 조회 후 DTO 팩토리(of)로 레벨/라벨 계산까지 함께 응답 조립
2729
@Transactional(readOnly = true)
2830
public ProfileResponseDto getProfile(Long id) {
2931
User user = userRepository.findById(id).orElseThrow(() -> new ServiceException(404, "사용자를 찾을 수 없습니다."));
3032

3133
long postCount = profileQueryRepository.countMyPosts(user.getId(), PostStatus.DELETED);
3234
long commentCount = profileQueryRepository.countMyComments(user.getId(), CommentStatus.DELETED);
3335
long likedPostCount = profileQueryRepository.countMyLikedPosts(user.getId(), PostLikeStatus.LIKE);
36+
long keepCount = myBarRepository.countByUser_IdAndStatus(user.getId(), KeepStatus.ACTIVE);
3437

3538
return ProfileResponseDto.of(
3639
user,
3740
postCount,
3841
commentCount,
39-
likedPostCount
42+
likedPostCount,
43+
keepCount
4044
);
4145
}
4246

4347
// 프로필 수정 (닉네임)
44-
// - 길이/중복 검사 후 반영, 이후 최신 프로필 다시 조회
48+
// - 길이/중복 검증 반영, 이후 최신 프로필 다시 조회
4549
@Transactional
4650
public ProfileResponseDto updateProfile(Long id, ProfileUpdateRequestDto profileUpdateRequestDto) {
4751
User user = userRepository.findById(id).orElseThrow(() -> new ServiceException(404, "사용자를 찾을 수 없습니다."));
@@ -63,4 +67,4 @@ public ProfileResponseDto updateProfile(Long id, ProfileUpdateRequestDto profile
6367

6468
return getProfile(id);
6569
}
66-
}
70+
}

src/test/java/com/back/domain/profile/controller/ProfileControllerTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void getProfile_success() throws Exception {
110110
.myPostCount(7L)
111111
.myCommentCount(14L)
112112
.myLikedPostCount(5L)
113+
.myKeepCount(9L)
113114
.build();
114115

115116
given(profileService.getProfile(principal.getId())).willReturn(responseDto);
@@ -128,7 +129,8 @@ void getProfile_success() throws Exception {
128129
.andExpect(jsonPath("$.data.abvLabel").value("12.5%"))
129130
.andExpect(jsonPath("$.data.myPostCount").value(7))
130131
.andExpect(jsonPath("$.data.myCommentCount").value(14))
131-
.andExpect(jsonPath("$.data.myLikedPostCount").value(5));
132+
.andExpect(jsonPath("$.data.myLikedPostCount").value(5))
133+
.andExpect(jsonPath("$.data.myKeepCount").value(9));
132134

133135
verify(profileService).getProfile(principal.getId());
134136
}
@@ -144,11 +146,12 @@ void patchNickname_success() throws Exception {
144146
.nickname("newNick")
145147
.email(principal.getEmail())
146148
.abvDegree(20.0)
147-
.abvLevel(3)
149+
.abvLevel(4)
148150
.abvLabel("20.0%")
149151
.myPostCount(11L)
150152
.myCommentCount(8L)
151153
.myLikedPostCount(3L)
154+
.myKeepCount(15L)
152155
.build();
153156

154157
given(profileService.updateProfile(eq(principal.getId()), any(ProfileUpdateRequestDto.class)))
@@ -162,7 +165,8 @@ void patchNickname_success() throws Exception {
162165
.andExpect(status().isOk())
163166
.andExpect(jsonPath("$.code").value(200))
164167
.andExpect(jsonPath("$.message").value("success"))
165-
.andExpect(jsonPath("$.data.nickname").value("newNick"));
168+
.andExpect(jsonPath("$.data.nickname").value("newNick"))
169+
.andExpect(jsonPath("$.data.myKeepCount").value(15));
166170

167171
ArgumentCaptor<ProfileUpdateRequestDto> captor = ArgumentCaptor.forClass(ProfileUpdateRequestDto.class);
168172
verify(profileService).updateProfile(eq(principal.getId()), captor.capture());

0 commit comments

Comments
 (0)