From ad3afe8dff70e20440f87e90d295a36c7ec1b1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=ED=99=8D=EC=84=9D?= <78216059+bayy1216@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:49:11 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]:=20=EA=B2=BD=ED=97=98=EC=B9=98=20?= =?UTF-8?q?=ED=9A=8D=EB=93=9D=20=EC=9C=A0=EC=A6=88=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EC=97=90=EC=84=9C=20=EC=B2=98=EB=A6=AC=20(#89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userchallenge/domain/UserChallenge.java | 4 +-- .../AddUserExpByVerificationUseCase.java | 8 ++++- .../SubUserExpByVerificationEvent.java | 12 ++++++++ .../SubUserExpByVerificationUseCase.java | 29 +++++++++++++++++++ .../application/UserChallengeService.java | 2 +- 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationEvent.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationUseCase.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/UserChallenge.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/UserChallenge.java index 97aeabc..bf8b171 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/UserChallenge.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/UserChallenge.java @@ -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 diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/AddUserExpByVerificationUseCase.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/AddUserExpByVerificationUseCase.java index c70b89e..04eddfd 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/AddUserExpByVerificationUseCase.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/AddUserExpByVerificationUseCase.java @@ -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; @@ -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()); } } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationEvent.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationEvent.java new file mode 100644 index 0000000..d463ba7 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationEvent.java @@ -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; +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationUseCase.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationUseCase.java new file mode 100644 index 0000000..5e5d86d --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/SubUserExpByVerificationUseCase.java @@ -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()); + } +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/UserChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/UserChallengeService.java index 60841d6..7febd22 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/UserChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/userchallenge/domain/application/UserChallengeService.java @@ -81,7 +81,7 @@ public ChallengeModel.ChallengeVerificationResult verification( AddUserExpByVerificationEvent event = userChallenge.addChallengeVerification(command); - // 챌린지 경험치 획득 로직 + // 챌린지 경험치 획득 로직 (유저, 챌린지그룹-유저 경험치) addUserExpByVerificationUseCase.invoke(event); // 챌린지 RequiredCount 가져오기 위해 챌린지 정보 가져온다