From b66c89dce9461fd860a963dd835b57ab69790cfd Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Jul 2024 23:04:15 +0900 Subject: [PATCH 01/19] =?UTF-8?q?refactor=20-=20#174=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20JsonProperty=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/dto/request/SocialSignUpRequest.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java b/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java index dc399a22..12d4aacb 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java +++ b/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java @@ -1,6 +1,5 @@ package sopt.org.hmh.domain.auth.dto.request; -import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; @@ -14,26 +13,24 @@ public record SocialSignUpRequest( @NotNull(message = "소셜 플랫폼은 null일 수 없습니다.") SocialPlatform socialPlatform, String name, - @JsonProperty(value = "onboarding") - OnboardingRequest onboardingRequest, + OnboardingRequest onboarding, @Valid - @JsonProperty(value = "challenge") - ChallengeSignUpRequest challengeSignUpRequest + ChallengeSignUpRequest challenge ) { public ChallengeRequest toChallengeRequest() { - return new ChallengeRequest(challengeSignUpRequest.period(), challengeSignUpRequest.goalTime()); + return new ChallengeRequest(challenge.period(), challenge.goalTime()); } public OnboardingInfo toOnboardingInfo(Long userId) { return OnboardingInfo.builder() - .averageUseTime(onboardingRequest.averageUseTime()) + .averageUseTime(onboarding.averageUseTime()) .userId(userId) .build(); } public List toProblemList(Long onboardingInfoId) { - return onboardingRequest.problemList().stream() + return onboarding.problemList().stream() .map(problem -> OnboardingProblem.builder() .onboardingInfoId(onboardingInfoId) .problem(problem) From 08989a62d1024a0d285ff435471232100a727bfa Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Jul 2024 23:13:19 +0900 Subject: [PATCH 02/19] =?UTF-8?q?refactor=20-=20#174=20user=20validate?= =?UTF-8?q?=EB=A5=BC=20addUser=20=EB=A9=94=EC=84=9C=EB=93=9C=EA=B0=80=20?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/domain/user/service/UserService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java index 397c5252..34c1f3d0 100644 --- a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java +++ b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java @@ -54,6 +54,8 @@ public void validateDuplicateUser(String socialId, SocialPlatform socialPlatform } public User addUser(SocialPlatform socialPlatform, String socialId, String name) { + this.validateDuplicateUser(socialId, socialPlatform); + return userRepository.save( User.builder() .socialPlatform(socialPlatform) From fe333c818c9acffc09af67ff89eee5decf77b736 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Jul 2024 23:36:51 +0900 Subject: [PATCH 03/19] =?UTF-8?q?refactor=20-=20#174=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=20=EC=83=9D=EC=84=B1=EA=B3=BC=20User=EC=97=90=20curre?= =?UTF-8?q?ntChallengeId=EB=A5=BC=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=EC=9D=B4=20=EA=B0=99?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=91=EB=8F=99=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/challenge/service/ChallengeService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeService.java b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeService.java index ccf0cf02..2576fea1 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeService.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeService.java @@ -8,6 +8,7 @@ import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; import sopt.org.hmh.domain.challenge.repository.ChallengeRepository; +import sopt.org.hmh.domain.user.domain.User; @Service @RequiredArgsConstructor @@ -32,8 +33,10 @@ public List getCurrentChallengeAppByChallengeId(Long challengeId) return this.findByIdOrElseThrow(challengeId).getApps(); } - public Challenge save(Challenge challenge) { - return challengeRepository.save(challenge); + public Challenge addChallengeAndUpdateUserCurrentChallenge(Challenge challenge, User user) { + Challenge newChallenge = challengeRepository.save(challenge); + user.changeCurrentChallengeId(newChallenge.getId()); + return newChallenge; } public Integer getChallengePeriod(Long challengeId) { From ef34a850dab6b26a1e0acc71a6f56dd3f5703090 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Jul 2024 23:37:23 +0900 Subject: [PATCH 04/19] =?UTF-8?q?refactor=20-=20#174=20addChallenge?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D?= =?UTF-8?q?=EC=9D=84=20=ED=95=98=EB=8A=94=20=EC=9D=BC=EA=B3=BC=20=EC=A0=81?= =?UTF-8?q?=ED=95=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/challenge/controller/ChallengeController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java index 3c503397..5ce0b501 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java @@ -29,7 +29,7 @@ public ResponseEntity> orderAddChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeRequest request) { - challengeFacade.addChallenge(userId, request, os); + challengeFacade.addChallengeAndDailyChallengeByPreviousChallenge(userId, request, os); return ResponseEntity .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) From 45774198114d1e54487b2c0c88cf0ba22d71a0a0 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Jul 2024 23:38:00 +0900 Subject: [PATCH 05/19] =?UTF-8?q?refactor=20-=20#174=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/challenge/domain/exception/ChallengeError.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/exception/ChallengeError.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/exception/ChallengeError.java index 96aa7f16..8c8a84df 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/exception/ChallengeError.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/exception/ChallengeError.java @@ -7,7 +7,7 @@ @AllArgsConstructor public enum ChallengeError implements ErrorBase { - CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "챌린지를 찾을 수 없습니다."), + CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "챌린지가 존재하지 않습니다."), INVALID_PERIOD_NUMERIC(HttpStatus.BAD_REQUEST, "유효한 챌린지 기간이 아닙니다."), INVALID_GOAL_TIME(HttpStatus.BAD_REQUEST, "챌린지 목표 시간이 유효하지 않습니다."), ; From 57d37bf1e6530c933ed6dffb2fc6867b63bf9b57 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 00:00:43 +0900 Subject: [PATCH 06/19] =?UTF-8?q?refactor=20-=20#174=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=20=EA=B0=9C=EC=84=A0=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthController.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java b/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java index 29eacd95..e965fc0b 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java +++ b/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java @@ -32,7 +32,10 @@ public ResponseEntity> orderLogin( ) { return ResponseEntity .status(AuthSuccess.LOGIN_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.LOGIN_SUCCESS, authFacade.login(socialAccessToken, request))); + .body(BaseResponse.success( + AuthSuccess.LOGIN_SUCCESS, + authFacade.login(socialAccessToken, request.socialPlatform()) + )); } @PostMapping("/signup") @@ -44,7 +47,10 @@ public ResponseEntity> orderSignup( ) { return ResponseEntity .status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.SIGNUP_SUCCESS, authFacade.signup(socialAccessToken, request, os))); + .body(BaseResponse.success( + AuthSuccess.SIGNUP_SUCCESS, + authFacade.signup(socialAccessToken, request, os) + )); } @PostMapping("/reissue") @@ -54,7 +60,10 @@ public ResponseEntity> orderReissue( ) { return ResponseEntity .status(AuthSuccess.REISSUE_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.REISSUE_SUCCESS, authFacade.reissueToken(refreshToken))); + .body(BaseResponse.success( + AuthSuccess.REISSUE_SUCCESS, + authFacade.reissueToken(refreshToken) + )); } @GetMapping("/social/token/kakao") @@ -63,6 +72,9 @@ public ResponseEntity> orderGetKakaoAcce ) { return ResponseEntity .status(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS, authFacade.getSocialAccessTokenByAuthorizationCode(code))); + .body(BaseResponse.success( + AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS, + authFacade.getSocialAccessTokenByAuthorizationCode(code) + )); } } \ No newline at end of file From 02f72d9e36c45d2c50a169b80462e4cc90d608d8 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 00:01:18 +0900 Subject: [PATCH 07/19] =?UTF-8?q?modify=20-=20#174=20=EC=9D=B4=EC=A0=84=20?= =?UTF-8?q?=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=95=B1=EC=9D=84=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EB=8B=A8?= =?UTF-8?q?=EC=88=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/app/repository/ChallengeAppRepository.java | 3 +++ .../org/hmh/domain/app/service/ChallengeAppService.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java b/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java index 3663e832..4a37f46d 100644 --- a/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java +++ b/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.app.repository; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.app.domain.exception.AppError; @@ -17,4 +18,6 @@ default ChallengeApp findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(Long chall } boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); + + List findAllByChallengeId(Long previousChallengeId); } diff --git a/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java index 366272f4..4d504adb 100644 --- a/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java +++ b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java @@ -31,6 +31,15 @@ public void addApps(Challenge challenge, List requests, Str }).toList()); } + public void addAppsByPreviousChallengeApp(String os, Long previousChallengeId, Challenge challenge) { + List previousChallengeAppRequests = + challengeAppRepository.findAllByChallengeId(previousChallengeId).stream() + .map(previousApp -> new ChallengeAppRequest(previousApp.getAppCode(), previousApp.getGoalTime())) + .toList(); + + this.addApps(challenge, previousChallengeAppRequests, os); + } + private void validateAppExist(Long challengeId, String appCode, String os) { if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)) { throw new AppException(AppError.APP_EXIST_ALREADY); From fee93d87585d05051ddf59bc34df977f4316c76e Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 00:02:24 +0900 Subject: [PATCH 08/19] =?UTF-8?q?modify=20-=20#174=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=B2=98=EC=9D=8C=20=EC=8B=9C=EC=9E=91?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=99=80=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84=20=EC=B1=8C=EB=A6=B0=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=9C=BC=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChallengeController.java | 2 +- .../challenge/service/ChallengeFacade.java | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java index 5ce0b501..5c44f385 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java @@ -29,7 +29,7 @@ public ResponseEntity> orderAddChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeRequest request) { - challengeFacade.addChallengeAndDailyChallengeByPreviousChallenge(userId, request, os); + challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os); return ResponseEntity .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java index a8e984e6..2f516b59 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java @@ -1,6 +1,5 @@ package sopt.org.hmh.domain.challenge.service; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,31 +30,34 @@ public class ChallengeFacade { private final ChallengeAppService challengeAppService; @Transactional - public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { + public Challenge startNewChallengeByPreviousChallenge(Long userId, ChallengeRequest challengeRequest, + String os) { User user = userService.findByIdOrThrowException(userId); + Long previousChallengeId = userService.getCurrentChallengeIdByUser(user); - Optional previousChallengeId = Optional.ofNullable(user.getCurrentChallengeId()); + Challenge newChallenge = + challengeService.addChallengeAndUpdateUserCurrentChallenge(challengeRequest.toEntity(userId), user); - Challenge challenge = challengeService.save(challengeRequest.toEntity(userId)); - user.changeCurrentChallengeId(challenge.getId()); + LocalDate startDate = newChallenge.getCreatedAt().toLocalDate(); // TODO: startDate CreatedAt에서 가져오지 않고 새로 만들기 + dailyChallengeService.addDailyChallenge(userId, startDate, newChallenge); + + challengeAppService.addAppsByPreviousChallengeApp(os, previousChallengeId, newChallenge); + + return newChallenge; + } + + @Transactional + public Challenge startFirstChallenge(User user, ChallengeRequest challengeRequest, String os) { + Long userId = user.getId(); + + Challenge challenge = challengeService.addChallengeAndUpdateUserCurrentChallenge(challengeRequest.toEntity(userId), user); LocalDate startDate = challenge.getCreatedAt().toLocalDate(); dailyChallengeService.addDailyChallenge(userId, startDate, challenge); - this.addAppsIfPreviousChallengeExist(os, previousChallengeId, challenge); return challenge; } - private void addAppsIfPreviousChallengeExist(String os, Optional previousChallengeId, Challenge challenge) { - if (previousChallengeId.isPresent()) { - Challenge previousChallenge = challengeService.findByIdOrElseThrow(previousChallengeId.get()); - List previousApps = previousChallenge.getApps().stream() - .map(app -> new ChallengeAppRequest(app.getAppCode(), app.getGoalTime())) - .toList(); - challengeAppService.addApps(challenge, previousApps, os); - } - } - @Transactional(readOnly = true) public ChallengeResponse getCurrentChallengeInfo(Long userId) { Challenge challenge = this.findCurrentChallengeByUserId(userId); From 31c0fc6070d9e3865c47b50c36c54ccbff6c9172 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 00:05:15 +0900 Subject: [PATCH 09/19] =?UTF-8?q?refactor=20-=20#174=20challenge=EC=97=90?= =?UTF-8?q?=EC=84=9C=20startDate=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20dailyChallengeService=EB=A1=9C?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/challenge/service/ChallengeFacade.java | 10 ++++------ .../dailychallenge/service/DailyChallengeService.java | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java index 2f516b59..2d4b77e9 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java @@ -35,11 +35,10 @@ public Challenge startNewChallengeByPreviousChallenge(Long userId, ChallengeRequ User user = userService.findByIdOrThrowException(userId); Long previousChallengeId = userService.getCurrentChallengeIdByUser(user); - Challenge newChallenge = - challengeService.addChallengeAndUpdateUserCurrentChallenge(challengeRequest.toEntity(userId), user); + Challenge newChallenge = challengeService.addChallengeAndUpdateUserCurrentChallenge( + challengeRequest.toEntity(userId), user); - LocalDate startDate = newChallenge.getCreatedAt().toLocalDate(); // TODO: startDate CreatedAt에서 가져오지 않고 새로 만들기 - dailyChallengeService.addDailyChallenge(userId, startDate, newChallenge); + dailyChallengeService.addDailyChallenge(userId, newChallenge); challengeAppService.addAppsByPreviousChallengeApp(os, previousChallengeId, newChallenge); @@ -52,8 +51,7 @@ public Challenge startFirstChallenge(User user, ChallengeRequest challengeReques Challenge challenge = challengeService.addChallengeAndUpdateUserCurrentChallenge(challengeRequest.toEntity(userId), user); - LocalDate startDate = challenge.getCreatedAt().toLocalDate(); - dailyChallengeService.addDailyChallenge(userId, startDate, challenge); + dailyChallengeService.addDailyChallenge(userId, challenge); return challenge; } diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java index c5ee346e..1932deeb 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java @@ -44,7 +44,8 @@ private void handleAlreadyProcessedDailyChallenge(DailyChallenge dailyChallenge) throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED); } - public void addDailyChallenge(Long userId, LocalDate startDate, Challenge challenge) { + public void addDailyChallenge(Long userId, Challenge challenge) { + LocalDate startDate = challenge.getCreatedAt().toLocalDate(); // TODO: startDate CreatedAt에서 가져오지 않고 새로 만들기 dailyChallengeRepository.saveAll(IntStream.range(0, challenge.getPeriod()) .mapToObj(i -> DailyChallenge.builder() .challengeDate(startDate.plusDays(i)) From 0d24b30b051de196a3c49ac0aa36ab217b39840b Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 13:45:39 +0900 Subject: [PATCH 10/19] =?UTF-8?q?feat=20-=20#174=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=B4=20currentChallengeId?= =?UTF-8?q?=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/user/service/UserService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java index 34c1f3d0..6217cc0b 100644 --- a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java +++ b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java @@ -12,6 +12,8 @@ import sopt.org.hmh.domain.auth.exception.AuthException; import sopt.org.hmh.domain.auth.repository.OnboardingInfoRepository; import sopt.org.hmh.domain.auth.repository.ProblemRepository; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.domain.user.domain.UserConstants; import sopt.org.hmh.domain.user.domain.exception.UserError; @@ -102,6 +104,11 @@ public Long getCurrentChallengeIdByUserId(Long userId) { .orElseThrow(() -> new UserException(UserError.NOT_FOUND_CURRENT_CHALLENGE_ID)); } + public Long getCurrentChallengeIdByUser(User user) { + return Optional.ofNullable(user.getCurrentChallengeId()) + .orElseThrow(() -> new ChallengeException(ChallengeError.CHALLENGE_NOT_FOUND)); + } + @Transactional public void changeRecentLockDate(Long userId, LocalDate lockDate) { this.findByIdOrThrowException(userId).changeRecentLockDate(lockDate); From 972a7629218e4d1b4a91da603ee886fb4a286afa Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 13:46:02 +0900 Subject: [PATCH 11/19] =?UTF-8?q?feat=20-=20#174=20ChallengeRequest?= =?UTF-8?q?=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/auth/dto/request/SocialSignUpRequest.java | 4 ---- .../domain/challenge/dto/request/ChallengeSignUpRequest.java | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java b/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java index 12d4aacb..ef3d4511 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java +++ b/src/main/java/sopt/org/hmh/domain/auth/dto/request/SocialSignUpRequest.java @@ -18,10 +18,6 @@ public record SocialSignUpRequest( ChallengeSignUpRequest challenge ) { - public ChallengeRequest toChallengeRequest() { - return new ChallengeRequest(challenge.period(), challenge.goalTime()); - } - public OnboardingInfo toOnboardingInfo(Long userId) { return OnboardingInfo.builder() .averageUseTime(onboarding.averageUseTime()) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeSignUpRequest.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeSignUpRequest.java index 527ca5d3..27f7d474 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeSignUpRequest.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeSignUpRequest.java @@ -21,4 +21,8 @@ public record ChallengeSignUpRequest( throw new ChallengeException(ChallengeError.INVALID_GOAL_TIME); } } + + public ChallengeRequest toChallengeRequest() { + return new ChallengeRequest(this.period, this.goalTime); + } } \ No newline at end of file From 7b6ecc906ed31a3ee2d51528d01f254e523068ca Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 13:58:45 +0900 Subject: [PATCH 12/19] =?UTF-8?q?feat=20-=20#174=20=EC=95=B1=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/ChallengeAppService.java | 32 +++++++++---------- .../challenge/service/ChallengeFacade.java | 26 +++++++++------ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java index 4d504adb..7217cc9a 100644 --- a/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java +++ b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java @@ -22,28 +22,28 @@ public void removeApp(Challenge challenge, String appcode, String os) { challengeAppRepository.delete(appToRemove); } - public void addApps(Challenge challenge, List requests, String os) { - challengeAppRepository.saveAll( - requests.stream().map( - request -> { - validateAppExist(challenge.getId(), request.appCode(), os); - return request.toEntity(challenge, os); - }).toList()); + public void addAppsByPreviousChallengeApp(String os, Long previousChallengeId, Challenge challenge) { + this.addApps(challengeAppRepository.findAllByChallengeId(previousChallengeId) + .stream().map(previousApp -> + new ChallengeAppRequest(previousApp.getAppCode(), previousApp.getGoalTime()) + .toEntity(challenge, os)) + .toList() + ); } - public void addAppsByPreviousChallengeApp(String os, Long previousChallengeId, Challenge challenge) { - List previousChallengeAppRequests = - challengeAppRepository.findAllByChallengeId(previousChallengeId).stream() - .map(previousApp -> new ChallengeAppRequest(previousApp.getAppCode(), previousApp.getGoalTime())) - .toList(); + public void addApps(List challengeApps) { + this.validateAppsExist(challengeApps); + challengeAppRepository.saveAll(challengeApps); + } - this.addApps(challenge, previousChallengeAppRequests, os); + private void validateAppsExist(List challengeApps) { + challengeApps.forEach(this::validateAppExist); } - private void validateAppExist(Long challengeId, String appCode, String os) { - if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)) { + private void validateAppExist(ChallengeApp challengeApp) { + if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs( + challengeApp.getChallenge().getId(), challengeApp.getAppCode(), challengeApp.getOs())) { throw new AppException(AppError.APP_EXIST_ALREADY); } } - } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java index 2d4b77e9..64fd461a 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java @@ -8,6 +8,7 @@ import sopt.org.hmh.domain.app.service.ChallengeAppService; import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; +import sopt.org.hmh.domain.challenge.dto.request.ChallengeSignUpRequest; import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; @@ -30,8 +31,7 @@ public class ChallengeFacade { private final ChallengeAppService challengeAppService; @Transactional - public Challenge startNewChallengeByPreviousChallenge(Long userId, ChallengeRequest challengeRequest, - String os) { + public void startNewChallengeByPreviousChallenge(Long userId, ChallengeRequest challengeRequest, String os) { User user = userService.findByIdOrThrowException(userId); Long previousChallengeId = userService.getCurrentChallengeIdByUser(user); @@ -41,19 +41,23 @@ public Challenge startNewChallengeByPreviousChallenge(Long userId, ChallengeRequ dailyChallengeService.addDailyChallenge(userId, newChallenge); challengeAppService.addAppsByPreviousChallengeApp(os, previousChallengeId, newChallenge); - - return newChallenge; } @Transactional - public Challenge startFirstChallenge(User user, ChallengeRequest challengeRequest, String os) { + public void startFirstChallengeWithChallengeSignUpRequest( + ChallengeSignUpRequest challengeSignUpRequest, User user, String os) { Long userId = user.getId(); - Challenge challenge = challengeService.addChallengeAndUpdateUserCurrentChallenge(challengeRequest.toEntity(userId), user); + Challenge newChallenge = challengeService.addChallengeAndUpdateUserCurrentChallenge( + challengeSignUpRequest.toChallengeRequest().toEntity(userId), user); - dailyChallengeService.addDailyChallenge(userId, challenge); + dailyChallengeService.addDailyChallenge(userId, newChallenge); - return challenge; + challengeAppService.addApps( + challengeSignUpRequest.apps().stream() + .map(challengeAppRequest -> challengeAppRequest.toEntity(newChallenge, os)) + .toList() + ); } @Transactional(readOnly = true) @@ -98,7 +102,11 @@ private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) @Transactional public void addAppsToCurrentChallenge(Long userId, List requests, String os) { Challenge challenge = this.findCurrentChallengeByUserId(userId); - challengeAppService.addApps(challenge, requests, os); + challengeAppService.addApps( + requests.stream() + .map(request -> request.toEntity(challenge, os)) + .toList() + ); } @Transactional From ee7d5de19aef857908801862109bd7537e6720f2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 14:10:32 +0900 Subject: [PATCH 13/19] =?UTF-8?q?modify=20-=20#174=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=98=88=EC=A0=95=20=EC=9C=A0=EC=A0=80=20recover=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=8B=A4=EB=A5=B8=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=B1=85=EC=9E=84=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/user/service/UserService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java index 6217cc0b..3c9bf910 100644 --- a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java +++ b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java @@ -42,11 +42,13 @@ public UserInfoResponse getUserInfo(Long userId) { } public User getUserBySocialPlatformAndSocialId(SocialPlatform socialPlatform, String socialId) { - User user = this.findBySocialPlatformAndSocialIdOrThrowException(socialPlatform, socialId); + return this.findBySocialPlatformAndSocialIdOrThrowException(socialPlatform, socialId); + } + + public void recoverIfIsDeletedUser(User user) { if (user.isDeleted()) { user.recover(); } - return user; } public void validateDuplicateUser(String socialId, SocialPlatform socialPlatform) { From a12962f40743d875cd7f126adfa9438dc1ebd55d Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 14:11:32 +0900 Subject: [PATCH 14/19] =?UTF-8?q?refactor=20-=20#174=20AuthFacade=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthController.java | 2 +- .../hmh/domain/auth/service/AuthFacade.java | 54 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java b/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java index e965fc0b..39a86dcd 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java +++ b/src/main/java/sopt/org/hmh/domain/auth/controller/AuthController.java @@ -49,7 +49,7 @@ public ResponseEntity> orderSignup( .status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus()) .body(BaseResponse.success( AuthSuccess.SIGNUP_SUCCESS, - authFacade.signup(socialAccessToken, request, os) + authFacade.signup(request, socialAccessToken, os) )); } diff --git a/src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java b/src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java index 5e314308..d52f691d 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java +++ b/src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java @@ -3,12 +3,9 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sopt.org.hmh.domain.app.service.ChallengeAppService; import sopt.org.hmh.domain.auth.dto.response.ReissueResponse; -import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.domain.user.domain.User; -import sopt.org.hmh.domain.auth.dto.request.SocialPlatformRequest; import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest; import sopt.org.hmh.domain.auth.dto.response.LoginResponse; import sopt.org.hmh.domain.user.service.UserService; @@ -27,53 +24,60 @@ public class AuthFacade { private final KakaoLoginService kakaoLoginService; private final AppleOAuthProvider appleOAuthProvider; private final ChallengeFacade challengeFacade; - private final ChallengeAppService challengeAppService; private final TokenService tokenService; private final UserService userService; @Transactional(readOnly = true) - public LoginResponse login(String socialAccessToken, SocialPlatformRequest request) { - SocialPlatform socialPlatform = request.socialPlatform(); + public LoginResponse login(String socialAccessToken, SocialPlatform socialPlatform) { String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken); User loginUser = userService.getUserBySocialPlatformAndSocialId(socialPlatform, socialId); - return performLogin(socialAccessToken, socialPlatform, loginUser); + return performLogin(loginUser, socialAccessToken, socialPlatform); } @Transactional - public LoginResponse signup(String socialAccessToken, SocialSignUpRequest request, String os) { + public LoginResponse signup(SocialSignUpRequest request, String socialAccessToken, String os) { SocialPlatform socialPlatform = request.socialPlatform(); String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken); - userService.validateDuplicateUser(socialId, socialPlatform); - User user = userService.addUser(socialPlatform, socialId, request.name()); - Long userId = user.getId(); - userService.registerOnboardingInfo(request, userId); + User newUser = userService.addUser(socialPlatform, socialId, request.name()); + Long newUserId = newUser.getId(); + + userService.registerOnboardingInfo(request, newUserId); - Challenge challenge = challengeFacade.addChallenge(userId, request.toChallengeRequest() , os); - challengeAppService.addApps(challenge, request.challengeSignUpRequest().apps(), os); + challengeFacade.startFirstChallengeWithChallengeSignUpRequest(request.challenge(), newUser , os); - return performLogin(socialAccessToken, socialPlatform, user); + return performLogin(newUser, socialAccessToken, socialPlatform); } private String getSocialIdBySocialAccessToken(SocialPlatform socialPlatform, String socialAccessToken) { - return switch (socialPlatform.toString()) { - case "KAKAO" -> kakaoLoginService.getSocialIdByKakao(socialAccessToken); - case "APPLE" -> appleOAuthProvider.getApplePlatformId(socialAccessToken); - default -> throw new JwtException(JwtError.INVALID_SOCIAL_ACCESS_TOKEN); - }; + if (socialPlatform == SocialPlatform.APPLE) { + return appleOAuthProvider.getApplePlatformId(socialAccessToken); + } + if (socialPlatform == SocialPlatform.KAKAO) { + return kakaoLoginService.getSocialIdByKakao(socialAccessToken); + } + throw new JwtException(JwtError.INVALID_SOCIAL_ACCESS_TOKEN); } - public ReissueResponse reissueToken(String refreshToken) { - return tokenService.reissueToken(refreshToken); + private LoginResponse performLogin(User loginUser, String socialAccessToken, SocialPlatform socialPlatform) { + this.updateAdditionalUserLoginInfo(loginUser, socialAccessToken, socialPlatform); + + Long userId = loginUser.getId(); + return new LoginResponse(userId, tokenService.issueToken(userId.toString())); } - private LoginResponse performLogin(String socialAccessToken, SocialPlatform socialPlatform, User loginUser) { + private void updateAdditionalUserLoginInfo(User loginUser, String socialAccessToken, SocialPlatform socialPlatform) { + userService.recoverIfIsDeletedUser(loginUser); + if (socialPlatform == SocialPlatform.KAKAO) { kakaoLoginService.updateUserInfoByKakao(loginUser, socialAccessToken); } - Long userId = loginUser.getId(); - return new LoginResponse(userId, tokenService.issueToken(userId.toString())); + } + + + public ReissueResponse reissueToken(String refreshToken) { + return tokenService.reissueToken(refreshToken); } public SocialAccessTokenResponse getSocialAccessTokenByAuthorizationCode(String code) { From 6513a46968a9e45bcbf298e9be74a3e1b80d137f Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 14:29:19 +0900 Subject: [PATCH 15/19] =?UTF-8?q?refactor=20-=20#174=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/app/repository/HistoryAppRepository.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/repository/HistoryAppRepository.java b/src/main/java/sopt/org/hmh/domain/app/repository/HistoryAppRepository.java index e650e923..97d496e7 100644 --- a/src/main/java/sopt/org/hmh/domain/app/repository/HistoryAppRepository.java +++ b/src/main/java/sopt/org/hmh/domain/app/repository/HistoryAppRepository.java @@ -2,17 +2,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import sopt.org.hmh.domain.app.domain.HistoryApp; -import sopt.org.hmh.domain.app.domain.exception.AppError; -import sopt.org.hmh.domain.app.domain.exception.AppException; - -import java.util.Optional; public interface HistoryAppRepository extends JpaRepository { - Optional findFirstByDailyChallengeIdAndAppCodeAndOs(Long dailyChallengeId, String appCode, String os); - - default HistoryApp findFirstByDailyChallengeIdAndAppCodeAndOsOrElseThrow(Long dailyChallengeId, String appCode, String os) { - return findFirstByDailyChallengeIdAndAppCodeAndOs(dailyChallengeId, appCode, os).orElseThrow(() -> new AppException( - AppError.APP_NOT_FOUND)); - } } From 761e34ba1399207a386305fcc94434d4f09b77ca Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 14:59:21 +0900 Subject: [PATCH 16/19] =?UTF-8?q?refactor=20-=20#174=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20implementation=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 041e3297..2752a7dc 100644 --- a/build.gradle +++ b/build.gradle @@ -41,9 +41,6 @@ dependencies { runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' - // Redis - implementation 'org.springframework.boot:spring-boot-starter-data-redis' - // Open Feign implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0' @@ -59,4 +56,8 @@ tasks.named('test') { useJUnitPlatform() } +clean { + delete file('src/main/generated') +} + jar.enabled = false \ No newline at end of file From f62efcb96920e013a7656714a1797386ee91bfc8 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 15:00:12 +0900 Subject: [PATCH 17/19] =?UTF-8?q?refactor=20-=20#174=20challengeAppReposit?= =?UTF-8?q?ory=20=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ChallengeAppRepository.java | 23 ----------- .../ChallengeAppJpaRepository.java | 15 +++++++ .../challenge_app/ChallengeAppRepository.java | 18 +++++++++ .../ChallengeAppRepositoryImpl.java | 39 +++++++++++++++++++ 4 files changed, 72 insertions(+), 23 deletions(-) delete mode 100644 src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppJpaRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepositoryImpl.java diff --git a/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java b/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java deleted file mode 100644 index 4a37f46d..00000000 --- a/src/main/java/sopt/org/hmh/domain/app/repository/ChallengeAppRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -package sopt.org.hmh.domain.app.repository; - -import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; -import sopt.org.hmh.domain.app.domain.ChallengeApp; -import sopt.org.hmh.domain.app.domain.exception.AppError; -import sopt.org.hmh.domain.app.domain.exception.AppException; - -import java.util.Optional; - -public interface ChallengeAppRepository extends JpaRepository { - - Optional findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); - - default ChallengeApp findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(Long challengeId, String appCode, String os) { - return findFirstByChallengeIdAndAppCodeAndOs(challengeId, appCode, os).orElseThrow(() -> new AppException( - AppError.APP_NOT_FOUND)); - } - - boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); - - List findAllByChallengeId(Long previousChallengeId); -} diff --git a/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppJpaRepository.java b/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppJpaRepository.java new file mode 100644 index 00000000..bad15c17 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppJpaRepository.java @@ -0,0 +1,15 @@ +package sopt.org.hmh.domain.app.repository.challenge_app; + +import java.util.List; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import sopt.org.hmh.domain.app.domain.ChallengeApp; + +public interface ChallengeAppJpaRepository extends JpaRepository { + + Optional findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); + + boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); + + List findAllByChallengeId(Long previousChallengeId); +} diff --git a/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepository.java b/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepository.java new file mode 100644 index 00000000..131fe47e --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepository.java @@ -0,0 +1,18 @@ +package sopt.org.hmh.domain.app.repository.challenge_app; + +import java.util.List; +import sopt.org.hmh.domain.app.domain.ChallengeApp; +import java.util.Optional; + +public interface ChallengeAppRepository { + + void saveAll(List challengeApps); + + void delete(ChallengeApp appToRemove); + + Optional findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); + + boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os); + + List findAllByChallengeId(Long previousChallengeId); +} diff --git a/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepositoryImpl.java new file mode 100644 index 00000000..bdc1fe7e --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/app/repository/challenge_app/ChallengeAppRepositoryImpl.java @@ -0,0 +1,39 @@ +package sopt.org.hmh.domain.app.repository.challenge_app; + +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import sopt.org.hmh.domain.app.domain.ChallengeApp; + +@Repository +@RequiredArgsConstructor +public class ChallengeAppRepositoryImpl implements ChallengeAppRepository{ + + private final ChallengeAppJpaRepository challengeAppJpaRepository; + + @Override + public void saveAll(List challengeApps) { + challengeAppJpaRepository.saveAll(challengeApps); + } + + @Override + public void delete(ChallengeApp appToRemove) { + challengeAppJpaRepository.delete(appToRemove); + } + + @Override + public Optional findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os) { + return challengeAppJpaRepository.findFirstByChallengeIdAndAppCodeAndOs(challengeId, appCode, os); + } + + @Override + public boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os) { + return challengeAppJpaRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os); + } + + @Override + public List findAllByChallengeId(Long previousChallengeId) { + return challengeAppJpaRepository.findAllByChallengeId(previousChallengeId); + } +} From 3251a18d8984f93666723cbdd868259b9e16dd5e Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 15:00:35 +0900 Subject: [PATCH 18/19] =?UTF-8?q?refactor=20-=20#174=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=EC=9D=B8=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC=EB=A5=BC=20service=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B1=85=EC=9E=84=EC=9D=84=20=EA=B0=96=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/app/service/ChallengeAppService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java index 7217cc9a..3a4be1ff 100644 --- a/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java +++ b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java @@ -7,7 +7,7 @@ import sopt.org.hmh.domain.app.domain.exception.AppError; import sopt.org.hmh.domain.app.domain.exception.AppException; import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; -import sopt.org.hmh.domain.app.repository.ChallengeAppRepository; +import sopt.org.hmh.domain.app.repository.challenge_app.ChallengeAppRepository; import sopt.org.hmh.domain.challenge.domain.Challenge; @Service @@ -18,7 +18,7 @@ public class ChallengeAppService { public void removeApp(Challenge challenge, String appcode, String os) { ChallengeApp appToRemove = - challengeAppRepository.findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), appcode, os); + this.findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), appcode, os); challengeAppRepository.delete(appToRemove); } @@ -46,4 +46,9 @@ private void validateAppExist(ChallengeApp challengeApp) { throw new AppException(AppError.APP_EXIST_ALREADY); } } + + private ChallengeApp findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(Long challengeId, String appCode, String os) { + return challengeAppRepository.findFirstByChallengeIdAndAppCodeAndOs(challengeId, appCode, os) + .orElseThrow(() -> new AppException(AppError.APP_NOT_FOUND)); + } } From cbbffcbcab14f54bd7a86162ff8942f18c00d51a Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Jul 2024 15:06:32 +0900 Subject: [PATCH 19/19] =?UTF-8?q?feat=20-=20#174=20Querydsl=EC=97=90=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20build.gradle=20=EC=84=A4=EC=A0=95?= =?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 --- .gitignore | 3 +++ build.gradle | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 894ecfdb..024e067d 100644 --- a/.gitignore +++ b/.gitignore @@ -173,4 +173,7 @@ application-prod.yml ### Test ### data.sql +### Querydsl ### +**/generated/ + # End of https://www.gitignore.io/api/java,macos,gradle,intellij diff --git a/build.gradle b/build.gradle index 2752a7dc..e50a71d7 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,12 @@ dependencies { runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' + // Querydsl + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + // Open Feign implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0'