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 @@ -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;
Expand All @@ -45,6 +47,7 @@ public static ProfileResponseDto of(User user,
.myPostCount(myPostCount)
.myCommentCount(myCommentCount)
.myLikedPostCount(myLikedPostCount)
.myKeepCount(myKeepCount)
.build();
}
}
16 changes: 10 additions & 6 deletions src/main/java/com/back/domain/profile/service/ProfileService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,28 +22,30 @@ 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, "사용자를 찾을 수 없습니다."));

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, "사용자를 찾을 수 없습니다."));
Expand All @@ -63,4 +67,4 @@ public ProfileResponseDto updateProfile(Long id, ProfileUpdateRequestDto profile

return getProfile(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
Expand All @@ -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)))
Expand All @@ -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<ProfileUpdateRequestDto> captor = ArgumentCaptor.forClass(ProfileUpdateRequestDto.class);
verify(profileService).updateProfile(eq(principal.getId()), captor.capture());
Expand Down