diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/StudyRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/StudyRepository.java new file mode 100644 index 00000000..63cdb398 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/StudyRepository.java @@ -0,0 +1,7 @@ +package kr.co.studyhubinu.studyhubserver.study; + +import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface StudyRepository extends JpaRepository { +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java new file mode 100644 index 00000000..d7979212 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java @@ -0,0 +1,25 @@ +package kr.co.studyhubinu.studyhubserver.user.domain; + +import kr.co.studyhubinu.studyhubserver.bookmark.repository.BookMarkRepository; +import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserActivityCountData; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class UserActivityFinder { + + private final StudyPostRepository studyPostRepository; + private final BookMarkRepository bookMarkRepository; + private final StudyRepository studyRepository; + + public UserActivityCountData countUserActivity(Long userId) { + Long postCount = studyPostRepository.countByPostedUserId(userId); + Long participateCount = 0L; + Long bookmarkCount = bookMarkRepository.countByUserId(userId); + return new UserActivityCountData(postCount, participateCount, bookmarkCount); + } + +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/UserActivityCountData.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/UserActivityCountData.java new file mode 100644 index 00000000..0f425191 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/UserActivityCountData.java @@ -0,0 +1,16 @@ +package kr.co.studyhubinu.studyhubserver.user.dto.data; + +import lombok.Getter; + +@Getter +public class UserActivityCountData { + private Long postCount; + private Long participateCount; + private Long bookmarkCount; + + public UserActivityCountData(Long postCount, Long participateCount, Long bookmarkCount) { + this.postCount = postCount; + this.participateCount = participateCount; + this.bookmarkCount = bookmarkCount; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/response/GetUserResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/response/GetUserResponse.java index cfb1f2c1..b7085612 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/response/GetUserResponse.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/response/GetUserResponse.java @@ -1,6 +1,7 @@ package kr.co.studyhubinu.studyhubserver.user.dto.response; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserActivityCountData; import kr.co.studyhubinu.studyhubserver.user.enums.GenderType; import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; import lombok.Getter; @@ -8,13 +9,19 @@ @Getter public class GetUserResponse { + private Long postCount; + private Long participateCount; + private Long bookmarkCount; private String nickname; private MajorType major; private GenderType gender; private String email; private String imageUrl; - - public GetUserResponse(UserEntity user) { + + public GetUserResponse(UserEntity user, UserActivityCountData data) { + this.postCount = data.getPostCount(); + this.participateCount = data.getParticipateCount(); + this.bookmarkCount = data.getBookmarkCount(); this.nickname = user.getNickname(); this.major = user.getMajor(); this.gender = user.getGender(); diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java index 6089dd7e..3da33335 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java @@ -5,6 +5,8 @@ import kr.co.studyhubinu.studyhubserver.exception.user.UserNotAccessRightException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; import kr.co.studyhubinu.studyhubserver.exception.user.*; +import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; +import kr.co.studyhubinu.studyhubserver.user.domain.UserActivityFinder; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; import kr.co.studyhubinu.studyhubserver.user.dto.data.*; import kr.co.studyhubinu.studyhubserver.user.dto.response.GetUserResponse; @@ -24,6 +26,7 @@ public class UserService { private final UserRepository userRepository; private final BCryptPasswordEncoder bCryptPasswordEncoder; + private final UserActivityFinder userActivityFinder; @Transactional public void registerUser(SignUpInfo signUpInfo) { @@ -46,7 +49,8 @@ public void deleteUser(Long userId) { public GetUserResponse getUser(Long userId) { UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); - return new GetUserResponse(user); + UserActivityCountData data = userActivityFinder.countUserActivity(userId); + return new GetUserResponse(user, data); } @Transactional