Skip to content

Commit

Permalink
[Refactor]: 경험치 획득 유즈케이스에서 처리 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
bayy1216 committed Sep 9, 2024
1 parent 6e82b13 commit ad3afe8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,17 @@ public Long getChallengeId() {
* 1. 챌린지 인증을 추가
* 2. 챌린지 인증을 추가하면서 챌린지 인증에 따른 경험치를 추가
* 3. 챌린지를 완료한 경우 챌린지 완료로 변경, 경험치 추가
* 4. 챌린지그룹-경험치 추가 이벤트를 반환
* 4. 챌린지그룹-경험치 추가 이벤트를 반환(경험치 증가는 이벤트 핸들러에서 처리)
*/
public AddUserExpByVerificationEvent addChallengeVerification(ChallengeCommand.VerificationCreate command) {
ChallengeVerification challengeVerification = ChallengeVerification.create(command, this);
this.challengeVerifications.add(challengeVerification);

int acquiredExp = this.challenge.getOnceExp();
user.addExp(challenge.getOnceExp());

// 만약 챌린지 인증 참여횟수와 필요참여획수가 같으면 챌린지 완료로 변경
if (this.challengeVerifications.size() == this.challenge.getRequiredCount()) {
user.addExp(challenge.getSuccessExp());
acquiredExp += challenge.getSuccessExp();
this.completeChallengeStatus();
}
return AddUserExpByVerificationEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.haedal.zzansuni.userchallenge.domain.application;

import lombok.RequiredArgsConstructor;
import org.haedal.zzansuni.user.domain.User;
import org.haedal.zzansuni.user.domain.port.UserReader;
import org.haedal.zzansuni.userchallenge.domain.port.ChallengeGroupUserExpReader;
import org.haedal.zzansuni.userchallenge.domain.ChallengeGroupUserExp;
import org.springframework.stereotype.Component;
Expand All @@ -9,15 +11,19 @@
@Component
@RequiredArgsConstructor
public class AddUserExpByVerificationUseCase {
private final UserReader userReader;
private final ChallengeGroupUserExpReader challengeGroupUserExpReader;

@Transactional
public void invoke(AddUserExpByVerificationEvent event) {
Long challengeGroupId = event.getChallengeGroupId();
Long userId = event.getUserId();
Long challengeGroupId = event.getChallengeGroupId();

User user = userReader.getById(userId);
ChallengeGroupUserExp challengeGroupUserExp = challengeGroupUserExpReader
.findByChallengeGroupIdAndUserId(challengeGroupId, userId).orElseThrow();

user.addExp(event.getAcquiredExp());
challengeGroupUserExp.addExp(event.getAcquiredExp());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.haedal.zzansuni.userchallenge.domain.application;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor(staticName = "of")
public class SubUserExpByVerificationEvent {
private Long userId;
private Integer subExp;
private Long challengeGroupId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.haedal.zzansuni.userchallenge.domain.application;

import lombok.RequiredArgsConstructor;
import org.haedal.zzansuni.user.domain.User;
import org.haedal.zzansuni.user.domain.port.UserReader;
import org.haedal.zzansuni.userchallenge.domain.ChallengeGroupUserExp;
import org.haedal.zzansuni.userchallenge.domain.port.ChallengeGroupUserExpReader;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
public class SubUserExpByVerificationUseCase {
private final UserReader userReader;
private final ChallengeGroupUserExpReader challengeGroupUserExpReader;

@Transactional
public void invoke(SubUserExpByVerificationEvent event) {
Long userId = event.getUserId();
Long challengeGroupId = event.getChallengeGroupId();

User user = userReader.getById(userId);
ChallengeGroupUserExp challengeGroupUserExp = challengeGroupUserExpReader
.findByChallengeGroupIdAndUserId(challengeGroupId, userId).orElseThrow();

// user.subExp(event.getSubExp());
// challengeGroupUserExp.subExp(event.getSubExp());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ChallengeModel.ChallengeVerificationResult verification(

AddUserExpByVerificationEvent event = userChallenge.addChallengeVerification(command);

// 챌린지 경험치 획득 로직
// 챌린지 경험치 획득 로직 (유저, 챌린지그룹-유저 경험치)
addUserExpByVerificationUseCase.invoke(event);

// 챌린지 RequiredCount 가져오기 위해 챌린지 정보 가져온다
Expand Down

0 comments on commit ad3afe8

Please sign in to comment.