Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wellbeing-dough committed Oct 12, 2023
2 parents e7d4089 + ca77945 commit 0dc9dc1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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<StudyEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
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;

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 0dc9dc1

Please sign in to comment.