From dc546855cd47db7ab25874acc6b9edd24653cd7f Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 13:27:02 +0900 Subject: [PATCH 01/37] =?UTF-8?q?[Del]:=20ResourceNotFoundException.java?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0=ED=9B=84=20NoSuchElementException=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../exception/ResourceNotFoundException.java | 12 ------------ .../challenge/ChallengeReaderImpl.java | 4 +--- .../userchallenge/UserChallengeReaderImpl.java | 5 ++--- 3 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/exception/ResourceNotFoundException.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/exception/ResourceNotFoundException.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/exception/ResourceNotFoundException.java deleted file mode 100644 index 641034f..0000000 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/exception/ResourceNotFoundException.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.haedal.zzansuni.exception; - -public class ResourceNotFoundException extends RuntimeException { - - public ResourceNotFoundException(String datasource, long id) { - super(datasource + "에서 ID " + id + "를 찾을 수 없습니다."); - } - - public ResourceNotFoundException(String datasource, String id) { - super(datasource + "에서 ID " + id + "를 찾을 수 없습니다."); - } -} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeReaderImpl.java index a6f707a..d426303 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeReaderImpl.java @@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeReader; -import org.haedal.zzansuni.exception.ResourceNotFoundException; import org.springframework.stereotype.Component; @Component @@ -16,8 +15,7 @@ public class ChallengeReaderImpl implements ChallengeReader { @Override public Challenge getById(Long id) { - return findById(id).orElseThrow( - () -> new ResourceNotFoundException("Challenge", id)); + return findById(id).orElseThrow(NoSuchElementException::new); } @Override diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java index 687f548..1fb7b64 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java @@ -1,10 +1,10 @@ package org.haedal.zzansuni.infrastructure.challengegroup.userchallenge; +import java.util.NoSuchElementException; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; -import org.haedal.zzansuni.exception.ResourceNotFoundException; import org.springframework.stereotype.Component; @Component @@ -15,8 +15,7 @@ public class UserChallengeReaderImpl implements UserChallengeReader { @Override public UserChallenge getById(Long id) { - return findById(id).orElseThrow( - () -> new ResourceNotFoundException("UserChallenge", id)); + return findById(id).orElseThrow(NoSuchElementException::new); } @Override From baeee780949b75a0b491e87cc01f90849e7c1ecb Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 15:01:29 +0900 Subject: [PATCH 02/37] =?UTF-8?q?[Feat]:=20ChallengeCommand=EC=97=90=20Ver?= =?UTF-8?q?ificate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeCommand.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java new file mode 100644 index 0000000..1dff26d --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java @@ -0,0 +1,29 @@ +package org.haedal.zzansuni.domain.challengegroup.challenge; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Builder; +import lombok.Getter; +import org.haedal.zzansuni.core.utils.SelfValidating; +import org.springframework.web.multipart.MultipartFile; + +public class ChallengeCommand { + + @Getter + @Builder + public static class Verificate extends SelfValidating { + + @NotBlank(message = "내용은 필수입니다.") + private final String content; + + @NotNull(message = "이미지는 필수입니다.") + private final MultipartFile image; + + public Verificate(String content, MultipartFile image) { + this.content = content; + this.image = image; + this.validateSelf(); + } + } + +} From 5170230d6790d83359e39f8e680eaa9b4aebff58 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 15:02:24 +0900 Subject: [PATCH 03/37] =?UTF-8?q?[Feat]:=20ChallengeService=EC=97=90=20Ver?= =?UTF-8?q?ification=20=EC=A0=80=EC=9E=A5=EB=A1=9C=EC=A7=81=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeService.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index e6727d3..bdbfd30 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -1,9 +1,11 @@ package org.haedal.zzansuni.domain.challengegroup.challenge; -import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.haedal.zzansuni.domain.user.UserReader; -import org.haedal.zzansuni.domain.user.UserStore; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; +import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; +import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -13,5 +15,17 @@ public class ChallengeService { private final ChallengeReader challengeReader; private final ChallengeStore challengeStore; - + private final UserChallengeReader userChallengeReader; + + private final ChallengeVerificationStore challengeVerificationStore; + + /** + * 챌린지 인증하기 + */ + public void verification(Long userChallengeId, Verificate verificate) { + UserChallenge userChallenge = userChallengeReader.getById(userChallengeId); + ChallengeVerification challengeVerification = ChallengeVerification.create(verificate, + userChallenge); + challengeVerificationStore.store(challengeVerification); + } } From 71de21c81b29ae7c8c81d6e6f3861d3805325f97 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 15:03:05 +0900 Subject: [PATCH 04/37] =?UTF-8?q?[Feat]:=20ChallengeVerification=20domain?= =?UTF-8?q?=EC=97=90=20=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../ChallengeVerification.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) rename zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/{challenge => challengeverification}/ChallengeVerification.java (65%) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeVerification.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java similarity index 65% rename from zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeVerification.java rename to zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java index 98947fb..10acd5b 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeVerification.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java @@ -1,4 +1,4 @@ -package org.haedal.zzansuni.domain.challengegroup.challenge; +package org.haedal.zzansuni.domain.challengegroup.challengeverification; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -15,6 +15,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.haedal.zzansuni.domain.BaseTimeEntity; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeVerificationStatus; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; @Entity @@ -39,5 +41,14 @@ public class ChallengeVerification extends BaseTimeEntity { @Enumerated(EnumType.STRING) private ChallengeVerificationStatus status; + public static ChallengeVerification create(Verificate command, + UserChallenge userChallenge) { + return ChallengeVerification.builder() + .userChallenge(userChallenge) + .imageUrl(null) + .content(command.getContent()) + .status(ChallengeVerificationStatus.WAITING) + .build(); + } } From e02ceba2827c6160e5fe031cb240f92994817951 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 15:03:31 +0900 Subject: [PATCH 05/37] =?UTF-8?q?[Feat]:=20ChallengeVerification=20Reader,?= =?UTF-8?q?Store=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../ChallengeVerificationReader.java | 10 +++++++ .../ChallengeVerificationStore.java | 7 +++++ .../ChallengeVerificationReaderImpl.java | 27 +++++++++++++++++++ .../ChallengeVerificationRepository.java | 9 +++++++ .../ChallengeVerificationStoreImpl.java | 18 +++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationStore.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationStoreImpl.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java new file mode 100644 index 0000000..1486792 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java @@ -0,0 +1,10 @@ +package org.haedal.zzansuni.domain.challengegroup.challengeverification; + +import java.util.Optional; + +public interface ChallengeVerificationReader { + + ChallengeVerification getById(Long id); + + Optional findById(Long id); +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationStore.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationStore.java new file mode 100644 index 0000000..fc5e127 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationStore.java @@ -0,0 +1,7 @@ +package org.haedal.zzansuni.domain.challengegroup.challengeverification; + +public interface ChallengeVerificationStore { + + ChallengeVerification store(ChallengeVerification challengeVerification); + +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java new file mode 100644 index 0000000..11b5925 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java @@ -0,0 +1,27 @@ +package org.haedal.zzansuni.infrastructure.challengegroup.challengeverification; + +import java.util.NoSuchElementException; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; +import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ChallengeVerificationReaderImpl implements ChallengeVerificationReader { + + private final ChallengeVerificationRepository challengeVerificationRepository; + + @Override + public ChallengeVerification getById(Long id) { + return findById(id).orElseThrow(NoSuchElementException::new); + } + + @Override + public Optional findById(Long id) { + return challengeVerificationRepository.findById(id); + } + +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java new file mode 100644 index 0000000..a358df8 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java @@ -0,0 +1,9 @@ +package org.haedal.zzansuni.infrastructure.challengegroup.challengeverification; + +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ChallengeVerificationRepository extends + JpaRepository { + +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationStoreImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationStoreImpl.java new file mode 100644 index 0000000..79ec8cc --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationStoreImpl.java @@ -0,0 +1,18 @@ +package org.haedal.zzansuni.infrastructure.challengegroup.challengeverification; + +import lombok.RequiredArgsConstructor; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ChallengeVerificationStoreImpl implements ChallengeVerificationStore { + + private final ChallengeVerificationRepository challengeVerificationRepository; + + @Override + public ChallengeVerification store(ChallengeVerification challengeVerification) { + return challengeVerificationRepository.save(challengeVerification); + } +} From 419b7bdf629e1ace920b9ca980db99d054381045 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:28:11 +0900 Subject: [PATCH 06/37] =?UTF-8?q?[Feat]:=20ChallengeController=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=9D=B8=EC=A6=9D=20api=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index 0ae4d54..35b0b18 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -8,6 +8,7 @@ import org.haedal.zzansuni.controller.PagingRequest; import org.haedal.zzansuni.controller.PagingResponse; import org.haedal.zzansuni.core.api.ApiResponse; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeService; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeCommand; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeService; @@ -39,13 +40,19 @@ public ApiResponse challengeParticipation( } @Operation(summary = "챌린지 인증", description = "챌린지에 인증한다.") - @PostMapping("/api/challenges/{challengeId}/verification") + @PostMapping("/api/challenges/{userChallengeId}/verification") public ApiResponse challengeVerification( - @PathVariable Long challengeId, + @PathVariable Long userChallengeId, @RequestPart("body") ChallengeReq.ChallengeVerificationRequest request, - @RequestPart("image") MultipartFile image + @RequestPart("image") MultipartFile image, + @AuthenticationPrincipal JwtUser jwtUser ) { - throw new RuntimeException("Not implemented"); + ChallengeCommand.Verificate command = new ChallengeCommand.Verificate( + request.content(), image); + ChallengeRes.ChallengeVerificationResponse response = ChallengeRes.ChallengeVerificationResponse.from( + challengeService.verification(userChallengeId, command, jwtUser.getId()) + ); + return ApiResponse.success(response, "챌린지 인증에 성공하였습니다."); } @ResponseStatus(HttpStatus.CREATED) From 0c1039e57dda05dbf694e77ed099981fa80d0399 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:28:42 +0900 Subject: [PATCH 07/37] =?UTF-8?q?[Feat]:=20ChallengeModel=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91=20=EB=B0=8F=20ChallengeVerificationResult=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeModel.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java new file mode 100644 index 0000000..4aadf06 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java @@ -0,0 +1,51 @@ +package org.haedal.zzansuni.domain.challengegroup.challenge; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; +import org.haedal.zzansuni.domain.challengegroup.DayType; + +@Getter +@Builder +public class ChallengeModel { + + private Long id; + private ChallengeGroup challengeGroup; + private Integer requiredCount; + private DayType dayType; + private Integer onceExp; + private Integer successExp; + private Integer difficulty; + + public static ChallengeModel from(Challenge challenge) { + return ChallengeModel.builder() + .id(challenge.getId()) + .challengeGroup(challenge.getChallengeGroup()) + .requiredCount(challenge.getRequiredCount()) + .dayType(challenge.getDayType()) + .onceExp(challenge.getOnceExp()) + .successExp(challenge.getSuccessExp()) + .difficulty(challenge.getDifficulty()) + .build(); + } + + @Getter + @Builder + @AllArgsConstructor + public static class ChallengeVerificationResult { + + private Integer totalCount; + private Integer successCount; + private Integer obtainExp; + + public static ChallengeVerificationResult from(Integer totalCount, Integer successCount, + Integer obtainExp) { + return ChallengeVerificationResult.builder() + .totalCount(totalCount) + .successCount(successCount) + .obtainExp(obtainExp) + .build(); + } + } +} From 2f05315895b5fcd98523a43196cd04faf3027244 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:29:35 +0900 Subject: [PATCH 08/37] =?UTF-8?q?[Feat]:=20ChallengeRes=EC=97=90=EC=84=9C?= =?UTF-8?q?=20ChallengeVerificationResponse=20=EC=83=9D=EC=84=B1=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/challenge/ChallengeRes.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java index f1fde44..8044cf5 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java @@ -6,6 +6,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; +import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; public class ChallengeRes { @@ -16,6 +18,14 @@ public record ChallengeVerificationResponse( Integer obtainExp ) { + public static ChallengeVerificationResponse from( + ChallengeModel.ChallengeVerificationResult result) { + return ChallengeVerificationResponse.builder() + .totalCount(result.getTotalCount()) + .successCount(result.getSuccessCount()) + .obtainExp(result.getObtainExp()) + .build(); + } } @Builder From 3df53cb82bdbebc2a814524c984eae51b3687e63 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:30:06 +0900 Subject: [PATCH 09/37] =?UTF-8?q?[Feat]:=20ChallengeService=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeService.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index bdbfd30..d7829f7 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -1,8 +1,10 @@ package org.haedal.zzansuni.domain.challengegroup.challenge; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; @@ -10,6 +12,7 @@ @RequiredArgsConstructor @Service +@Slf4j public class ChallengeService { private final ChallengeReader challengeReader; @@ -18,14 +21,33 @@ public class ChallengeService { private final UserChallengeReader userChallengeReader; private final ChallengeVerificationStore challengeVerificationStore; + private final ChallengeVerificationReader challengeVerificationReader; /** - * 챌린지 인증하기 + * 챌린지 인증하기 1. ChallengeVerification 테이블에 데이터 추가 2. Challenge 엔티티에서 필요참여횟수 가져오기 3. UserChallenge + * 엔티티에서 참여횟수 가져오기 4. 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 */ - public void verification(Long userChallengeId, Verificate verificate) { + public ChallengeModel.ChallengeVerificationResult verification(Long userChallengeId, + Verificate verificate, Long userId) { UserChallenge userChallenge = userChallengeReader.getById(userChallengeId); ChallengeVerification challengeVerification = ChallengeVerification.create(verificate, userChallenge); challengeVerificationStore.store(challengeVerification); + + Challenge challenge = userChallenge.getChallenge(); + + /** + * 사용자가 챌린지를 몇번 수행했는지 가져온다 + */ + Integer currentCount = challengeVerificationReader.countByUserChallengeId(userChallengeId); + log.info("currentCount: {}", currentCount); + /** + * 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 + */ + + userChallenge.verification(currentCount, challenge.getRequiredCount()); + + return ChallengeModel.ChallengeVerificationResult + .from(challenge.getRequiredCount(), currentCount, challenge.getOnceExp()); } } From a69fc8bcf7077cd5ab7ee65faa4de358df64c0aa Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:30:35 +0900 Subject: [PATCH 10/37] =?UTF-8?q?[Refact]:=20ChallengeStatus=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../domain/challengegroup/challenge/ChallengeStatus.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeStatus.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeStatus.java index 97fb2ae..2d876c1 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeStatus.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeStatus.java @@ -5,7 +5,8 @@ @RequiredArgsConstructor public enum ChallengeStatus { PROCEEDING("진행중"), - FINISHED("종료"); + SUCCESS("성공"), + FAIL("실패"); private final String korean; } From 043b86f2236428ca1ca6d5d51964e56bdb5076ab Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:31:10 +0900 Subject: [PATCH 11/37] =?UTF-8?q?[Feat]:=20ChallengeVerification=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=20=EC=83=81=ED=83=9C=20=EC=8A=B9=EC=9D=B8?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengeverification/ChallengeVerification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java index 10acd5b..5cbf540 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerification.java @@ -47,7 +47,7 @@ public static ChallengeVerification create(Verificate command, .userChallenge(userChallenge) .imageUrl(null) .content(command.getContent()) - .status(ChallengeVerificationStatus.WAITING) + .status(ChallengeVerificationStatus.APPROVED) .build(); } From 14eecce58f1410e1780ca9d3ebd3e9933240c3ec Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:31:46 +0900 Subject: [PATCH 12/37] =?UTF-8?q?[Feat]:=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=ED=9A=9F=EC=88=98=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?dao=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../ChallengeVerificationReader.java | 5 +++++ .../ChallengeVerificationReaderImpl.java | 8 ++++++++ .../ChallengeVerificationRepository.java | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java index 1486792..4bd629c 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java @@ -7,4 +7,9 @@ public interface ChallengeVerificationReader { ChallengeVerification getById(Long id); Optional findById(Long id); + + /** + * 사용자 챌린지를 이용하여 챌린지 인증을 몇번 했는지 조회한다. + */ + Integer countByUserChallengeId(Long userChallengeId); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java index 11b5925..3535e7e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java @@ -24,4 +24,12 @@ public Optional findById(Long id) { return challengeVerificationRepository.findById(id); } + /** + * 사용자 챌린지를 이용하여 챌린지 인증을 몇번 했는지 조회한다. + */ + @Override + public Integer countByUserChallengeId(Long userChallengeId) { + return challengeVerificationRepository.countByUserChallengeId(userChallengeId); + } + } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java index a358df8..a16746d 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java @@ -6,4 +6,11 @@ public interface ChallengeVerificationRepository extends JpaRepository { + /** + * 사용자 챌린지를 이용하여 챌린지 인증을 몇번 했는지 조회한다. + * + * @param userChallengeId + * @return Integer + */ + Integer countByUserChallengeId(Long userChallengeId); } From 6a566ae1f9ce96c446e172c0248b637790e0ca70 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:32:51 +0900 Subject: [PATCH 13/37] =?UTF-8?q?[Feat]:=20UserChallenge=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 챌린지 인증 참여횟수와 필요참여획수가 같으면 챌린지 완료로 변경 #5 --- .../userchallenge/UserChallenge.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java index 3324d7b..e5d5f35 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java @@ -48,4 +48,19 @@ public static UserChallenge from(Challenge challenge, User user) { .status(ChallengeStatus.PROCEEDING) .build(); } + + private void complete() { + this.status = ChallengeStatus.SUCCESS; + } + + /** + * 챌린지 인증 참여횟수와 필요참여획수가 같으면 챌린지 완료로 변경 + */ + public void verification(Integer currentCount, Integer requiredCount) { + if (currentCount.equals(requiredCount)) { + complete(); + } + } + + } From 5d1b0314fdfc4b1aad0a077dbd3d1dad13ea63a2 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:33:40 +0900 Subject: [PATCH 14/37] =?UTF-8?q?[Feat]:=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=EB=A1=9C=EC=A7=81=20Todo=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 챌린지 그룹 누적 참여자수 증가 로직 todo 작성 #5 --- .../challengegroup/userchallenge/UserChallengeService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java index 67dcfc9..b369a3e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java @@ -25,6 +25,8 @@ public void participateChallenge(Long userId, Challenge challenge = challengeReader.getById(participateInfo.getChallengeId()); UserChallenge userChallenge = UserChallenge.from(challenge, user); userChallengeStore.store(userChallenge); + + // TODO: 챌린지 그룹 누적 참여자수 증가 로직 추가 } } From ddac9ec4f725932dff1679ceb0e81e0f06d097f0 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:44:23 +0900 Subject: [PATCH 15/37] =?UTF-8?q?[Fix]:=20Controller=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B8=EC=A6=9D=20jwtUser=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/challenge/ChallengeController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index 35b0b18..e4da60e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -44,13 +44,12 @@ public ApiResponse challengeParticipation( public ApiResponse challengeVerification( @PathVariable Long userChallengeId, @RequestPart("body") ChallengeReq.ChallengeVerificationRequest request, - @RequestPart("image") MultipartFile image, - @AuthenticationPrincipal JwtUser jwtUser + @RequestPart("image") MultipartFile image ) { ChallengeCommand.Verificate command = new ChallengeCommand.Verificate( request.content(), image); ChallengeRes.ChallengeVerificationResponse response = ChallengeRes.ChallengeVerificationResponse.from( - challengeService.verification(userChallengeId, command, jwtUser.getId()) + challengeService.verification(userChallengeId, command) ); return ApiResponse.success(response, "챌린지 인증에 성공하였습니다."); } From 0967f80ee0b8cdf85a1fcb254fb2dc7936d93e4a Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:45:12 +0900 Subject: [PATCH 16/37] =?UTF-8?q?[Fix]:=20ChallengeService=20Transactional?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../domain/challengegroup/challenge/ChallengeService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index d7829f7..e05f1fa 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -9,10 +9,12 @@ import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service @Slf4j +@Transactional public class ChallengeService { private final ChallengeReader challengeReader; @@ -28,7 +30,7 @@ public class ChallengeService { * 엔티티에서 참여횟수 가져오기 4. 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 */ public ChallengeModel.ChallengeVerificationResult verification(Long userChallengeId, - Verificate verificate, Long userId) { + Verificate verificate) { UserChallenge userChallenge = userChallengeReader.getById(userChallengeId); ChallengeVerification challengeVerification = ChallengeVerification.create(verificate, userChallenge); @@ -44,7 +46,6 @@ public ChallengeModel.ChallengeVerificationResult verification(Long userChalleng /** * 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 */ - userChallenge.verification(currentCount, challenge.getRequiredCount()); return ChallengeModel.ChallengeVerificationResult From ebd61748a2f3b156e74f55ccc3738e2ad4747492 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 16:46:38 +0900 Subject: [PATCH 17/37] =?UTF-8?q?[Fix]:=20UserChallengeService=20Transacti?= =?UTF-8?q?onal=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/userchallenge/UserChallengeService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java index b369a3e..2460af7 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java @@ -6,9 +6,11 @@ import org.haedal.zzansuni.domain.user.User; import org.haedal.zzansuni.domain.user.UserReader; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Transactional public class UserChallengeService { private final UserChallengeStore userChallengeStore; From c790d786b4575b46df9b7e3b3c611fa2cf7574d1 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:40:51 +0900 Subject: [PATCH 18/37] =?UTF-8?q?[Fix]:=20Challenge=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit startDate, endDate 추가 #5 --- .../zzansuni/domain/challengegroup/challenge/Challenge.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/Challenge.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/Challenge.java index 96a0494..23008b5 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/Challenge.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/Challenge.java @@ -9,6 +9,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import java.time.LocalDate; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -44,5 +45,9 @@ public class Challenge extends BaseTimeEntity { private Integer difficulty; + private LocalDate startDate; + + private LocalDate endDate; + } From 0719072b7d2bd6666d43d4c4e76162fd171cba41 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:41:38 +0900 Subject: [PATCH 19/37] =?UTF-8?q?[Feat]:=20ChallengeController=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EA=B8=B0=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeController.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index e4da60e..b9e3cc8 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -27,6 +27,7 @@ public class ChallengeController { private final ChallengeService challengeService; private final UserChallengeService userChallengeService; + @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "챌린지 참여", description = "챌린지에 참여한다.") @PostMapping("/api/challenges/{challengeId}/join") public ApiResponse challengeParticipation( @@ -34,11 +35,12 @@ public ApiResponse challengeParticipation( @AuthenticationPrincipal JwtUser jwtUser ) { UserChallengeCommand.Participate command = new UserChallengeCommand.Participate(challengeId, - jwtUser.getId()); - userChallengeService.participateChallenge(jwtUser.getId(), command); + 1L); + userChallengeService.participateChallenge(1L, command); return ApiResponse.success(null, "챌린지 참여에 성공하였습니다."); } + @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "챌린지 인증", description = "챌린지에 인증한다.") @PostMapping("/api/challenges/{userChallengeId}/verification") public ApiResponse challengeVerification( @@ -65,13 +67,17 @@ public ApiResponse challengeReviewCreate( throw new RuntimeException("Not implemented"); } + @ResponseStatus(HttpStatus.OK) @Operation(summary = "챌린지 기록 조회", description = "챌린지 기록을 조회한다.") @GetMapping("/api/challenges/{challengeId}/record") public ApiResponse getChallengeRecord( @PathVariable Long challengeId, @AuthenticationPrincipal JwtUser jwtUser ) { - throw new RuntimeException("Not implemented"); + ChallengeRes.ChallengeRecordResponse response = ChallengeRes.ChallengeRecordResponse.from( + challengeService.getChallengeRecord(1L, challengeId) + ); + return ApiResponse.success(response, "챌린지 기록 조회에 성공하였습니다."); } @Operation(summary = "챌린지 기록 상세 조회", description = "챌린지 기록 상세를 조회한다.") @@ -80,6 +86,7 @@ public ApiResponse getChallengeRecordDeta @PathVariable Long recordId, @AuthenticationPrincipal JwtUser jwtUser ) { + throw new RuntimeException("Not implemented"); } From 3f3433c3a227f618ca87d372ca39a53d7483ba88 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:42:15 +0900 Subject: [PATCH 20/37] =?UTF-8?q?[Feat]:=20ChallengeModel=EC=97=90=20Chall?= =?UTF-8?q?engeRecordDto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeModel.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java index 4aadf06..7e67c6f 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java @@ -1,10 +1,15 @@ package org.haedal.zzansuni.domain.challengegroup.challenge; +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; import org.haedal.zzansuni.domain.challengegroup.DayType; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; @Getter @Builder @@ -35,9 +40,9 @@ public static ChallengeModel from(Challenge challenge) { @AllArgsConstructor public static class ChallengeVerificationResult { - private Integer totalCount; - private Integer successCount; - private Integer obtainExp; + private final Integer totalCount; + private final Integer successCount; + private final Integer obtainExp; public static ChallengeVerificationResult from(Integer totalCount, Integer successCount, Integer obtainExp) { @@ -48,4 +53,31 @@ public static ChallengeVerificationResult from(Integer totalCount, Integer succe .build(); } } + + @Getter + @Builder + @AllArgsConstructor + public static class ChallengeRecordDto { + + private final String title; + private final Integer totalCount; + private final Integer successCount; + private final LocalDate startDate; + private final LocalDate endDate; + private final List recordIds; + + public static ChallengeRecordDto from(Challenge challenge, ChallengeGroup challengeGroup, + List challengeVerificationList) { + return ChallengeRecordDto.builder() + .title(challengeGroup.getTitle()) + .totalCount(challenge.getRequiredCount()) + .successCount(challengeVerificationList.size()) + .startDate(challenge.getStartDate()) + .endDate(challenge.getEndDate()) + .recordIds(challengeVerificationList.stream() + .map(ChallengeVerification::getId) + .collect(Collectors.toList())) + .build(); + } + } } From 923c6105241ac5de4ec6f37ae047874e7cd56bff Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:42:50 +0900 Subject: [PATCH 21/37] =?UTF-8?q?[Feat]:=20ChallengeRes=EC=97=90=EC=84=9C?= =?UTF-8?q?=20ChallengeRecordResponse=20=EC=83=9D=EC=84=B1=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/challenge/ChallengeRes.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java index 8044cf5..4a15b22 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java @@ -38,6 +38,16 @@ public record ChallengeRecordResponse( List recordIds ) { + public static ChallengeRecordResponse from(ChallengeModel.ChallengeRecordDto dto) { + return ChallengeRecordResponse.builder() + .title(dto.getTitle()) + .totalCount(dto.getTotalCount()) + .successCount(dto.getSuccessCount()) + .startDate(dto.getStartDate()) + .endDate(dto.getEndDate()) + .recordIds(dto.getRecordIds()) + .build(); + } } @Builder From 19cb467641e14b49b2df409cbd972486cd655ceb Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:43:20 +0900 Subject: [PATCH 22/37] =?UTF-8?q?[Feat]:=20ChallengeService=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EA=B8=B0=EB=A1=9D=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index e05f1fa..db9680a 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; @@ -32,10 +33,14 @@ public class ChallengeService { public ChallengeModel.ChallengeVerificationResult verification(Long userChallengeId, Verificate verificate) { UserChallenge userChallenge = userChallengeReader.getById(userChallengeId); + // TODO 이미지 업로드 로직 필요 ChallengeVerification challengeVerification = ChallengeVerification.create(verificate, userChallenge); challengeVerificationStore.store(challengeVerification); + /** + * 챌린지 RequiredCount 가져오기 위해 챌린지 정보 가져온다 + */ Challenge challenge = userChallenge.getChallenge(); /** @@ -51,4 +56,18 @@ public ChallengeModel.ChallengeVerificationResult verification(Long userChalleng return ChallengeModel.ChallengeVerificationResult .from(challenge.getRequiredCount(), currentCount, challenge.getOnceExp()); } + + /** + * 챌린지 기록 가져오기 + */ + public ChallengeModel.ChallengeRecordDto getChallengeRecord(Long userId, Long challengeId) { + Challenge challenge = challengeReader.getById(challengeId); + ChallengeGroup challengeGroup = challenge.getChallengeGroup(); + UserChallenge userChallenge = userChallengeReader.getByUserIdAndChallengeId(userId, + challengeId); + return ChallengeModel.ChallengeRecordDto + .from(challenge, challengeGroup, + challengeVerificationReader.findByUserChallengeId(userChallenge.getId())); + + } } From f7e26ee0974afcb7262dbb9a23240ab45de3060c Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:46:35 +0900 Subject: [PATCH 23/37] =?UTF-8?q?[Feat]:=20ChallengeVerificationReader?= =?UTF-8?q?=EC=97=90=20findByUserChallengeId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengeverification/ChallengeVerificationReader.java | 4 ++++ .../ChallengeVerificationReaderImpl.java | 6 ++++++ .../ChallengeVerificationRepository.java | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java index 4bd629c..9695ac9 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationReader.java @@ -1,5 +1,6 @@ package org.haedal.zzansuni.domain.challengegroup.challengeverification; +import java.util.List; import java.util.Optional; public interface ChallengeVerificationReader { @@ -12,4 +13,7 @@ public interface ChallengeVerificationReader { * 사용자 챌린지를 이용하여 챌린지 인증을 몇번 했는지 조회한다. */ Integer countByUserChallengeId(Long userChallengeId); + + List findByUserChallengeId(Long id); + } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java index 3535e7e..21542f6 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationReaderImpl.java @@ -1,5 +1,6 @@ package org.haedal.zzansuni.infrastructure.challengegroup.challengeverification; +import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -32,4 +33,9 @@ public Integer countByUserChallengeId(Long userChallengeId) { return challengeVerificationRepository.countByUserChallengeId(userChallengeId); } + @Override + public List findByUserChallengeId(Long id) { + return challengeVerificationRepository.findByUserChallengeId(id); + } + } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java index a16746d..0a355e7 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengeverification/ChallengeVerificationRepository.java @@ -1,5 +1,6 @@ package org.haedal.zzansuni.infrastructure.challengegroup.challengeverification; +import java.util.List; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,4 +14,7 @@ public interface ChallengeVerificationRepository extends * @return Integer */ Integer countByUserChallengeId(Long userChallengeId); + + List findByUserChallengeId(Long id); + } From 37cd305674a5b834b3d0d18f0dcfff9d81a2344a Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 21:47:02 +0900 Subject: [PATCH 24/37] =?UTF-8?q?[Feat]:=20UserChallengeReader=EC=97=90=20?= =?UTF-8?q?getByUserIdAndChallengeId,findByUserIdAndChallengeId=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../userchallenge/UserChallengeReader.java | 4 ++++ .../userchallenge/UserChallengeReaderImpl.java | 11 +++++++++++ .../userchallenge/UserChallengeRepository.java | 3 +++ 3 files changed, 18 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java index 7480d1f..03d93f1 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java @@ -7,4 +7,8 @@ public interface UserChallengeReader { UserChallenge getById(Long id); Optional findById(Long id); + + UserChallenge getByUserIdAndChallengeId(Long userId, Long challengeId); + + Optional findByUserIdAndChallengeId(Long userId, Long challengeId); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java index 1fb7b64..af6734c 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java @@ -22,4 +22,15 @@ public UserChallenge getById(Long id) { public Optional findById(Long id) { return userChallengeRepository.findById(id); } + + @Override + public UserChallenge getByUserIdAndChallengeId(Long userId, Long challengeId) { + return findByUserIdAndChallengeId(userId, challengeId).orElseThrow( + NoSuchElementException::new); + } + + @Override + public Optional findByUserIdAndChallengeId(Long userId, Long challengeId) { + return userChallengeRepository.findByUserIdAndChallengeId(userId, challengeId); + } } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java index 0b5a3aa..e796415 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java @@ -1,8 +1,11 @@ package org.haedal.zzansuni.infrastructure.challengegroup.userchallenge; +import java.util.Optional; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; import org.springframework.data.jpa.repository.JpaRepository; public interface UserChallengeRepository extends JpaRepository { + Optional findByUserIdAndChallengeId(Long userId, Long challengeId); + } From 4d5914472476e06a9c5500f8cdd49495369551c2 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 23:52:29 +0900 Subject: [PATCH 25/37] =?UTF-8?q?[Feat]:=20ChallengeController=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EA=B8=B0=EB=A1=9D=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/challenge/ChallengeController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index b9e3cc8..da1ef48 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -80,14 +80,17 @@ public ApiResponse getChallengeRecord( return ApiResponse.success(response, "챌린지 기록 조회에 성공하였습니다."); } + @Operation(summary = "챌린지 기록 상세 조회", description = "챌린지 기록 상세를 조회한다.") @GetMapping("/api/challenges/record/{recordId}") public ApiResponse getChallengeRecordDetail( @PathVariable Long recordId, @AuthenticationPrincipal JwtUser jwtUser ) { - - throw new RuntimeException("Not implemented"); + ChallengeRes.ChallengeRecordDetailDto response = ChallengeRes.ChallengeRecordDetailDto.from( + challengeService.getChallengeRecordDetail(recordId) + ); + return ApiResponse.success(response, "챌린지 기록 상세 조회에 성공하였습니다."); } @Operation(summary = "진행중인 챌린지 조회", description = "진행중인 챌린지 조회한다.") From ee608d8d6ba72f604f9e6ae625ecf9221705b9e4 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 23:53:09 +0900 Subject: [PATCH 26/37] =?UTF-8?q?[Feat]:=20ChallengeRecordDetailDto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/challenge/ChallengeRes.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java index 4a15b22..49ec50e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java @@ -8,6 +8,7 @@ import java.util.List; import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationModel; public class ChallengeRes { @@ -58,6 +59,16 @@ public record ChallengeRecordDetailDto( String imageUrl ) { + public static ChallengeRecordDetailDto from(ChallengeVerificationModel model) { + return ChallengeRecordDetailDto.builder() + .id(model.getId()) + .createdAt(model.getCreatedAt()) + .content(model.getContent()) + .imageUrl(model.getImageUrl()) + .build(); + + } + } From 38233c915018059055645eec8b7413b357541d6b Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 23:53:36 +0900 Subject: [PATCH 27/37] =?UTF-8?q?[Feat]:=20sevice=EC=97=90=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EA=B8=B0=EB=A1=9D=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../domain/challengegroup/challenge/ChallengeService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index db9680a..72a90fa 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -5,6 +5,7 @@ import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationModel; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; @@ -70,4 +71,11 @@ public ChallengeModel.ChallengeRecordDto getChallengeRecord(Long userId, Long ch challengeVerificationReader.findByUserChallengeId(userChallenge.getId())); } + + /** + * 챌린지 기록 상세 가져오기 + */ + public ChallengeVerificationModel getChallengeRecordDetail(Long recordId) { + return ChallengeVerificationModel.from(challengeVerificationReader.getById(recordId)); + } } From 1ec67521995cc61f3b1c202f40900abd5ac6a0d1 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Fri, 31 May 2024 23:53:49 +0900 Subject: [PATCH 28/37] =?UTF-8?q?[Feat]:=20ChallengeVerificationModel=20?= =?UTF-8?q?=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../ChallengeVerificationModel.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationModel.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationModel.java new file mode 100644 index 0000000..6a7eb6b --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengeverification/ChallengeVerificationModel.java @@ -0,0 +1,25 @@ +package org.haedal.zzansuni.domain.challengegroup.challengeverification; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class ChallengeVerificationModel { + + private final Long id; + private final LocalDateTime createdAt; + private final String content; + private final String imageUrl; + + public static ChallengeVerificationModel from(ChallengeVerification challengeVerification) { + return ChallengeVerificationModel.builder() + .id(challengeVerification.getId()) + .createdAt(challengeVerification.getCreatedAt()) + .content(challengeVerification.getContent()) + .imageUrl(challengeVerification.getImageUrl()) + .build(); + } +} From 3f7648f6e1c6ef774826078e46123f09ea04d61c Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:03:25 +0900 Subject: [PATCH 29/37] =?UTF-8?q?[Feat]:=20ChallengeCommand=20review=20cre?= =?UTF-8?q?ate=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeCommand.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java index 1dff26d..9f11ef1 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCommand.java @@ -26,4 +26,21 @@ public Verificate(String content, MultipartFile image) { } } + @Getter + @Builder + public static class ReviewCreate extends SelfValidating { + + @NotBlank(message = "내용은 필수입니다.") + private final String content; + + @NotNull(message = "평점은 필수입니다.") + private final Integer rating; + + public ReviewCreate(String content, Integer rating) { + this.content = content; + this.rating = rating; + this.validateSelf(); + } + } + } From 5904dade3929f46a5c8a8df4516514669d71d825 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:04:41 +0900 Subject: [PATCH 30/37] =?UTF-8?q?[Feat]:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=EC=97=90=20=EB=A6=AC=EB=B7=B0=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeController.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index da1ef48..9683963 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -36,7 +36,7 @@ public ApiResponse challengeParticipation( ) { UserChallengeCommand.Participate command = new UserChallengeCommand.Participate(challengeId, 1L); - userChallengeService.participateChallenge(1L, command); + userChallengeService.participateChallenge(jwtUser.getId(), command); return ApiResponse.success(null, "챌린지 참여에 성공하였습니다."); } @@ -64,7 +64,9 @@ public ApiResponse challengeReviewCreate( @AuthenticationPrincipal JwtUser jwtUser, @RequestBody ChallengeReq.ChallengeReviewCreateRequest request ) { - throw new RuntimeException("Not implemented"); + Long response = challengeService.reviewCreate(request.toCommand(), challengeId, + jwtUser.getId()); + return ApiResponse.success(response, "챌린지 리뷰 작성에 성공하였습니다."); } @ResponseStatus(HttpStatus.OK) @@ -75,7 +77,7 @@ public ApiResponse getChallengeRecord( @AuthenticationPrincipal JwtUser jwtUser ) { ChallengeRes.ChallengeRecordResponse response = ChallengeRes.ChallengeRecordResponse.from( - challengeService.getChallengeRecord(1L, challengeId) + challengeService.getChallengeRecord(jwtUser.getId(), challengeId) ); return ApiResponse.success(response, "챌린지 기록 조회에 성공하였습니다."); } @@ -90,15 +92,17 @@ public ApiResponse getChallengeRecordDeta ChallengeRes.ChallengeRecordDetailDto response = ChallengeRes.ChallengeRecordDetailDto.from( challengeService.getChallengeRecordDetail(recordId) ); + log.info("response: {}", response); return ApiResponse.success(response, "챌린지 기록 상세 조회에 성공하였습니다."); } @Operation(summary = "진행중인 챌린지 조회", description = "진행중인 챌린지 조회한다.") @GetMapping("/api/user/challenges/currents") - public ApiResponse> getChallengeCurrentsPaging( + public ApiResponse> getChallengeCurrentsPaging( @Valid PagingRequest pagingRequest, @AuthenticationPrincipal JwtUser jwtUser ) { +// challengeService.getChallengeCurrentsPaging(1L, pagingRequest); throw new RuntimeException("Not implemented"); } From 938fe9b739b6cfec32c89c6fe8fb4ba7c0b2b535 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:05:16 +0900 Subject: [PATCH 31/37] =?UTF-8?q?[Refact]:=20static->record=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeModel.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java index 7e67c6f..8a2c2a3 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java @@ -1,11 +1,13 @@ package org.haedal.zzansuni.domain.challengegroup.challenge; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory; import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; import org.haedal.zzansuni.domain.challengegroup.DayType; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; @@ -35,14 +37,9 @@ public static ChallengeModel from(Challenge challenge) { .build(); } - @Getter @Builder - @AllArgsConstructor - public static class ChallengeVerificationResult { - - private final Integer totalCount; - private final Integer successCount; - private final Integer obtainExp; + public record ChallengeVerificationResult(Integer totalCount, Integer successCount, + Integer obtainExp) { public static ChallengeVerificationResult from(Integer totalCount, Integer successCount, Integer obtainExp) { @@ -54,17 +51,10 @@ public static ChallengeVerificationResult from(Integer totalCount, Integer succe } } - @Getter - @Builder - @AllArgsConstructor - public static class ChallengeRecordDto { - private final String title; - private final Integer totalCount; - private final Integer successCount; - private final LocalDate startDate; - private final LocalDate endDate; - private final List recordIds; + @Builder + public record ChallengeRecordDto(String title, Integer totalCount, Integer successCount, + LocalDate startDate, LocalDate endDate, List recordIds) { public static ChallengeRecordDto from(Challenge challenge, ChallengeGroup challengeGroup, List challengeVerificationList) { @@ -80,4 +70,6 @@ public static ChallengeRecordDto from(Challenge challenge, ChallengeGroup challe .build(); } } + + } From fb27b0164269222be8e38dd3f0473449be5d6062 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:06:05 +0900 Subject: [PATCH 32/37] =?UTF-8?q?[Feat]:=20=EB=A6=AC=EB=B7=B0=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20req=20tocommand=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challengegroup/challenge/ChallengeReq.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java index 89af4a0..28447c7 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java @@ -1,15 +1,27 @@ package org.haedal.zzansuni.controller.challengegroup.challenge; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; + public class ChallengeReq { public record ChallengeVerificationRequest( - String content + String content ) { + } public record ChallengeReviewCreateRequest( - String content, - Integer rating + String content, + Integer rating ) { + + public ChallengeCommand.ReviewCreate toCommand() { + return ChallengeCommand.ReviewCreate.builder() + .content(content) + .rating(rating) + .build(); + } } + } From 511310c0be914abd8e4aa1342c88e37e44a09c2a Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:06:41 +0900 Subject: [PATCH 33/37] =?UTF-8?q?[Feat]:=20review=20create=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeRes.java | 25 +++++++++---------- .../ChallengeReview.java | 11 +++++++- 2 files changed, 22 insertions(+), 14 deletions(-) rename zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/{challenge => challengereview}/ChallengeReview.java (73%) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java index 49ec50e..bc0929a 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java @@ -6,7 +6,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; -import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationModel; @@ -22,9 +21,9 @@ public record ChallengeVerificationResponse( public static ChallengeVerificationResponse from( ChallengeModel.ChallengeVerificationResult result) { return ChallengeVerificationResponse.builder() - .totalCount(result.getTotalCount()) - .successCount(result.getSuccessCount()) - .obtainExp(result.getObtainExp()) + .totalCount(result.totalCount()) + .successCount(result.successCount()) + .obtainExp(result.obtainExp()) .build(); } } @@ -41,12 +40,12 @@ public record ChallengeRecordResponse( public static ChallengeRecordResponse from(ChallengeModel.ChallengeRecordDto dto) { return ChallengeRecordResponse.builder() - .title(dto.getTitle()) - .totalCount(dto.getTotalCount()) - .successCount(dto.getSuccessCount()) - .startDate(dto.getStartDate()) - .endDate(dto.getEndDate()) - .recordIds(dto.getRecordIds()) + .title(dto.title()) + .totalCount(dto.totalCount()) + .successCount(dto.successCount()) + .startDate(dto.startDate()) + .endDate(dto.endDate()) + .recordIds(dto.recordIds()) .build(); } } @@ -73,13 +72,13 @@ public static ChallengeRecordDetailDto from(ChallengeVerificationModel model) { @Builder - public record ChallengeCurrentDto( - Long id, + public record ChallengeCurrentResponse( + Long challengeId, String title, Integer successCount, Integer totalCount, - LocalDate participationDate, + LocalDateTime participationDate, LocalDate startDate, LocalDate endDate, diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeReview.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java similarity index 73% rename from zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeReview.java rename to zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java index d90293c..0330e75 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeReview.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java @@ -1,4 +1,4 @@ -package org.haedal.zzansuni.domain.challengegroup.challenge; +package org.haedal.zzansuni.domain.challengegroup.challengereview; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -34,4 +34,13 @@ public class ChallengeReview extends BaseTimeEntity { private Integer rating; + public static ChallengeReview create(UserChallenge userChallenge, String content, + Integer rating) { + return ChallengeReview.builder() + .userChallenge(userChallenge) + .content(content) + .rating(rating) + .build(); + } + } From 68b4fe76f465ddb6355f8bc272a1104918136e8b Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:07:01 +0900 Subject: [PATCH 34/37] =?UTF-8?q?[Feat]:=20review=EA=B4=80=EB=A0=A8=20dao?= =?UTF-8?q?=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../ChallengeReviewReader.java | 11 ++++++++ .../challengereview/ChallengeReviewStore.java | 7 +++++ .../ChallengeReviewReaderImpl.java | 27 +++++++++++++++++++ .../ChallengeReviewRepository.java | 10 +++++++ .../ChallengeReviewStoreImpl.java | 19 +++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewReader.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewStore.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewReaderImpl.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewRepository.java create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewStoreImpl.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewReader.java new file mode 100644 index 0000000..5b1bc1f --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewReader.java @@ -0,0 +1,11 @@ +package org.haedal.zzansuni.domain.challengegroup.challengereview; + +import java.util.Optional; + +public interface ChallengeReviewReader { + + ChallengeReview getByChallengeId(Long challengeId); + + Optional findByUserChallengeId(Long challengeId); + +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewStore.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewStore.java new file mode 100644 index 0000000..cb34791 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReviewStore.java @@ -0,0 +1,7 @@ +package org.haedal.zzansuni.domain.challengegroup.challengereview; + +public interface ChallengeReviewStore { + + ChallengeReview store(ChallengeReview challengeReview); + +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewReaderImpl.java new file mode 100644 index 0000000..cc806e1 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewReaderImpl.java @@ -0,0 +1,27 @@ +package org.haedal.zzansuni.infrastructure.challengegroup.challengereview; + +import java.util.NoSuchElementException; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReview; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReviewReader; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ChallengeReviewReaderImpl implements ChallengeReviewReader { + + private final ChallengeReviewRepository challengeReviewRepository; + + @Override + public ChallengeReview getByChallengeId(Long challengeId) { + return challengeReviewRepository.findByUserChallengeId(challengeId) + .orElseThrow(NoSuchElementException::new); + } + + @Override + public Optional findByUserChallengeId(Long challengeId) { + return challengeReviewRepository.findByUserChallengeId(challengeId); + } + +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewRepository.java new file mode 100644 index 0000000..514f764 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewRepository.java @@ -0,0 +1,10 @@ +package org.haedal.zzansuni.infrastructure.challengegroup.challengereview; + +import java.util.Optional; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReview; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ChallengeReviewRepository extends JpaRepository { + + Optional findByUserChallengeId(Long userChallengeId); +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewStoreImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewStoreImpl.java new file mode 100644 index 0000000..a5829d5 --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challengereview/ChallengeReviewStoreImpl.java @@ -0,0 +1,19 @@ +package org.haedal.zzansuni.infrastructure.challengegroup.challengereview; + +import lombok.RequiredArgsConstructor; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReview; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReviewStore; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; + +@Component +@RequiredArgsConstructor +public class ChallengeReviewStoreImpl implements ChallengeReviewStore { + + private final ChallengeReviewRepository challengeReviewRepository; + + @Override + public ChallengeReview store(ChallengeReview challengeReview) { + return challengeReviewRepository.save(challengeReview); + } +} From fa6b6408925e8d82cffeb9d7f4fe2512eee1f94e Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:07:23 +0900 Subject: [PATCH 35/37] =?UTF-8?q?[Feat]:=20service=EC=97=90=EC=84=9C=20rev?= =?UTF-8?q?iew=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeService.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index 72a90fa..93da2eb 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -2,14 +2,21 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.haedal.zzansuni.controller.PagingRequest; +import org.haedal.zzansuni.controller.PagingResponse; import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.ReviewCreate; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReview; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReviewReader; +import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReviewStore; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationModel; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,6 +34,9 @@ public class ChallengeService { private final ChallengeVerificationStore challengeVerificationStore; private final ChallengeVerificationReader challengeVerificationReader; + private final ChallengeReviewStore challengeReviewStore; + private final ChallengeReviewReader challengeReviewReader; + /** * 챌린지 인증하기 1. ChallengeVerification 테이블에 데이터 추가 2. Challenge 엔티티에서 필요참여횟수 가져오기 3. UserChallenge * 엔티티에서 참여횟수 가져오기 4. 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 @@ -78,4 +88,25 @@ public ChallengeModel.ChallengeRecordDto getChallengeRecord(Long userId, Long ch public ChallengeVerificationModel getChallengeRecordDetail(Long recordId) { return ChallengeVerificationModel.from(challengeVerificationReader.getById(recordId)); } + + /** + * 챌린지 리뷰 작성하기 + */ + public Long reviewCreate(ReviewCreate command, Long challengeId, Long id) { + UserChallenge userChallenge = userChallengeReader.getByUserIdAndChallengeId(id, + challengeId); + ChallengeReview challengeReview = ChallengeReview.create(userChallenge, + command.getContent(), + command.getRating()); + /** + * 이미 리뷰를 작성했는지 확인 + */ + challengeReviewReader.findByUserChallengeId(challengeId) + .ifPresent(review -> { + throw new IllegalArgumentException("이미 리뷰를 작성했습니다."); + }); + + challengeReviewStore.store(challengeReview); + return challengeReview.getId(); + } } From 0e22b0a08171dd7b27ecb348778ba2afbe1325dd Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 03:07:49 +0900 Subject: [PATCH 36/37] =?UTF-8?q?[Feat]:=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=EC=97=90=EC=84=9C=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=ED=95=9C=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20val?= =?UTF-8?q?id=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../userchallenge/UserChallengeService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java index 2460af7..2e4fe22 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java @@ -25,6 +25,15 @@ public void participateChallenge(Long userId, UserChallengeCommand.Participate participateInfo) { User user = userReader.getById(userId); Challenge challenge = challengeReader.getById(participateInfo.getChallengeId()); + + /** + * 이미 참여한 챌린지인지 확인 + */ + userChallengeReader.findByUserIdAndChallengeId(userId, participateInfo.getChallengeId()) + .ifPresent(userChallenge -> { + throw new IllegalArgumentException("이미 참여한 챌린지입니다."); + }); + UserChallenge userChallenge = UserChallenge.from(challenge, user); userChallengeStore.store(userChallenge); From 64f077adefa06c2e83b3af65083ca0e3a2a762eb Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Sat, 1 Jun 2024 14:22:11 +0900 Subject: [PATCH 37/37] =?UTF-8?q?[Refact]:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=ED=95=98=EB=A9=B4=EC=84=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5 --- .../challenge/ChallengeController.java | 17 ++--- .../challenge/ChallengeReq.java | 8 +++ .../challenge/ChallengeRes.java | 3 +- .../challenge/ChallengeCurrentDto.java | 36 ++++++++++ .../challenge/ChallengeModel.java | 21 +++--- .../challenge/ChallengeService.java | 71 +++++-------------- .../challengereview/ChallengeReview.java | 9 +-- .../userchallenge/UserChallenge.java | 4 +- .../userchallenge/UserChallengeCommand.java | 23 ------ .../userchallenge/UserChallengeService.java | 50 +++++++++++-- .../challenge/ChallengeRepository.java | 26 +++++++ 11 files changed, 160 insertions(+), 108 deletions(-) create mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCurrentDto.java delete mode 100644 zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeCommand.java diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index 9683963..c8ad834 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -9,8 +9,8 @@ import org.haedal.zzansuni.controller.PagingResponse; import org.haedal.zzansuni.core.api.ApiResponse; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeService; -import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeCommand; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeService; import org.haedal.zzansuni.global.jwt.JwtUser; import org.springframework.http.HttpStatus; @@ -34,9 +34,7 @@ public ApiResponse challengeParticipation( @PathVariable Long challengeId, @AuthenticationPrincipal JwtUser jwtUser ) { - UserChallengeCommand.Participate command = new UserChallengeCommand.Participate(challengeId, - 1L); - userChallengeService.participateChallenge(jwtUser.getId(), command); + userChallengeService.participateChallenge(jwtUser.getId(), challengeId); return ApiResponse.success(null, "챌린지 참여에 성공하였습니다."); } @@ -48,11 +46,10 @@ public ApiResponse challengeVerifica @RequestPart("body") ChallengeReq.ChallengeVerificationRequest request, @RequestPart("image") MultipartFile image ) { - ChallengeCommand.Verificate command = new ChallengeCommand.Verificate( - request.content(), image); - ChallengeRes.ChallengeVerificationResponse response = ChallengeRes.ChallengeVerificationResponse.from( - challengeService.verification(userChallengeId, command) - ); + ChallengeCommand.Verificate command = request.toCommand(image); + ChallengeModel.ChallengeVerificationResult model = userChallengeService.verification( + userChallengeId, command); + var response = ChallengeRes.ChallengeVerificationResponse.from(model); return ApiResponse.success(response, "챌린지 인증에 성공하였습니다."); } @@ -64,7 +61,7 @@ public ApiResponse challengeReviewCreate( @AuthenticationPrincipal JwtUser jwtUser, @RequestBody ChallengeReq.ChallengeReviewCreateRequest request ) { - Long response = challengeService.reviewCreate(request.toCommand(), challengeId, + Long response = challengeService.createReview(request.toCommand(), challengeId, jwtUser.getId()); return ApiResponse.success(response, "챌린지 리뷰 작성에 성공하였습니다."); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java index 28447c7..d01f0f9 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeReq.java @@ -2,6 +2,7 @@ import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; +import org.springframework.web.multipart.MultipartFile; public class ChallengeReq { @@ -9,6 +10,13 @@ public record ChallengeVerificationRequest( String content ) { + public ChallengeCommand.Verificate toCommand(MultipartFile image) { + return ChallengeCommand.Verificate.builder() + .content(content) + .image(image) + .build(); + } + } public record ChallengeReviewCreateRequest( diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java index bc0929a..b86d099 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeRes.java @@ -7,6 +7,7 @@ import java.time.LocalDateTime; import java.util.List; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeRecord; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationModel; public class ChallengeRes { @@ -38,7 +39,7 @@ public record ChallengeRecordResponse( List recordIds ) { - public static ChallengeRecordResponse from(ChallengeModel.ChallengeRecordDto dto) { + public static ChallengeRecordResponse from(ChallengeRecord dto) { return ChallengeRecordResponse.builder() .title(dto.title()) .totalCount(dto.totalCount()) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCurrentDto.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCurrentDto.java new file mode 100644 index 0000000..80fff3a --- /dev/null +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeCurrentDto.java @@ -0,0 +1,36 @@ +package org.haedal.zzansuni.domain.challengegroup.challenge; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory; + +@Getter +public class ChallengeCurrentDto { + + private final Long challengeId; + private final String title; + private final Integer successCount; + private final Integer totalCount; + private final LocalDateTime participationDate; + private final LocalDate startDate; + private final LocalDate endDate; + private final ChallengeCategory category; + private final Boolean reviewWritten; + + // 생성자 추가 + public ChallengeCurrentDto(Long challengeId, String title, Integer successCount, + Integer totalCount, LocalDateTime participationDate, LocalDate startDate, LocalDate endDate, + ChallengeCategory category, Boolean reviewWritten) { + this.challengeId = challengeId; + this.title = title; + this.successCount = successCount; + this.totalCount = totalCount; + this.participationDate = participationDate; + this.startDate = startDate; + this.endDate = endDate; + this.category = category; + this.reviewWritten = reviewWritten; + } +} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java index 8a2c2a3..5411005 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeModel.java @@ -1,17 +1,13 @@ package org.haedal.zzansuni.domain.challengegroup.challenge; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory; import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; import org.haedal.zzansuni.domain.challengegroup.DayType; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; -import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; @Getter @Builder @@ -41,6 +37,15 @@ public static ChallengeModel from(Challenge challenge) { public record ChallengeVerificationResult(Integer totalCount, Integer successCount, Integer obtainExp) { + public static ChallengeVerificationResult of(Integer totalCount, Integer successCount, + Integer obtainExp) { + return ChallengeVerificationResult.builder() + .totalCount(totalCount) + .successCount(successCount) + .obtainExp(obtainExp) + .build(); + } + public static ChallengeVerificationResult from(Integer totalCount, Integer successCount, Integer obtainExp) { return ChallengeVerificationResult.builder() @@ -53,12 +58,12 @@ public static ChallengeVerificationResult from(Integer totalCount, Integer succe @Builder - public record ChallengeRecordDto(String title, Integer totalCount, Integer successCount, - LocalDate startDate, LocalDate endDate, List recordIds) { + public record ChallengeRecord(String title, Integer totalCount, Integer successCount, + LocalDate startDate, LocalDate endDate, List recordIds) { - public static ChallengeRecordDto from(Challenge challenge, ChallengeGroup challengeGroup, + public static ChallengeRecord from(Challenge challenge, ChallengeGroup challengeGroup, List challengeVerificationList) { - return ChallengeRecordDto.builder() + return ChallengeRecord.builder() .title(challengeGroup.getTitle()) .totalCount(challenge.getRequiredCount()) .successCount(challengeVerificationList.size()) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java index 93da2eb..bf7ab6e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.java @@ -1,111 +1,76 @@ package org.haedal.zzansuni.domain.challengegroup.challenge; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.haedal.zzansuni.controller.PagingRequest; -import org.haedal.zzansuni.controller.PagingResponse; import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; -import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.ReviewCreate; -import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeRecord; import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReview; import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReviewReader; import org.haedal.zzansuni.domain.challengegroup.challengereview.ChallengeReviewStore; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationModel; import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; -import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; -import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service @Slf4j -@Transactional public class ChallengeService { private final ChallengeReader challengeReader; - private final ChallengeStore challengeStore; private final UserChallengeReader userChallengeReader; - private final ChallengeVerificationStore challengeVerificationStore; private final ChallengeVerificationReader challengeVerificationReader; private final ChallengeReviewStore challengeReviewStore; private final ChallengeReviewReader challengeReviewReader; - /** - * 챌린지 인증하기 1. ChallengeVerification 테이블에 데이터 추가 2. Challenge 엔티티에서 필요참여횟수 가져오기 3. UserChallenge - * 엔티티에서 참여횟수 가져오기 4. 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 - */ - public ChallengeModel.ChallengeVerificationResult verification(Long userChallengeId, - Verificate verificate) { - UserChallenge userChallenge = userChallengeReader.getById(userChallengeId); - // TODO 이미지 업로드 로직 필요 - ChallengeVerification challengeVerification = ChallengeVerification.create(verificate, - userChallenge); - challengeVerificationStore.store(challengeVerification); - - /** - * 챌린지 RequiredCount 가져오기 위해 챌린지 정보 가져온다 - */ - Challenge challenge = userChallenge.getChallenge(); - - /** - * 사용자가 챌린지를 몇번 수행했는지 가져온다 - */ - Integer currentCount = challengeVerificationReader.countByUserChallengeId(userChallengeId); - log.info("currentCount: {}", currentCount); - /** - * 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 - */ - userChallenge.verification(currentCount, challenge.getRequiredCount()); - - return ChallengeModel.ChallengeVerificationResult - .from(challenge.getRequiredCount(), currentCount, challenge.getOnceExp()); - } /** * 챌린지 기록 가져오기 */ - public ChallengeModel.ChallengeRecordDto getChallengeRecord(Long userId, Long challengeId) { + + @Transactional(readOnly = true) + public ChallengeRecord getChallengeRecord(Long userId, Long challengeId) { Challenge challenge = challengeReader.getById(challengeId); ChallengeGroup challengeGroup = challenge.getChallengeGroup(); UserChallenge userChallenge = userChallengeReader.getByUserIdAndChallengeId(userId, challengeId); - return ChallengeModel.ChallengeRecordDto - .from(challenge, challengeGroup, - challengeVerificationReader.findByUserChallengeId(userChallenge.getId())); + List challengeVerifications = challengeVerificationReader.findByUserChallengeId( + userChallenge.getId()); + return ChallengeRecord.from(challenge, challengeGroup, challengeVerifications); } /** * 챌린지 기록 상세 가져오기 */ + + @Transactional(readOnly = true) public ChallengeVerificationModel getChallengeRecordDetail(Long recordId) { - return ChallengeVerificationModel.from(challengeVerificationReader.getById(recordId)); + ChallengeVerification challengeVerification = challengeVerificationReader.getById(recordId); + return ChallengeVerificationModel.from(challengeVerification); } /** * 챌린지 리뷰 작성하기 */ - public Long reviewCreate(ReviewCreate command, Long challengeId, Long id) { - UserChallenge userChallenge = userChallengeReader.getByUserIdAndChallengeId(id, + @Transactional + public Long createReview(ChallengeCommand.ReviewCreate command, Long challengeId, Long userId) { + UserChallenge userChallenge = userChallengeReader.getByUserIdAndChallengeId(userId, challengeId); - ChallengeReview challengeReview = ChallengeReview.create(userChallenge, - command.getContent(), - command.getRating()); - /** - * 이미 리뷰를 작성했는지 확인 - */ + + //이미 리뷰를 작성했는지 확인 challengeReviewReader.findByUserChallengeId(challengeId) .ifPresent(review -> { throw new IllegalArgumentException("이미 리뷰를 작성했습니다."); }); - + ChallengeReview challengeReview = ChallengeReview.create(userChallenge, command); challengeReviewStore.store(challengeReview); return challengeReview.getId(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java index 0330e75..e072244 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challengereview/ChallengeReview.java @@ -13,6 +13,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.haedal.zzansuni.domain.BaseTimeEntity; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand; import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; @Entity @@ -34,12 +35,12 @@ public class ChallengeReview extends BaseTimeEntity { private Integer rating; - public static ChallengeReview create(UserChallenge userChallenge, String content, - Integer rating) { + public static ChallengeReview create(UserChallenge userChallenge, + ChallengeCommand.ReviewCreate command) { return ChallengeReview.builder() .userChallenge(userChallenge) - .content(content) - .rating(rating) + .content(command.getContent()) + .rating(command.getRating()) .build(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java index e5d5f35..8e953e8 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallenge.java @@ -41,7 +41,7 @@ public class UserChallenge extends BaseTimeEntity { @Enumerated(EnumType.STRING) private ChallengeStatus status; - public static UserChallenge from(Challenge challenge, User user) { + public static UserChallenge create(Challenge challenge, User user) { return UserChallenge.builder() .challenge(challenge) .user(user) @@ -56,7 +56,7 @@ private void complete() { /** * 챌린지 인증 참여횟수와 필요참여획수가 같으면 챌린지 완료로 변경 */ - public void verification(Integer currentCount, Integer requiredCount) { + public void tryComplete(Integer currentCount, Integer requiredCount) { if (currentCount.equals(requiredCount)) { complete(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeCommand.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeCommand.java deleted file mode 100644 index 678d3f5..0000000 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.haedal.zzansuni.domain.challengegroup.userchallenge; - -import lombok.Builder; -import lombok.Getter; -import org.haedal.zzansuni.core.utils.SelfValidating; - -public class UserChallengeCommand { - - @Getter - @Builder - public static class Participate extends SelfValidating { - - private Long challengeId; - private Long userId; - - public Participate(Long challengeId, Long userId) { - this.challengeId = challengeId; - this.userId = userId; - this.validateSelf(); - } - } - -} diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java index 2e4fe22..e0ed08e 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java @@ -1,16 +1,22 @@ package org.haedal.zzansuni.domain.challengegroup.userchallenge; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand.Verificate; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeReader; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerification; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationReader; +import org.haedal.zzansuni.domain.challengegroup.challengeverification.ChallengeVerificationStore; import org.haedal.zzansuni.domain.user.User; import org.haedal.zzansuni.domain.user.UserReader; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +@Slf4j @Service @RequiredArgsConstructor -@Transactional public class UserChallengeService { private final UserChallengeStore userChallengeStore; @@ -18,26 +24,56 @@ public class UserChallengeService { private final UserReader userReader; private final ChallengeReader challengeReader; + private final ChallengeVerificationStore challengeVerificationStore; + private final ChallengeVerificationReader challengeVerificationReader; + /** * 챌린지 참여하기 1. 유저와 챌린지 정보를 받아서 UserChallenge 테이블에 데이터 추가 */ - public void participateChallenge(Long userId, - UserChallengeCommand.Participate participateInfo) { + @Transactional + public void participateChallenge(Long userId, Long challengeId) { User user = userReader.getById(userId); - Challenge challenge = challengeReader.getById(participateInfo.getChallengeId()); + Challenge challenge = challengeReader.getById(challengeId); /** * 이미 참여한 챌린지인지 확인 */ - userChallengeReader.findByUserIdAndChallengeId(userId, participateInfo.getChallengeId()) + userChallengeReader.findByUserIdAndChallengeId(userId, challengeId) .ifPresent(userChallenge -> { throw new IllegalArgumentException("이미 참여한 챌린지입니다."); }); - - UserChallenge userChallenge = UserChallenge.from(challenge, user); + + UserChallenge userChallenge = UserChallenge.create(challenge, user); userChallengeStore.store(userChallenge); // TODO: 챌린지 그룹 누적 참여자수 증가 로직 추가 } + /** + * 챌린지 인증하기

1. ChallengeVerification 테이블에 데이터 추가
2. Challenge 엔티티에서 필요참여횟수 가져오기
3. + * UserChallenge 엔티티에서 참여횟수 가져오기
4. 참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 + */ + @Transactional + public ChallengeModel.ChallengeVerificationResult verification(Long userChallengeId, + Verificate verificate) { + UserChallenge userChallenge = userChallengeReader.getById(userChallengeId); + // TODO 이미지 업로드 로직 필요 + ChallengeVerification challengeVerification = ChallengeVerification.create(verificate, + userChallenge); + challengeVerificationStore.store(challengeVerification); + + // 챌린지 RequiredCount 가져오기 위해 챌린지 정보 가져온다 + + Challenge challenge = userChallenge.getChallenge(); + + //사용자가 챌린지를 몇번 수행했는지 가져온다 + Integer currentCount = challengeVerificationReader.countByUserChallengeId(userChallengeId); + log.info("currentCount: {}", currentCount); + + //참여횟수와 필요참여횟수가 같으면 챌린지 완료로 변경 + userChallenge.tryComplete(currentCount, challenge.getRequiredCount()); + + return ChallengeModel.ChallengeVerificationResult + .of(challenge.getRequiredCount(), currentCount, challenge.getOnceExp()); + } } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeRepository.java index 3569933..f42df5c 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeRepository.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeRepository.java @@ -1,8 +1,34 @@ package org.haedal.zzansuni.infrastructure.challengegroup.challenge; +import org.haedal.zzansuni.controller.challengegroup.challenge.ChallengeRes.ChallengeCurrentResponse; import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; +import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCurrentDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface ChallengeRepository extends JpaRepository { + @Query( + "SELECT new org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCurrentDto(" + + + "c.id, cg.title, " + + "(SELECT COUNT(cv) FROM ChallengeVerification cv WHERE cv.userChallenge.challenge.id = c.id AND cv.userChallenge.user.id = :userId), " + + + "c.requiredCount, " + + "uc.createdAt, c.startDate, c.endDate, " + + "cg.category, " + + "(SELECT COUNT(cr) > 0 FROM ChallengeReview cr WHERE cr.userChallenge.challenge.id = c.id AND cr.userChallenge.user.id = :userId)" + + + ") " + + "FROM Challenge c " + + "JOIN c.challengeGroup cg " + + "JOIN UserChallenge uc ON uc.challenge.id = c.id " + + "WHERE uc.user.id = :userId " + + "AND uc.status = org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeStatus.PROCEEDING ") + Page findAllCurrentChallenges(@Param("userId") Long userId, + Pageable pageable); } +