Skip to content

Commit

Permalink
Feat : UserService 기능 추가 (#19)
Browse files Browse the repository at this point in the history
- 푼 퀴즈 및 맟춘 퀴즈 업데이트 기능 추가
- findUserById 함수 추가
  • Loading branch information
chanmin-00 committed Dec 30, 2024
1 parent bca5845 commit 5b16b27
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/ripple/BE/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ public class User extends BaseEntity {
@Column(length = 100, unique = true, nullable = true)
private String keyCode; // 카카오 로그인 시 발급되는 고유 코드

@Column(name = "quiz_count")
private int quizCount = 0; // 퀴즈 푼 횟수

@Column(name = "correct_count")
private int correctCount = 0; // 정답 횟수

// 카카오 로그인 시 사용
@Builder(builderMethodName = "kakaoBuilder", buildMethodName = "buildKakaoUser")
public User(String keyCode, String accountEmail, String profileImageUrl, LoginType loginType) {
Expand Down Expand Up @@ -165,4 +171,12 @@ public void updateProfile(UpdateUserProfileRequest request) {
this.isCoummunityAlarmAllowed = request.isCommunityAlarmAllowed();
this.isProfileCompleted = true;
}

public void increaseQuizCount(int count) {
this.quizCount += count;
}

public void increaseCorrectCount(int count) {
this.correctCount += count;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/ripple/BE/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,24 @@ public void updateProfile(UpdateUserProfileRequest request, Long id) {
user.updateProfile(request);
}

@Transactional
public void updateQuizAndCorrectCount(User user, int quizCount, int correctCount) {
user.increaseQuizCount(quizCount);
user.increaseCorrectCount(correctCount);
}

@Transactional(readOnly = true)
public User findUser(String accountEmail) {
return userRepository
.findByAccountEmail(accountEmail)
.orElseThrow(() -> new UserException(USER_NOT_FOUND));
}

@Transactional(readOnly = true)
public User findUserById(Long id) {
return userRepository.findById(id).orElseThrow(() -> new UserException(USER_NOT_FOUND));
}

@Transactional
public void createUser(String accountEmail, String password) {
// 이미 존재하는 이메일인지 확인
Expand Down
Binary file modified src/main/resources/static/excel/example.xlsx
Binary file not shown.

0 comments on commit 5b16b27

Please sign in to comment.