From 6fcdd2152ee93eee14def2603308680fc74c4de5 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 11 Jun 2024 23:47:36 +0900 Subject: [PATCH 001/100] =?UTF-8?q?fix=20-=20#155=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=20=EC=B5=9C=EC=86=8C=20=EC=8B=9C=EA=B0=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/challenge/domain/ChallengeConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java index 3696732d..2858b263 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java @@ -5,7 +5,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public abstract class ChallengeConstants { - public static final Long MINIMUM_GOAL_TIME = 0L; + public static final Long MINIMUM_GOAL_TIME = 3_600_000L; public static final Long MAXIMUM_GOAL_TIME = 21_600_000L; public static final Integer USAGE_POINT = 100; public static final Integer EARNED_POINT = 20; From 94d9c4d710b2dc63cdd2fc5e15e47fc9b827a46b Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:01:35 +0900 Subject: [PATCH 002/100] =?UTF-8?q?refactor=20-=20#164=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EA=B8=B0=EA=B0=84=20=EB=B0=8F=20=EB=AA=A9?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=EA=B0=84=20validate=20request=20dto=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A7=84=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../domain/exception/ChallengeError.java | 7 ++--- .../dto/request/ChallengeRequest.java | 19 ++++++++++++- .../challenge/service/ChallengeService.java | 27 +++---------------- 3 files changed, 24 insertions(+), 29 deletions(-) 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 b3e2563c..31554c75 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 @@ -8,11 +8,8 @@ public enum ChallengeError implements ErrorBase { CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "챌린지를 찾을 수 없습니다."), - INVALID_PERIOD_NULL(HttpStatus.BAD_REQUEST, "챌린지 기간은 null일 수 없습니다."), - INVALID_PERIOD_NUMERIC(HttpStatus.BAD_REQUEST, "유효한 숫자의 챌린지 기간을 입력해주세요."), - INVALID_GOAL_TIME_NULL(HttpStatus.BAD_REQUEST, "목표시간은 null일 수 없습니다."), - INVALID_GOAL_TIME_NUMERIC(HttpStatus.BAD_REQUEST, "유효한 숫자의 목표 시간을 입력해주세요."), - CHALLENGE_ALREADY_FAILED_TODAY(HttpStatus.BAD_REQUEST, "이미 실패 처리 된 챌린지입니다."), + INVALID_PERIOD_NUMERIC(HttpStatus.BAD_REQUEST, "유효한 챌린지 기간이 아닙니다."), + ; private final HttpStatus status; diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java index 33ff3ba3..741fe174 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java @@ -1,7 +1,24 @@ package sopt.org.hmh.domain.challenge.dto.request; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; + public record ChallengeRequest( + @NotNull(message = "챌린지 기간은 null일 수 없습니다.") Integer period, + @Max(value = ChallengeConstants.MAXIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최대 목표 시간 이상으로 설정할 수 없습니다.") + @Min(value = ChallengeConstants.MINIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최소 목표 시간 이하로 설정할 수 없습니다.") + @NotNull(message = "챌린지 목표시간은 null일 수 없습니다.") Long goalTime ) { -} \ No newline at end of file + + public ChallengeRequest { + if (!ChallengeConstants.AVAILABLE_CHALLENGE_PERIODS.contains(period)) { + throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC); + } + } +} 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 5e08363f..079a2107 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 @@ -12,10 +12,9 @@ import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; import sopt.org.hmh.domain.app.repository.ChallengeAppRepository; import sopt.org.hmh.domain.challenge.domain.Challenge; -import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; -import sopt.org.hmh.domain.challenge.domain.ChallengeDay; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; +import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; import sopt.org.hmh.domain.challenge.repository.ChallengeRepository; @@ -41,9 +40,9 @@ public class ChallengeService { private final UserService userService; @Transactional - public Challenge addChallenge(Long userId, Integer period, Long goalTime, String os) { - validateChallengePeriod(period); - validateChallengeGoalTime(goalTime); + public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { + Integer period = challengeRequest.period(); + Long goalTime = challengeRequest.goalTime(); Challenge challenge = challengeRepository.save(Challenge.builder() .userId(userId) @@ -144,24 +143,6 @@ private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) return (daysBetween >= period) ? -1 : daysBetween; } - private void validateChallengePeriod(Integer period) { - if (period == null) { - throw new ChallengeException(ChallengeError.INVALID_PERIOD_NULL); - } - if (period != ChallengeDay.DAYS7.getValue() && period != ChallengeDay.DAYS14.getValue() && period != ChallengeDay.DAYS20.getValue() && period != ChallengeDay.DAYS30.getValue()) { - throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC); - } - } - - private void validateChallengeGoalTime(Long goalTime) { - if (goalTime == null) { - throw new ChallengeException(ChallengeError.INVALID_GOAL_TIME_NULL); - } - if (goalTime < ChallengeConstants.MINIMUM_GOAL_TIME || goalTime > ChallengeConstants.MAXIMUM_GOAL_TIME) { - throw new ChallengeException(ChallengeError.INVALID_GOAL_TIME_NUMERIC); - } - } - private void validateAppExist(Long challengeId, String appCode, String os) { if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)) { throw new AppException(AppError.APP_EXIST_ALREADY); From fbe6f92c7cf3d4a35815d53d7b74f098a054af63 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:02:13 +0900 Subject: [PATCH 003/100] =?UTF-8?q?refactor=20-=20#164=20challenge=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=EC=9D=84=20List=EB=A1=9C=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EC=97=AC=20contain=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=ED=86=B5=ED=95=B4=20validation=EC=9D=84?= =?UTF-8?q?=20=EC=A7=84=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/domain/ChallengeConstants.java | 3 ++- .../domain/challenge/domain/ChallengeDay.java | 18 ------------------ 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeDay.java diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java index 2858b263..dc472b63 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.challenge.domain; +import java.util.List; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -9,5 +10,5 @@ public abstract class ChallengeConstants { public static final Long MAXIMUM_GOAL_TIME = 21_600_000L; public static final Integer USAGE_POINT = 100; public static final Integer EARNED_POINT = 20; - + public static final List AVAILABLE_CHALLENGE_PERIODS = List.of(7, 14, 20, 30); } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeDay.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeDay.java deleted file mode 100644 index 0416b163..00000000 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeDay.java +++ /dev/null @@ -1,18 +0,0 @@ -package sopt.org.hmh.domain.challenge.domain; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public enum ChallengeDay { - - DAYS7(7), - DAYS14(14), - DAYS20(20), - DAYS30(30), - ; - - private final int value; -} From ee2e7f79556948b7ae91928ccca97d0d8509a6f9 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:04:29 +0900 Subject: [PATCH 004/100] =?UTF-8?q?refactor=20-=20#164=20appcode=20validat?= =?UTF-8?q?ion=EC=9D=84=20DTO=EC=83=9D=EC=84=B1=EC=8B=9C=EC=97=90=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/app/dto/request/AppRemoveRequest.java | 3 +++ .../hmh/domain/app/dto/request/ChallengeAppRequest.java | 3 +++ .../hmh/domain/challenge/service/ChallengeService.java | 8 -------- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/AppRemoveRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/AppRemoveRequest.java index f837fdf3..9167615d 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/AppRemoveRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/AppRemoveRequest.java @@ -1,6 +1,9 @@ package sopt.org.hmh.domain.app.dto.request; +import jakarta.validation.constraints.NotNull; + public record AppRemoveRequest( + @NotNull(message = "앱 코드는 null일 수 없습니다.") String appCode ) { } diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java index f366e34f..4722d1d9 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java @@ -1,6 +1,9 @@ package sopt.org.hmh.domain.app.dto.request; +import jakarta.validation.constraints.NotNull; + public record ChallengeAppRequest( + @NotNull(message = "앱 코드는 null일 수 없습니다.") String appCode, Long goalTime ) { 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 079a2107..e182d85e 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 @@ -110,7 +110,6 @@ public DailyChallengeResponse getDailyChallenge(Long userId) { @Transactional public void removeApp(Challenge challenge, AppRemoveRequest request, String os) { - validateAppCode(request.appCode()); ChallengeApp appToRemove = challengeAppRepository .findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), request.appCode(), os); challengeAppRepository.delete(appToRemove); @@ -121,7 +120,6 @@ public void addApps(Challenge challenge, List requests, Str List appsToUpdate = requests.stream() .map(request -> { validateAppExist(challenge.getId(), request.appCode(), os); - validateAppCode(request.appCode()); validateAppTime(request.goalTime()); return ChallengeApp.builder() .challenge(challenge) @@ -149,12 +147,6 @@ private void validateAppExist(Long challengeId, String appCode, String os) { } } - private void validateAppCode(String appCode) { - if (appCode.isEmpty()) { - throw new AppException(AppError.INVALID_APP_CODE_NULL); - } - } - private void validateAppTime(Long appTime) { if (appTime == null) { throw new AppException(AppError.INVALID_TIME_NULL); From fa5529d4a3d50b65ae2309ff83ec72514d7551ec Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:07:07 +0900 Subject: [PATCH 005/100] =?UTF-8?q?refactor=20-=20#164=20app=20=EB=AA=A9?= =?UTF-8?q?=ED=91=9C=20=EC=8B=9C=EA=B0=84=20validation=EC=9D=84=20DTO=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/app/dto/request/ChallengeAppRequest.java | 7 +++++++ .../hmh/domain/challenge/service/ChallengeService.java | 9 --------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java index 4722d1d9..3fe849f7 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java @@ -1,10 +1,17 @@ package sopt.org.hmh.domain.app.dto.request; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; +import sopt.org.hmh.domain.app.domain.AppConstants; public record ChallengeAppRequest( @NotNull(message = "앱 코드는 null일 수 없습니다.") String appCode, + @NotNull(message = "앱 시간은 null일 수 없습니다.") + @Max(value = AppConstants.MAXIMUM_APP_TIME, message = "앱 시간은 최대 앱 시간 이상으로 설정할 수 없습니다.") + @Min(value = AppConstants.MINIMUM_APP_TIME, message = "앱 시간은 최소 앱 시간 이하로 설정할 수 없습니다.") Long goalTime ) { + } 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 e182d85e..2f23f3cb 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 @@ -120,7 +120,6 @@ public void addApps(Challenge challenge, List requests, Str List appsToUpdate = requests.stream() .map(request -> { validateAppExist(challenge.getId(), request.appCode(), os); - validateAppTime(request.goalTime()); return ChallengeApp.builder() .challenge(challenge) .appCode(request.appCode()) @@ -147,14 +146,6 @@ private void validateAppExist(Long challengeId, String appCode, String os) { } } - private void validateAppTime(Long appTime) { - if (appTime == null) { - throw new AppException(AppError.INVALID_TIME_NULL); - } - if (appTime > AppConstants.MAXIMUM_APP_TIME || appTime < AppConstants.MINIMUM_APP_TIME) - throw new AppException(AppError.INVALID_TIME_RANGE); - } - public Challenge findByIdOrElseThrow(Long challengeId) { return challengeRepository.findById(challengeId).orElseThrow( () -> new ChallengeException(ChallengeError.CHALLENGE_NOT_FOUND)); From 4110639de22b67185d62b91e74d52a5b4878b135 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:17:13 +0900 Subject: [PATCH 006/100] =?UTF-8?q?refactor=20-=20#164=20request=20dto=20?= =?UTF-8?q?=EC=A0=9C=EC=95=BD=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/app/dto/request/HistoryAppRequest.java | 4 ++++ .../hmh/domain/auth/dto/request/SocialSignUpRequest.java | 2 ++ .../challenge/dto/request/ChallengeSignUpRequest.java | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/HistoryAppRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/HistoryAppRequest.java index 4dde2153..524e154f 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/HistoryAppRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/HistoryAppRequest.java @@ -1,7 +1,11 @@ package sopt.org.hmh.domain.app.dto.request; +import jakarta.validation.constraints.NotNull; + public record HistoryAppRequest( + @NotNull(message = "앱 코드는 null일 수 없습니다.") String appCode, + @NotNull(message = "앱 사용시간은 null일 수 없습니다.") Long usageTime ) { } \ No newline at end of file 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 9861dc6f..5acf5d8b 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,10 +1,12 @@ package sopt.org.hmh.domain.auth.dto.request; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; import sopt.org.hmh.domain.challenge.dto.request.ChallengeSignUpRequest; import sopt.org.hmh.global.auth.social.SocialPlatform; public record SocialSignUpRequest( + @NotNull(message = "소셜 플랫폼은 null일 수 없습니다.") SocialPlatform socialPlatform, String name, @JsonProperty(value = "onboarding") 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 8491d7f5..9ffbfdcb 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 @@ -1,11 +1,19 @@ package sopt.org.hmh.domain.challenge.dto.request; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; import java.util.List; +import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; public record ChallengeSignUpRequest( + @NotNull(message = "챌린지 기간은 null일 수 없습니다.") Integer period, + @Max(value = ChallengeConstants.MAXIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최대 목표 시간 이상으로 설정할 수 없습니다.") + @Min(value = ChallengeConstants.MINIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최소 목표 시간 이하로 설정할 수 없습니다.") + @NotNull(message = "챌린지 목표시간은 null일 수 없습니다.") Long goalTime, List apps ) { From 2602926ecfa38464b5828639536a866ead6a49dc Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:22:05 +0900 Subject: [PATCH 007/100] =?UTF-8?q?refactor=20-=20#164=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20Error=20cons?= =?UTF-8?q?tants=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/hmh/domain/app/domain/exception/AppError.java | 3 --- .../java/sopt/org/hmh/domain/auth/exception/AuthError.java | 1 - .../dailychallenge/domain/exception/DailyChallengeError.java | 1 - 3 files changed, 5 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java b/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java index 5f417124..58e8b940 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java @@ -9,9 +9,6 @@ public enum AppError implements ErrorBase { APP_NOT_FOUND(HttpStatus.NOT_FOUND, "앱을 찾을 수 없습니다."), APP_EXIST_ALREADY(HttpStatus.CONFLICT, "이미 추가된 앱입니다."), - INVALID_APP_CODE_NULL(HttpStatus.BAD_REQUEST, "앱 코드 값이 비어있습니다"), - INVALID_TIME_RANGE(HttpStatus.BAD_REQUEST, "앱 시간의 범위가 유효한지 확인해주세요"), - INVALID_TIME_NULL(HttpStatus.BAD_REQUEST, "앱 시간을 입력해주세요"), ; private final HttpStatus status; diff --git a/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java b/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java index 2b80ff6b..4fe210e5 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java +++ b/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java @@ -8,7 +8,6 @@ public enum AuthError implements ErrorBase { // 400 BAD REQUEST - INVALID_USER(HttpStatus.BAD_REQUEST, "Principle 객체가 없습니다."), DUPLICATE_USER(HttpStatus.BAD_REQUEST, "이미 회원가입된 유저입니다."), // 403 FORBIDDEN diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java index e4bea843..60c5b7aa 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java @@ -8,7 +8,6 @@ public enum DailyChallengeError implements ErrorBase { DAILY_CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "일별 챌린지를 찾을 수 없습니다."), - DAILY_CHALLENGE_YESTERDAY_NOT_FOUND(HttpStatus.NOT_FOUND, "어제의 일별 챌린지를 찾을 수 없습니다."), DAILY_CHALLENGE_ALREADY_PROCESSED(HttpStatus.BAD_REQUEST, "이미 처리된 일별 챌린지입니다.") ; From 017e953b00792e184027265e6e5b5ce12ce5859e Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:32:47 +0900 Subject: [PATCH 008/100] =?UTF-8?q?refactor=20-=20#164=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20Error=20cons?= =?UTF-8?q?tants=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java | 1 - .../dailychallenge/domain/exception/DailyChallengeError.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java b/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java index 2b80ff6b..4fe210e5 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java +++ b/src/main/java/sopt/org/hmh/domain/auth/exception/AuthError.java @@ -8,7 +8,6 @@ public enum AuthError implements ErrorBase { // 400 BAD REQUEST - INVALID_USER(HttpStatus.BAD_REQUEST, "Principle 객체가 없습니다."), DUPLICATE_USER(HttpStatus.BAD_REQUEST, "이미 회원가입된 유저입니다."), // 403 FORBIDDEN diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java index e4bea843..60c5b7aa 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/exception/DailyChallengeError.java @@ -8,7 +8,6 @@ public enum DailyChallengeError implements ErrorBase { DAILY_CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "일별 챌린지를 찾을 수 없습니다."), - DAILY_CHALLENGE_YESTERDAY_NOT_FOUND(HttpStatus.NOT_FOUND, "어제의 일별 챌린지를 찾을 수 없습니다."), DAILY_CHALLENGE_ALREADY_PROCESSED(HttpStatus.BAD_REQUEST, "이미 처리된 일별 챌린지입니다.") ; From 3f6659671e65d21a13c4bc911f809d2aaa80be6f Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:33:51 +0900 Subject: [PATCH 009/100] =?UTF-8?q?refactor=20-=20#164=20app=20time=20vali?= =?UTF-8?q?dation=EC=97=90=EC=84=9C=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=EC=97=90=EC=84=9C=20=EC=83=81=EC=88=98=EB=A7=8C?= =?UTF-8?q?=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=B4=EC=95=BC=ED=95=98?= =?UTF-8?q?=EC=97=AC=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90=EC=84=9C=20val?= =?UTF-8?q?idation=EC=9D=84=20=EC=A7=84=ED=96=89=ED=95=98=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 --- .../domain/app/dto/request/ChallengeAppRequest.java | 12 +++++++----- .../challenge/dto/request/ChallengeRequest.java | 10 ++++++---- .../dto/request/ChallengeSignUpRequest.java | 13 ++++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java index 3fe849f7..4d925ca4 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java @@ -1,17 +1,19 @@ package sopt.org.hmh.domain.app.dto.request; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import sopt.org.hmh.domain.app.domain.AppConstants; +import sopt.org.hmh.domain.app.domain.exception.AppError; +import sopt.org.hmh.domain.app.domain.exception.AppException; public record ChallengeAppRequest( @NotNull(message = "앱 코드는 null일 수 없습니다.") String appCode, @NotNull(message = "앱 시간은 null일 수 없습니다.") - @Max(value = AppConstants.MAXIMUM_APP_TIME, message = "앱 시간은 최대 앱 시간 이상으로 설정할 수 없습니다.") - @Min(value = AppConstants.MINIMUM_APP_TIME, message = "앱 시간은 최소 앱 시간 이하로 설정할 수 없습니다.") Long goalTime ) { - + public ChallengeAppRequest { + if (goalTime > AppConstants.MAXIMUM_APP_TIME || goalTime < AppConstants.MINIMUM_APP_TIME) { + throw new AppException(AppError.INVALID_TIME_RANGE); + } + } } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java index 741fe174..0cb0d3ee 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java @@ -1,8 +1,9 @@ package sopt.org.hmh.domain.challenge.dto.request; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; +import sopt.org.hmh.domain.app.domain.AppConstants; +import sopt.org.hmh.domain.app.domain.exception.AppError; +import sopt.org.hmh.domain.app.domain.exception.AppException; import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; @@ -10,8 +11,6 @@ public record ChallengeRequest( @NotNull(message = "챌린지 기간은 null일 수 없습니다.") Integer period, - @Max(value = ChallengeConstants.MAXIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최대 목표 시간 이상으로 설정할 수 없습니다.") - @Min(value = ChallengeConstants.MINIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최소 목표 시간 이하로 설정할 수 없습니다.") @NotNull(message = "챌린지 목표시간은 null일 수 없습니다.") Long goalTime ) { @@ -20,5 +19,8 @@ public record ChallengeRequest( if (!ChallengeConstants.AVAILABLE_CHALLENGE_PERIODS.contains(period)) { throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC); } + if (goalTime > AppConstants.MAXIMUM_APP_TIME || goalTime < AppConstants.MINIMUM_APP_TIME) { + throw new AppException(AppError.INVALID_TIME_RANGE); + } } } 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 9ffbfdcb..e7915521 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 @@ -1,20 +1,23 @@ package sopt.org.hmh.domain.challenge.dto.request; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; +import sopt.org.hmh.domain.app.domain.AppConstants; +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 java.util.List; -import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; public record ChallengeSignUpRequest( @NotNull(message = "챌린지 기간은 null일 수 없습니다.") Integer period, - @Max(value = ChallengeConstants.MAXIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최대 목표 시간 이상으로 설정할 수 없습니다.") - @Min(value = ChallengeConstants.MINIMUM_GOAL_TIME, message = "챌린지 목표 시간은 최소 목표 시간 이하로 설정할 수 없습니다.") @NotNull(message = "챌린지 목표시간은 null일 수 없습니다.") Long goalTime, List apps ) { + public ChallengeSignUpRequest { + if (goalTime > AppConstants.MAXIMUM_APP_TIME || goalTime < AppConstants.MINIMUM_APP_TIME) { + throw new AppException(AppError.INVALID_TIME_RANGE); + } + } } \ No newline at end of file From 35d0fda19aae2340e927bc2e815f0a7644044b3e Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:34:21 +0900 Subject: [PATCH 010/100] =?UTF-8?q?refactor=20-=20#164=20addChallenge?= =?UTF-8?q?=EC=9D=98=20=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/auth/dto/request/SocialSignUpRequest.java | 4 ++++ .../java/sopt/org/hmh/domain/auth/service/AuthService.java | 3 +-- .../hmh/domain/challenge/controller/ChallengeController.java | 2 +- 3 files changed, 6 insertions(+), 3 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 5acf5d8b..a2e41616 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 @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.constraints.NotNull; +import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.request.ChallengeSignUpRequest; import sopt.org.hmh.global.auth.social.SocialPlatform; @@ -14,4 +15,7 @@ public record SocialSignUpRequest( @JsonProperty(value = "challenge") ChallengeSignUpRequest challengeSignUpRequest ) { + public ChallengeRequest toChallengeRequest() { + return new ChallengeRequest(challengeSignUpRequest.period(), challengeSignUpRequest.goalTime()); + } } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java b/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java index e1d0e9a3..a1bc731f 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java +++ b/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java @@ -52,8 +52,7 @@ public LoginResponse signup(String socialAccessToken, SocialSignUpRequest reques User user = userService.addUser(socialPlatform, socialId, request.name()); - Challenge challenge = challengeService.addChallenge(user.getId(), request.challengeSignUpRequest().period(), - request.challengeSignUpRequest().goalTime(), os); + Challenge challenge = challengeService.addChallenge(user.getId(), request.toChallengeRequest() , os); challengeService.addApps(challenge, request.challengeSignUpRequest().apps(), os); userService.registerOnboardingInfo(request); 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 70be065e..1737df88 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 @@ -28,7 +28,7 @@ public class ChallengeController implements ChallengeApi { public ResponseEntity> orderAddChallenge(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody final ChallengeRequest request) { - challengeService.addChallenge(userId, request.period(), request.goalTime(), os); + challengeService.addChallenge(userId, request, os); return ResponseEntity .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) From d1c60946ba1d50dbb181c806070a91ba0006dec7 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 12 Jun 2024 17:36:36 +0900 Subject: [PATCH 011/100] =?UTF-8?q?merge=20-=20#164=20=EA=B9=83=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=BC=AC=EC=9D=B8=20AppError=20=EB=8B=A4=EC=8B=9C?= =?UTF-8?q?=20=EB=B3=B5=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/app/domain/exception/AppError.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java b/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java index 58e8b940..84e7fe05 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java @@ -9,6 +9,7 @@ public enum AppError implements ErrorBase { APP_NOT_FOUND(HttpStatus.NOT_FOUND, "앱을 찾을 수 없습니다."), APP_EXIST_ALREADY(HttpStatus.CONFLICT, "이미 추가된 앱입니다."), + INVALID_TIME_RANGE(HttpStatus.BAD_REQUEST, "앱 시간의 범위가 유효한지 확인해주세요"), ; private final HttpStatus status; From bfc6325fea34a6ee4a5692014200f536b090879d Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 15:41:39 +0900 Subject: [PATCH 012/100] =?UTF-8?q?refactor=20-=20#166=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=EA=B0=92=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/challenge/domain/ChallengeConstants.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java index dc472b63..117439b0 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java @@ -6,8 +6,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public abstract class ChallengeConstants { - public static final Long MINIMUM_GOAL_TIME = 3_600_000L; - public static final Long MAXIMUM_GOAL_TIME = 21_600_000L; public static final Integer USAGE_POINT = 100; public static final Integer EARNED_POINT = 20; public static final List AVAILABLE_CHALLENGE_PERIODS = List.of(7, 14, 20, 30); From 9742bda80109fe0329a07740e08ba7ece1c53e88 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 15:58:13 +0900 Subject: [PATCH 013/100] =?UTF-8?q?refactor=20-=20#166=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=EC=97=90=20=EB=A7=9E=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20App=20=EC=B5=9C=EB=8C=80=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=9D=84=202=EC=8B=9C=EA=B0=84=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=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/app/domain/AppConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/AppConstants.java b/src/main/java/sopt/org/hmh/domain/app/domain/AppConstants.java index 744ee28d..367d9328 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/AppConstants.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/AppConstants.java @@ -6,5 +6,5 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public abstract class AppConstants { public static final Long MINIMUM_APP_TIME = 0L; - public static final Long MAXIMUM_APP_TIME = 21_600_000L; // 6시간 + public static final Long MAXIMUM_APP_TIME = 7_200_000L; // 2시간 } \ No newline at end of file From 113f53c9ff33e05471758d00926253f33d62ddf6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 16:04:47 +0900 Subject: [PATCH 014/100] =?UTF-8?q?refactor=20-=20#166=20GOAL=20TIME=20ERR?= =?UTF-8?q?OR=20=EB=AC=B8=EA=B5=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/app/domain/exception/AppError.java | 2 +- .../org/hmh/domain/app/dto/request/ChallengeAppRequest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java b/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java index 84e7fe05..e422cb6e 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/exception/AppError.java @@ -9,7 +9,7 @@ public enum AppError implements ErrorBase { APP_NOT_FOUND(HttpStatus.NOT_FOUND, "앱을 찾을 수 없습니다."), APP_EXIST_ALREADY(HttpStatus.CONFLICT, "이미 추가된 앱입니다."), - INVALID_TIME_RANGE(HttpStatus.BAD_REQUEST, "앱 시간의 범위가 유효한지 확인해주세요"), + INVALID_GOAL_TIME(HttpStatus.BAD_REQUEST, "앱 목표 시간이 유효하지 않습니다."), ; private final HttpStatus status; diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java index 4d925ca4..3d8d5f3f 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java @@ -13,7 +13,7 @@ public record ChallengeAppRequest( ) { public ChallengeAppRequest { if (goalTime > AppConstants.MAXIMUM_APP_TIME || goalTime < AppConstants.MINIMUM_APP_TIME) { - throw new AppException(AppError.INVALID_TIME_RANGE); + throw new AppException(AppError.INVALID_GOAL_TIME); } } } From 1a4a98de896db7b27ee9f122680f9b82ac4f95d5 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 16:06:33 +0900 Subject: [PATCH 015/100] =?UTF-8?q?refactor=20-=20#166=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=20=EC=A0=95=EC=9D=98=EB=90=9C=20challenge=20constants?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/challenge/domain/ChallengeConstants.java | 2 ++ .../challenge/domain/exception/ChallengeError.java | 2 +- .../challenge/dto/request/ChallengeRequest.java | 4 ++-- .../dto/request/ChallengeSignUpRequest.java | 13 +++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java index 117439b0..b9e3c9fe 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/ChallengeConstants.java @@ -6,6 +6,8 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public abstract class ChallengeConstants { + public static final Long MINIMUM_GOAL_TIME = 3_600_000L; // 1시간 + public static final Long MAXIMUM_GOAL_TIME = 21_600_000L; // 6시간 public static final Integer USAGE_POINT = 100; public static final Integer EARNED_POINT = 20; public static final List AVAILABLE_CHALLENGE_PERIODS = List.of(7, 14, 20, 30); 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 31554c75..96aa7f16 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 @@ -9,7 +9,7 @@ public enum ChallengeError implements ErrorBase { CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "챌린지를 찾을 수 없습니다."), INVALID_PERIOD_NUMERIC(HttpStatus.BAD_REQUEST, "유효한 챌린지 기간이 아닙니다."), - + INVALID_GOAL_TIME(HttpStatus.BAD_REQUEST, "챌린지 목표 시간이 유효하지 않습니다."), ; private final HttpStatus status; diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java index 0cb0d3ee..7f32031f 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java @@ -19,8 +19,8 @@ public record ChallengeRequest( if (!ChallengeConstants.AVAILABLE_CHALLENGE_PERIODS.contains(period)) { throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC); } - if (goalTime > AppConstants.MAXIMUM_APP_TIME || goalTime < AppConstants.MINIMUM_APP_TIME) { - throw new AppException(AppError.INVALID_TIME_RANGE); + if (goalTime > ChallengeConstants.MAXIMUM_GOAL_TIME || goalTime < ChallengeConstants.MINIMUM_GOAL_TIME) { + throw new ChallengeException(ChallengeError.INVALID_GOAL_TIME); } } } 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 e7915521..527ca5d3 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 @@ -1,23 +1,24 @@ package sopt.org.hmh.domain.challenge.dto.request; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; -import sopt.org.hmh.domain.app.domain.AppConstants; -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 java.util.List; +import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; public record ChallengeSignUpRequest( @NotNull(message = "챌린지 기간은 null일 수 없습니다.") Integer period, @NotNull(message = "챌린지 목표시간은 null일 수 없습니다.") Long goalTime, - List apps + List<@Valid ChallengeAppRequest> apps ) { public ChallengeSignUpRequest { - if (goalTime > AppConstants.MAXIMUM_APP_TIME || goalTime < AppConstants.MINIMUM_APP_TIME) { - throw new AppException(AppError.INVALID_TIME_RANGE); + if (goalTime > ChallengeConstants.MAXIMUM_GOAL_TIME || goalTime < ChallengeConstants.MINIMUM_GOAL_TIME) { + throw new ChallengeException(ChallengeError.INVALID_GOAL_TIME); } } } \ No newline at end of file From 1f3062ab8926531641bd2f4abd03af42794b646b Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 16:07:02 +0900 Subject: [PATCH 016/100] =?UTF-8?q?refactor=20-=20#166=20AuthController=20?= =?UTF-8?q?valid=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/hmh/domain/auth/controller/AuthController.java | 3 ++- .../org/hmh/domain/auth/dto/request/SocialSignUpRequest.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) 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 f12e88a5..792bdbc9 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 @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.auth.controller; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -39,7 +40,7 @@ public ResponseEntity> orderLogin( public ResponseEntity> orderSignup( @RequestHeader("Authorization") final String socialAccessToken, @RequestHeader("OS") final String os, - @RequestBody final SocialSignUpRequest request + @RequestBody @Valid final SocialSignUpRequest request ) { return ResponseEntity .status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus()) 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 a2e41616..166c194d 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,7 @@ package sopt.org.hmh.domain.auth.dto.request; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.request.ChallengeSignUpRequest; @@ -12,6 +13,7 @@ public record SocialSignUpRequest( String name, @JsonProperty(value = "onboarding") OnboardingRequest onboardingRequest, + @Valid @JsonProperty(value = "challenge") ChallengeSignUpRequest challengeSignUpRequest ) { From 38cc570d7c95ef9eb698a02ea80a8a09bd6d3e1a Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 16:08:14 +0900 Subject: [PATCH 017/100] =?UTF-8?q?refactor=20-=20#166=20ChallengeControll?= =?UTF-8?q?er=20valid=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/app/dto/request/ChallengeAppArrayRequest.java | 3 ++- .../domain/challenge/controller/ChallengeController.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppArrayRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppArrayRequest.java index 5c6f8b41..fab0b981 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppArrayRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppArrayRequest.java @@ -1,8 +1,9 @@ package sopt.org.hmh.domain.app.dto.request; +import jakarta.validation.Valid; import java.util.List; public record ChallengeAppArrayRequest( - List apps + List<@Valid ChallengeAppRequest> apps ) { } 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 1737df88..1c8775c9 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 @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.challenge.controller; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -27,7 +28,7 @@ public class ChallengeController implements ChallengeApi { @Override public ResponseEntity> orderAddChallenge(@UserId final Long userId, @RequestHeader("OS") final String os, - @RequestBody final ChallengeRequest request) { + @RequestBody @Valid final ChallengeRequest request) { challengeService.addChallenge(userId, request, os); return ResponseEntity @@ -59,7 +60,7 @@ public ResponseEntity> orderGetDailyChallen @Override public ResponseEntity> orderAddApps(@UserId final Long userId, @RequestHeader("OS") final String os, - @RequestBody final ChallengeAppArrayRequest requests) { + @RequestBody @Valid final ChallengeAppArrayRequest requests) { Challenge challenge = challengeService.findCurrentChallengeByUserId(userId); challengeService.addApps(challenge, requests.apps(), os); @@ -73,7 +74,7 @@ public ResponseEntity> orderAddApps(@UserId final Long userId, @Override public ResponseEntity> orderRemoveApp(@UserId final Long userId, @RequestHeader("OS") final String os, - @RequestBody final AppRemoveRequest request) { + @RequestBody @Valid final AppRemoveRequest request) { Challenge challenge = challengeService.findCurrentChallengeByUserId(userId); challengeService.removeApp(challenge, request, os); From b433262e3d67e7803c57001574ea6b4ad22dd8ea Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 16:09:35 +0900 Subject: [PATCH 018/100] =?UTF-8?q?refactor=20-=20#166=20DailyChallengeCon?= =?UTF-8?q?troller=20valid=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dailychallenge/controller/DailyChallengeController.java | 3 ++- .../dto/request/FinishedDailyChallengeListRequest.java | 3 ++- .../dto/request/FinishedDailyChallengeRequest.java | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java index 2a30c4db..40fca2e8 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.dailychallenge.controller; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -22,7 +23,7 @@ public class DailyChallengeController implements DailyChallengeApi { public ResponseEntity> orderAddHistoryDailyChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, - @RequestBody final FinishedDailyChallengeListRequest request + @RequestBody @Valid final FinishedDailyChallengeListRequest request ) { dailyChallengeFacade.addFinishedDailyChallengeHistory(userId, request, os); return ResponseEntity diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java index 5e5c9c87..cae0e1da 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java @@ -1,9 +1,10 @@ package sopt.org.hmh.domain.dailychallenge.dto.request; +import jakarta.validation.Valid; import java.util.List; public record FinishedDailyChallengeListRequest( - List finishedDailyChallenges + List<@Valid FinishedDailyChallengeRequest> finishedDailyChallenges ) { } diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java index 19d1b777..540bc927 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java @@ -1,11 +1,14 @@ package sopt.org.hmh.domain.dailychallenge.dto.request; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import java.time.LocalDate; import java.util.List; import sopt.org.hmh.domain.app.dto.request.HistoryAppRequest; public record FinishedDailyChallengeRequest( + @NotNull(message = "챌린지 날짜는 null일 수 없습니다.") LocalDate challengeDate, - List apps + List<@Valid HistoryAppRequest> apps ) { } From 2ed097e04af49aae1e4cc44b761ee22f9aa42af2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 16:11:43 +0900 Subject: [PATCH 019/100] =?UTF-8?q?refactor=20-=20#166=20PointController?= =?UTF-8?q?=20@Valid=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/dto/request/ChallengeDateRequest.java | 10 ++++++++++ .../sopt/org/hmh/domain/point/controller/PointApi.java | 2 +- .../hmh/domain/point/controller/PointController.java | 5 +++-- .../domain/point/dto/request/ChallengeDateRequest.java | 8 -------- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeDateRequest.java delete mode 100644 src/main/java/sopt/org/hmh/domain/point/dto/request/ChallengeDateRequest.java diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeDateRequest.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeDateRequest.java new file mode 100644 index 00000000..b94f0828 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeDateRequest.java @@ -0,0 +1,10 @@ +package sopt.org.hmh.domain.challenge.dto.request; + +import jakarta.validation.constraints.NotNull; +import java.time.LocalDate; + +public record ChallengeDateRequest( + @NotNull(message = "챌린지 날짜는 null일 수 없습니다.") + LocalDate challengeDate +) { +} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/point/controller/PointApi.java b/src/main/java/sopt/org/hmh/domain/point/controller/PointApi.java index 527575ce..f65a06f0 100644 --- a/src/main/java/sopt/org/hmh/domain/point/controller/PointApi.java +++ b/src/main/java/sopt/org/hmh/domain/point/controller/PointApi.java @@ -7,7 +7,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; -import sopt.org.hmh.domain.point.dto.request.ChallengeDateRequest; +import sopt.org.hmh.domain.challenge.dto.request.ChallengeDateRequest; import sopt.org.hmh.domain.point.dto.response.ChallengePointStatusListResponse; import sopt.org.hmh.domain.point.dto.response.EarnPointResponse; import sopt.org.hmh.domain.point.dto.response.UsagePointResponse; diff --git a/src/main/java/sopt/org/hmh/domain/point/controller/PointController.java b/src/main/java/sopt/org/hmh/domain/point/controller/PointController.java index 209b5f2c..b9e29920 100644 --- a/src/main/java/sopt/org/hmh/domain/point/controller/PointController.java +++ b/src/main/java/sopt/org/hmh/domain/point/controller/PointController.java @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.point.controller; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -7,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import sopt.org.hmh.domain.point.dto.request.ChallengeDateRequest; +import sopt.org.hmh.domain.challenge.dto.request.ChallengeDateRequest; import sopt.org.hmh.domain.point.dto.response.*; import sopt.org.hmh.domain.point.exception.PointSuccess; import sopt.org.hmh.domain.point.service.PointFacade; @@ -37,7 +38,7 @@ public ResponseEntity> orderGetCh @PatchMapping("/use") public ResponseEntity> orderUsagePointAndChallengeFailed( @UserId final Long userId, - @RequestBody final ChallengeDateRequest challengeDateRequest + @RequestBody @Valid final ChallengeDateRequest challengeDateRequest ) { return ResponseEntity .status(PointSuccess.POINT_USAGE_SUCCESS.getHttpStatus()) diff --git a/src/main/java/sopt/org/hmh/domain/point/dto/request/ChallengeDateRequest.java b/src/main/java/sopt/org/hmh/domain/point/dto/request/ChallengeDateRequest.java deleted file mode 100644 index 931db058..00000000 --- a/src/main/java/sopt/org/hmh/domain/point/dto/request/ChallengeDateRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package sopt.org.hmh.domain.point.dto.request; - -import java.time.LocalDate; - -public record ChallengeDateRequest( - LocalDate challengeDate -) { -} \ No newline at end of file From d80fd58d44553cead23c448bc963a6c73becee8c Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:05:16 +0900 Subject: [PATCH 020/100] =?UTF-8?q?refactor=20-=20#122=20Request=20to=20En?= =?UTF-8?q?tity=EC=9D=98=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EA=B0=80=EB=8F=85=EC=84=B1=20=ED=96=A5?= =?UTF-8?q?=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/ChallengeRequest.java | 12 +++++-- .../challenge/service/ChallengeService.java | 32 +++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java index 7f32031f..c2d60485 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/ChallengeRequest.java @@ -1,9 +1,7 @@ package sopt.org.hmh.domain.challenge.dto.request; import jakarta.validation.constraints.NotNull; -import sopt.org.hmh.domain.app.domain.AppConstants; -import sopt.org.hmh.domain.app.domain.exception.AppError; -import sopt.org.hmh.domain.app.domain.exception.AppException; +import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.domain.ChallengeConstants; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; @@ -23,4 +21,12 @@ public record ChallengeRequest( throw new ChallengeException(ChallengeError.INVALID_GOAL_TIME); } } + + public Challenge toEntity(Long userId) { + return Challenge.builder() + .userId(userId) + .period(period) + .goalTime(goalTime) + .build(); + } } 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 a745bfd4..a45c80ce 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 @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.challenge.service; +import java.util.stream.IntStream; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,7 +26,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; import java.util.List; @Service @@ -39,14 +39,8 @@ public class ChallengeService { @Transactional public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { - Integer period = challengeRequest.period(); - Long goalTime = challengeRequest.goalTime(); - - Challenge challenge = challengeRepository.save(Challenge.builder() - .userId(userId) - .period(period) - .goalTime(goalTime) - .build()); + Challenge challenge = challengeRepository.save(challengeRequest.toEntity(userId)); + LocalDate startDate = challenge.getCreatedAt().toLocalDate(); User user = userService.findByIdOrThrowException(userId); Long previousChallengeId = user.getCurrentChallengeId(); @@ -58,17 +52,15 @@ public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, St addApps(challenge, previousApps, os); } - List dailyChallenges = new ArrayList<>(); - LocalDate startDate = challenge.getCreatedAt().toLocalDate(); - for (int dayCount = 0; dayCount < period; dayCount++) { - DailyChallenge dailyChallenge = DailyChallenge.builder() - .challengeDate(startDate.plusDays(dayCount)) - .challenge(challenge) - .userId(userId) - .goalTime(goalTime).build(); - dailyChallenges.add(dailyChallenge); - } - dailyChallengeRepository.saveAll(dailyChallenges); + Integer period = challengeRequest.period(); + Long goalTime = challengeRequest.goalTime(); + dailyChallengeRepository.saveAll(IntStream.range(0, period) + .mapToObj(i -> DailyChallenge.builder() + .challengeDate(startDate.plusDays(i)) + .challenge(challenge) + .userId(userId) + .goalTime(goalTime).build()) + .toList()); user.changeCurrentChallengeId(challenge.getId()); From 6fc77805b84a325837f13a758d7c781172466edd Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:11:13 +0900 Subject: [PATCH 021/100] =?UTF-8?q?refactor=20-=20#122=20User=20domain?= =?UTF-8?q?=EC=97=90=20=EC=A0=9C=EC=95=BD=EC=A1=B0=EA=B1=B4=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 --- .../java/sopt/org/hmh/domain/user/domain/User.java | 11 ++++++----- .../auth/social/kakao/fegin/KakaoLoginService.java | 10 +--------- .../auth/social/kakao/response/KakaoUserProfile.java | 3 +-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/User.java b/src/main/java/sopt/org/hmh/domain/user/domain/User.java index d67594a8..ecb68520 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/User.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/User.java @@ -31,10 +31,15 @@ public class User extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(nullable = false) private String name; + + @Column(nullable = false) private Long currentChallengeId; @Enumerated(EnumType.STRING) + @Column(nullable = false) private SocialPlatform socialPlatform; @Column(unique = true) @@ -43,9 +48,6 @@ public class User extends BaseTimeEntity { @Min(value = 0) private Integer point; - @Column(columnDefinition = "TEXT") - private String profileImageUrl; - private LocalDate recentLockDate; private boolean isDeleted = false; @@ -59,9 +61,8 @@ public User(SocialPlatform socialPlatform, String socialId, String name) { this.point = UserConstants.INITIAL_POINT; } - public void updateSocialInfo(String nickname, String profileImageUrl) { + public void updateSocialInfo(String nickname) { this.name = nickname; - this.profileImageUrl = profileImageUrl; } public void softDelete() { diff --git a/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java b/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java index c1aff229..af480f48 100644 --- a/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java +++ b/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java @@ -36,15 +36,7 @@ public void updateUserInfoByKakao(User loginUser, final String socialAccessToken KakaoUserResponse userRequest = getKakaoUserRequest(socialAccessToken); try { - String nickname = userRequest.kakaoAccount().profile().nickname(); - String profileImageUrl = userRequest.kakaoAccount().profile().profileImageUrl(); - - if (!StringUtils.hasText(profileImageUrl)) { - profileImageUrl = ""; - } - - loginUser.updateSocialInfo(nickname, profileImageUrl); - + loginUser.updateSocialInfo(userRequest.kakaoAccount().profile().nickname()); } catch (NullPointerException exception) { throw new JwtException(JwtError.INVALID_SOCIAL_ACCESS_TOKEN_FORMAT); } diff --git a/src/main/java/sopt/org/hmh/global/auth/social/kakao/response/KakaoUserProfile.java b/src/main/java/sopt/org/hmh/global/auth/social/kakao/response/KakaoUserProfile.java index 5809a820..e903cf2a 100644 --- a/src/main/java/sopt/org/hmh/global/auth/social/kakao/response/KakaoUserProfile.java +++ b/src/main/java/sopt/org/hmh/global/auth/social/kakao/response/KakaoUserProfile.java @@ -5,7 +5,6 @@ @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public record KakaoUserProfile( - String nickname, - String profileImageUrl + String nickname ) { } \ No newline at end of file From 95426026e873231a6b2ed3d31fdfb5686f38339a Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:12:06 +0900 Subject: [PATCH 022/100] =?UTF-8?q?refactor=20-=20#122=20User=20domain=20?= =?UTF-8?q?=EC=A0=9C=EC=95=BD=EC=A1=B0=EA=B1=B4=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/domain/User.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/User.java b/src/main/java/sopt/org/hmh/domain/user/domain/User.java index ecb68520..0423f5c2 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/User.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/User.java @@ -35,7 +35,6 @@ public class User extends BaseTimeEntity { @Column(nullable = false) private String name; - @Column(nullable = false) private Long currentChallengeId; @Enumerated(EnumType.STRING) From 18939dd86fd2eea10d57089e27e628080f567bfa Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:21:08 +0900 Subject: [PATCH 023/100] =?UTF-8?q?refactor=20-=20#122=20AppService=20->?= =?UTF-8?q?=20HistoryAppService=EB=A1=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=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 --- .../app/service/{AppService.java => HistoryAppService.java} | 2 +- .../domain/dailychallenge/service/DailyChallengeFacade.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/sopt/org/hmh/domain/app/service/{AppService.java => HistoryAppService.java} (98%) diff --git a/src/main/java/sopt/org/hmh/domain/app/service/AppService.java b/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java similarity index 98% rename from src/main/java/sopt/org/hmh/domain/app/service/AppService.java rename to src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java index e6e24b93..4782342b 100644 --- a/src/main/java/sopt/org/hmh/domain/app/service/AppService.java +++ b/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java @@ -15,7 +15,7 @@ @Service @RequiredArgsConstructor @Transactional -public class AppService { +public class HistoryAppService { private final HistoryAppRepository historyAppRepository; diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index be3ba3f1..b8ebb09a 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.app.domain.ChallengeApp; -import sopt.org.hmh.domain.app.service.AppService; +import sopt.org.hmh.domain.app.service.HistoryAppService; import sopt.org.hmh.domain.challenge.service.ChallengeService; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; @@ -17,7 +17,7 @@ public class DailyChallengeFacade { private final DailyChallengeService dailyChallengeService; - private final AppService appService; + private final HistoryAppService historyAppService; private final ChallengeService challengeService; private final UserService userService; @@ -27,7 +27,7 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); List currentChallengeApps = challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); - appService.addAppForHistory(currentChallengeApps, request.apps(), dailyChallenge, os); + historyAppService.addAppForHistory(currentChallengeApps, request.apps(), dailyChallenge, os); }); } } From 9c71768f8c16c7221f1db0348b97601f527930dd Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:31:35 +0900 Subject: [PATCH 024/100] =?UTF-8?q?refactor=20-=20#122=20ChallengeAppServi?= =?UTF-8?q?ce=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/ChallengeAppService.java | 47 +++++++++++++ .../challenge/service/ChallengeService.java | 68 ++++--------------- .../service/DailyChallengeService.java | 12 ++++ 3 files changed, 73 insertions(+), 54 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java 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 new file mode 100644 index 00000000..e82e3188 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/app/service/ChallengeAppService.java @@ -0,0 +1,47 @@ +package sopt.org.hmh.domain.app.service; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +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 sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; +import sopt.org.hmh.domain.app.repository.ChallengeAppRepository; +import sopt.org.hmh.domain.challenge.domain.Challenge; + +@Service +@RequiredArgsConstructor +@Transactional +public class ChallengeAppService { + + private final ChallengeAppRepository challengeAppRepository; + + public void removeApp(Challenge challenge, String appcode, String os) { + ChallengeApp appToRemove = + challengeAppRepository.findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), appcode, os); + challengeAppRepository.delete(appToRemove); + } + + public void addApps(Challenge challenge, List requests, String os) { + List appsToUpdate = requests.stream() + .map(request -> { + validateAppExist(challenge.getId(), request.appCode(), os); + return ChallengeApp.builder() + .challenge(challenge) + .appCode(request.appCode()) + .goalTime(request.goalTime()) + .os(os) + .build(); + }).toList(); + challengeAppRepository.saveAll(appsToUpdate); + } + + private void validateAppExist(Long challengeId, String appCode, String os) { + if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)) { + throw new AppException(AppError.APP_EXIST_ALREADY); + } + } + +} 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 a45c80ce..2d9380c9 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 @@ -1,16 +1,12 @@ package sopt.org.hmh.domain.challenge.service; -import java.util.stream.IntStream; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; 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 sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; -import sopt.org.hmh.domain.app.repository.ChallengeAppRepository; +import sopt.org.hmh.domain.app.service.ChallengeAppService; import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; @@ -19,7 +15,7 @@ import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; import sopt.org.hmh.domain.challenge.repository.ChallengeRepository; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; -import sopt.org.hmh.domain.dailychallenge.repository.DailyChallengeRepository; +import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService; import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.domain.user.service.UserService; @@ -33,38 +29,30 @@ public class ChallengeService { private final ChallengeRepository challengeRepository; - private final ChallengeAppRepository challengeAppRepository; - private final DailyChallengeRepository dailyChallengeRepository; + private final DailyChallengeService dailyChallengeService; private final UserService userService; + private final ChallengeAppService challengeAppService; @Transactional public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { Challenge challenge = challengeRepository.save(challengeRequest.toEntity(userId)); LocalDate startDate = challenge.getCreatedAt().toLocalDate(); - User user = userService.findByIdOrThrowException(userId); - Long previousChallengeId = user.getCurrentChallengeId(); + this.addAppsIfPreviousChallengeExist(os, user.getCurrentChallengeId(), challenge); + user.changeCurrentChallengeId(challenge.getId()); + dailyChallengeService.addDailyChallenge(userId, startDate, challenge); + + return challenge; + } + + private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId, Challenge challenge) { if (previousChallengeId != null) { - Challenge previousChallenge = findByIdOrElseThrow(previousChallengeId); + Challenge previousChallenge = this.findByIdOrElseThrow(previousChallengeId); List previousApps = previousChallenge.getApps().stream() .map(app -> new ChallengeAppRequest(app.getAppCode(), app.getGoalTime())) .toList(); - addApps(challenge, previousApps, os); + challengeAppService.addApps(challenge, previousApps, os); } - - Integer period = challengeRequest.period(); - Long goalTime = challengeRequest.goalTime(); - dailyChallengeRepository.saveAll(IntStream.range(0, period) - .mapToObj(i -> DailyChallenge.builder() - .challengeDate(startDate.plusDays(i)) - .challenge(challenge) - .userId(userId) - .goalTime(goalTime).build()) - .toList()); - - user.changeCurrentChallengeId(challenge.getId()); - - return challenge; } public ChallengeResponse getChallenge(Long userId) { @@ -95,28 +83,6 @@ public DailyChallengeResponse getDailyChallenge(Long userId) { .build(); } - @Transactional - public void removeApp(Challenge challenge, AppRemoveRequest request, String os) { - ChallengeApp appToRemove = challengeAppRepository - .findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), request.appCode(), os); - challengeAppRepository.delete(appToRemove); - } - - @Transactional - public void addApps(Challenge challenge, List requests, String os) { - List appsToUpdate = requests.stream() - .map(request -> { - validateAppExist(challenge.getId(), request.appCode(), os); - return ChallengeApp.builder() - .challenge(challenge) - .appCode(request.appCode()) - .goalTime(request.goalTime()) - .os(os) - .build(); - }).toList(); - challengeAppRepository.saveAll(appsToUpdate); - } - @Transactional public void deleteChallengeRelatedByUserId(List expiredUserIdList) { challengeRepository.deleteByUserIdIn(expiredUserIdList); @@ -127,12 +93,6 @@ private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) return (daysBetween >= period) ? -1 : daysBetween; } - private void validateAppExist(Long challengeId, String appCode, String os) { - if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)) { - throw new AppException(AppError.APP_EXIST_ALREADY); - } - } - public Challenge findByIdOrElseThrow(Long challengeId) { return challengeRepository.findById(challengeId).orElseThrow( () -> new ChallengeException(ChallengeError.CHALLENGE_NOT_FOUND)); 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 bf8a48ca..000e6646 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 @@ -2,9 +2,11 @@ import java.time.LocalDate; import java.util.List; +import java.util.stream.IntStream; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; import sopt.org.hmh.domain.dailychallenge.domain.Status; import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeError; @@ -65,4 +67,14 @@ public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChal } }); } + + public void addDailyChallenge(Long userId, LocalDate startDate, Challenge challenge) { + dailyChallengeRepository.saveAll(IntStream.range(0, challenge.getPeriod()) + .mapToObj(i -> DailyChallenge.builder() + .challengeDate(startDate.plusDays(i)) + .challenge(challenge) + .userId(userId) + .goalTime(challenge.getGoalTime()).build()) + .toList()); + } } \ No newline at end of file From 840ccaecc02cd6718084d70452009e609a53b02a Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:47:10 +0900 Subject: [PATCH 025/100] =?UTF-8?q?refactor=20-=20#122=20ChallengeFacade?= =?UTF-8?q?=20ChallengeService=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/auth/service/AuthService.java | 10 +- .../controller/ChallengeController.java | 18 ++-- .../challenge/service/ChallengeFacade.java | 101 ++++++++++++++++++ .../challenge/service/ChallengeService.java | 86 ++------------- .../service/DailyChallengeFacade.java | 1 + 5 files changed, 124 insertions(+), 92 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java diff --git a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java b/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java index a1bc731f..00ecd938 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java +++ b/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java @@ -3,9 +3,10 @@ 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.ChallengeService; +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; @@ -27,7 +28,8 @@ public class AuthService { private final KakaoLoginService kakaoLoginService; private final AppleOAuthProvider appleOAuthProvider; - private final ChallengeService challengeService; + private final ChallengeFacade challengeFacade; + private final ChallengeAppService challengeAppService; private final TokenService tokenService; private final UserService userService; @@ -52,8 +54,8 @@ public LoginResponse signup(String socialAccessToken, SocialSignUpRequest reques User user = userService.addUser(socialPlatform, socialId, request.name()); - Challenge challenge = challengeService.addChallenge(user.getId(), request.toChallengeRequest() , os); - challengeService.addApps(challenge, request.challengeSignUpRequest().apps(), os); + Challenge challenge = challengeFacade.addChallenge(user.getId(), request.toChallengeRequest() , os); + challengeAppService.addApps(challenge, request.challengeSignUpRequest().apps(), os); userService.registerOnboardingInfo(request); 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 1c8775c9..7487ce03 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 @@ -12,7 +12,7 @@ import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; -import sopt.org.hmh.domain.challenge.service.ChallengeService; +import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.global.auth.UserId; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -22,14 +22,14 @@ @RequestMapping("/api/v1/challenge") public class ChallengeController implements ChallengeApi { - private final ChallengeService challengeService; + private final ChallengeFacade challengeFacade; @PostMapping @Override public ResponseEntity> orderAddChallenge(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeRequest request) { - challengeService.addChallenge(userId, request, os); + challengeFacade.addChallenge(userId, request, os); return ResponseEntity .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) @@ -43,7 +43,7 @@ public ResponseEntity> orderGetChallenge(@UserId return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, - challengeService.getChallenge(userId))); + challengeFacade.getChallenge(userId))); } @GetMapping("/home") @@ -53,7 +53,7 @@ public ResponseEntity> orderGetDailyChallen return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, - challengeService.getDailyChallenge(userId))); + challengeFacade.getDailyChallenge(userId))); } @PostMapping("/app") @@ -61,8 +61,8 @@ public ResponseEntity> orderGetDailyChallen public ResponseEntity> orderAddApps(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeAppArrayRequest requests) { - Challenge challenge = challengeService.findCurrentChallengeByUserId(userId); - challengeService.addApps(challenge, requests.apps(), os); + Challenge challenge = challengeFacade.findCurrentChallengeByUserId(userId); + challengeFacade.addApps(challenge, requests.apps(), os); return ResponseEntity .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) @@ -75,8 +75,8 @@ public ResponseEntity> orderAddApps(@UserId final Long userId, public ResponseEntity> orderRemoveApp(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final AppRemoveRequest request) { - Challenge challenge = challengeService.findCurrentChallengeByUserId(userId); - challengeService.removeApp(challenge, request, os); + Challenge challenge = challengeFacade.findCurrentChallengeByUserId(userId); + challengeFacade.removeApp(challenge, request.appCode(), os); return ResponseEntity .status(AppSuccess.REMOVE_APP_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 new file mode 100644 index 00000000..cfbacac0 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeFacade.java @@ -0,0 +1,101 @@ +package sopt.org.hmh.domain.challenge.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; +import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; +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.response.ChallengeResponse; +import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; +import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; +import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService; +import sopt.org.hmh.domain.user.domain.User; +import sopt.org.hmh.domain.user.service.UserService; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ChallengeFacade { + + private final ChallengeService challengeService; + private final DailyChallengeService dailyChallengeService; + private final UserService userService; + private final ChallengeAppService challengeAppService; + + @Transactional + public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { + Challenge challenge = challengeService.save(challengeRequest.toEntity(userId)); + LocalDate startDate = challenge.getCreatedAt().toLocalDate(); + + User user = userService.findByIdOrThrowException(userId); + this.addAppsIfPreviousChallengeExist(os, user.getCurrentChallengeId(), challenge); + user.changeCurrentChallengeId(challenge.getId()); + + dailyChallengeService.addDailyChallenge(userId, startDate, challenge); + + return challenge; + } + + private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId, Challenge challenge) { + if (previousChallengeId != null) { + Challenge previousChallenge = challengeService.findByIdOrElseThrow(previousChallengeId); + List previousApps = previousChallenge.getApps().stream() + .map(app -> new ChallengeAppRequest(app.getAppCode(), app.getGoalTime())) + .toList(); + challengeAppService.addApps(challenge, previousApps, os); + } + } + + public ChallengeResponse getChallenge(Long userId) { + Challenge challenge = findCurrentChallengeByUserId(userId); + Integer todayIndex = calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod()); + + return ChallengeResponse.builder() + .period(challenge.getPeriod()) + .statuses(challenge.getHistoryDailyChallenges() + .stream() + .map(DailyChallenge::getStatus) + .toList()) + .todayIndex(todayIndex) + .startDate(challenge.getCreatedAt().toLocalDate().toString()) + .goalTime(challenge.getGoalTime()) + .apps(challenge.getApps().stream() + .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) + .build(); + } + + public DailyChallengeResponse getDailyChallenge(Long userId) { + Challenge challenge = findCurrentChallengeByUserId(userId); + + return DailyChallengeResponse.builder() + .goalTime(challenge.getGoalTime()) + .apps(challenge.getApps().stream() + .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) + .build(); + } + + public Challenge findCurrentChallengeByUserId(Long userId) { + User user = userService.findByIdOrThrowException(userId); + return challengeService.findByIdOrElseThrow(user.getCurrentChallengeId()); + } + + private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) { + int daysBetween = (int) ChronoUnit.DAYS.between(challengeCreateAt.toLocalDate(), LocalDate.now()); + return (daysBetween >= period) ? -1 : daysBetween; + } + + public void addApps(Challenge challenge, List requests, String os) { + challengeAppService.addApps(challenge, requests, os); + } + + public void removeApp(Challenge challenge, String appCode, String os) { + challengeAppService.removeApp(challenge, appCode, os); + } +} \ No newline at end of file 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 2d9380c9..3472f34c 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 @@ -1,109 +1,37 @@ package sopt.org.hmh.domain.challenge.service; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.app.domain.ChallengeApp; -import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; -import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; -import sopt.org.hmh.domain.app.service.ChallengeAppService; import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; -import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; -import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; -import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; import sopt.org.hmh.domain.challenge.repository.ChallengeRepository; -import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; -import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService; -import sopt.org.hmh.domain.user.domain.User; -import sopt.org.hmh.domain.user.service.UserService; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; @Service @RequiredArgsConstructor public class ChallengeService { private final ChallengeRepository challengeRepository; - private final DailyChallengeService dailyChallengeService; - private final UserService userService; - private final ChallengeAppService challengeAppService; - - @Transactional - public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { - Challenge challenge = challengeRepository.save(challengeRequest.toEntity(userId)); - LocalDate startDate = challenge.getCreatedAt().toLocalDate(); - User user = userService.findByIdOrThrowException(userId); - this.addAppsIfPreviousChallengeExist(os, user.getCurrentChallengeId(), challenge); - user.changeCurrentChallengeId(challenge.getId()); - dailyChallengeService.addDailyChallenge(userId, startDate, challenge); - - return challenge; - } - - private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId, Challenge challenge) { - if (previousChallengeId != null) { - Challenge previousChallenge = this.findByIdOrElseThrow(previousChallengeId); - List previousApps = previousChallenge.getApps().stream() - .map(app -> new ChallengeAppRequest(app.getAppCode(), app.getGoalTime())) - .toList(); - challengeAppService.addApps(challenge, previousApps, os); - } - } - - public ChallengeResponse getChallenge(Long userId) { - Challenge challenge = findCurrentChallengeByUserId(userId); - Integer todayIndex = calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod()); - - return ChallengeResponse.builder() - .period(challenge.getPeriod()) - .statuses(challenge.getHistoryDailyChallenges() - .stream() - .map(DailyChallenge::getStatus) - .toList()) - .todayIndex(todayIndex) - .startDate(challenge.getCreatedAt().toLocalDate().toString()) - .goalTime(challenge.getGoalTime()) - .apps(challenge.getApps().stream() - .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) - .build(); - } - - public DailyChallengeResponse getDailyChallenge(Long userId) { - Challenge challenge = findCurrentChallengeByUserId(userId); - - return DailyChallengeResponse.builder() - .goalTime(challenge.getGoalTime()) - .apps(challenge.getApps().stream() - .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) - .build(); - } @Transactional public void deleteChallengeRelatedByUserId(List expiredUserIdList) { challengeRepository.deleteByUserIdIn(expiredUserIdList); } - private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) { - int daysBetween = (int) ChronoUnit.DAYS.between(challengeCreateAt.toLocalDate(), LocalDate.now()); - return (daysBetween >= period) ? -1 : daysBetween; - } - public Challenge findByIdOrElseThrow(Long challengeId) { return challengeRepository.findById(challengeId).orElseThrow( () -> new ChallengeException(ChallengeError.CHALLENGE_NOT_FOUND)); } - public Challenge findCurrentChallengeByUserId(Long userId) { - User user = userService.findByIdOrThrowException(userId); - return findByIdOrElseThrow(user.getCurrentChallengeId()); - } - public List getCurrentChallengeAppByChallengeId(Long challengeId) { return this.findByIdOrElseThrow(challengeId).getApps(); } -} \ No newline at end of file + + public Challenge save(Challenge challenge) { + return challengeRepository.save(challenge); + } + +} diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index b8ebb09a..acde8691 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -6,6 +6,7 @@ import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.app.service.HistoryAppService; +import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.domain.challenge.service.ChallengeService; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; From 373e0be41efbfc382968d935bdb9d9d53f671d93 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:54:05 +0900 Subject: [PATCH 026/100] =?UTF-8?q?refactor=20-=20#122=20toEntity=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=9D=B4=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EA=B0=80=EB=8F=85=EC=84=B1=20=ED=96=A5?= =?UTF-8?q?=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dto/request/ChallengeAppRequest.java | 11 +++++++++++ .../domain/app/service/ChallengeAppService.java | 17 ++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java index 3d8d5f3f..20732ecd 100644 --- a/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java +++ b/src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppRequest.java @@ -2,8 +2,10 @@ import jakarta.validation.constraints.NotNull; import sopt.org.hmh.domain.app.domain.AppConstants; +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 sopt.org.hmh.domain.challenge.domain.Challenge; public record ChallengeAppRequest( @NotNull(message = "앱 코드는 null일 수 없습니다.") @@ -16,4 +18,13 @@ public record ChallengeAppRequest( throw new AppException(AppError.INVALID_GOAL_TIME); } } + + public ChallengeApp toEntity(Challenge challenge , String os) { + return ChallengeApp.builder() + .challenge(challenge) + .appCode(appCode) + .goalTime(goalTime) + .os(os) + .build(); + } } 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 e82e3188..771f3fa3 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 @@ -25,17 +25,12 @@ public void removeApp(Challenge challenge, String appcode, String os) { } public void addApps(Challenge challenge, List requests, String os) { - List appsToUpdate = requests.stream() - .map(request -> { - validateAppExist(challenge.getId(), request.appCode(), os); - return ChallengeApp.builder() - .challenge(challenge) - .appCode(request.appCode()) - .goalTime(request.goalTime()) - .os(os) - .build(); - }).toList(); - challengeAppRepository.saveAll(appsToUpdate); + challengeAppRepository.saveAll( + requests.stream().map( + request -> { + validateAppExist(challenge.getId(), request.appCode(), os); + return request.toEntity(challenge, os); + }).toList()); } private void validateAppExist(Long challengeId, String appCode, String os) { From 47e2a6900be5279cdd2c601a4a1d30e74776bc45 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 18 Jun 2024 23:59:27 +0900 Subject: [PATCH 027/100] =?UTF-8?q?refactor=20-=20#122=20addHistoryApp=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=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/app/service/HistoryAppService.java | 5 +++-- .../dailychallenge/service/DailyChallengeFacade.java | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java b/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java index 4782342b..ca7a17eb 100644 --- a/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java +++ b/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java @@ -19,8 +19,9 @@ public class HistoryAppService { private final HistoryAppRepository historyAppRepository; - public void addAppForHistory(List currentChallengeApps, List apps, - DailyChallenge dailyChallenge, String os) { + public void addHistoryApp( + List currentChallengeApps, List apps, + DailyChallenge dailyChallenge, String os) { historyAppRepository.saveAll(supplementAdditionalInfo(currentChallengeApps, apps, dailyChallenge, os)); } diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index acde8691..dea2c475 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -6,7 +6,6 @@ import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.app.service.HistoryAppService; -import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.domain.challenge.service.ChallengeService; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; @@ -23,12 +22,13 @@ public class DailyChallengeFacade { private final UserService userService; public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequest requests, String os) { + Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); + List currentChallengeApps = challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); + requests.finishedDailyChallenges().forEach(request -> { DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); - Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); - List currentChallengeApps = challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); - historyAppService.addAppForHistory(currentChallengeApps, request.apps(), dailyChallenge, os); + historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); }); } } From 0a83bd122237ec2c0d7a39b410cf0169e6485765 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:00:06 +0900 Subject: [PATCH 028/100] =?UTF-8?q?refactor=20-=20#122=20this=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=20=ED=96=A5=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/challenge/service/ChallengeFacade.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 cfbacac0..c78ff61f 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 @@ -54,8 +54,8 @@ private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId } public ChallengeResponse getChallenge(Long userId) { - Challenge challenge = findCurrentChallengeByUserId(userId); - Integer todayIndex = calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod()); + Challenge challenge = this.findCurrentChallengeByUserId(userId); + Integer todayIndex = this.calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod()); return ChallengeResponse.builder() .period(challenge.getPeriod()) @@ -72,7 +72,7 @@ public ChallengeResponse getChallenge(Long userId) { } public DailyChallengeResponse getDailyChallenge(Long userId) { - Challenge challenge = findCurrentChallengeByUserId(userId); + Challenge challenge = this.findCurrentChallengeByUserId(userId); return DailyChallengeResponse.builder() .goalTime(challenge.getGoalTime()) From f5bd894657ffaf717e7ff85e7ef95d3819cbeb18 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:04:34 +0900 Subject: [PATCH 029/100] =?UTF-8?q?refactor=20-=20#122=20facade=EC=97=90?= =?UTF-8?q?=EC=84=9C=20facade=EB=A5=BC=20=EC=B0=B8=EC=A1=B0=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=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 --- .../org/hmh/domain/point/service/PointFacade.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java b/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java index 606db230..a21ec8fc 100644 --- a/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java +++ b/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java @@ -26,7 +26,8 @@ public class PointFacade { private final ChallengeService challengeService; public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challengeDate) { - DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); + DailyChallenge dailyChallenge = + dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); User user = userService.findByIdOrThrowException(userId); dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); @@ -39,19 +40,19 @@ public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challe } public EarnPointResponse earnPointAndChallengeEarned(Long userId, LocalDate challengeDate) { - DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); + DailyChallenge dailyChallenge = + dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); User user = userService.findByIdOrThrowException(userId); dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.UNEARNED)); dailyChallenge.changeStatus(Status.EARNED); - return new EarnPointResponse( - user.increasePoint(ChallengeConstants.EARNED_POINT) - ); + return new EarnPointResponse(user.increasePoint(ChallengeConstants.EARNED_POINT)); } public ChallengePointStatusListResponse getChallengePointStatusList(Long userId) { - Challenge challenge = challengeService.findCurrentChallengeByUserId(userId); + User user = userService.findByIdOrThrowException(userId); + Challenge challenge = challengeService.findByIdOrElseThrow(user.getCurrentChallengeId()); List challengePointStatusResponseList = challenge.getHistoryDailyChallenges().stream() .map(dailyChallenge -> new ChallengePointStatusResponse( From 4fc73071e02cdfc85dd897232bbd1771fdd3b1ac Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:13:09 +0900 Subject: [PATCH 030/100] =?UTF-8?q?refactor=20-=20#122=20controller?= =?UTF-8?q?=EA=B0=80=20=ED=95=98=EB=82=98=EC=9D=98=20class=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=94=EB=9D=BC=EB=B3=B4=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DailyChallengeController.java | 4 +--- .../service/DailyChallengeFacade.java | 15 +++++++++++++++ .../service/DailyChallengeService.java | 14 -------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java index 46a1c42e..63c045c5 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeController.java @@ -8,7 +8,6 @@ import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeFacade; -import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService; import sopt.org.hmh.global.auth.UserId; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -19,7 +18,6 @@ public class DailyChallengeController implements DailyChallengeApi { private final DailyChallengeFacade dailyChallengeFacade; - private final DailyChallengeService dailyChallengeService; @Override @PostMapping("/finish") @@ -41,7 +39,7 @@ public ResponseEntity> orderChangeStatusDailyCha @RequestHeader("OS") final String os, @RequestBody final FinishedDailyChallengeStatusListRequest request ) { - dailyChallengeService.changeDailyChallengeStatusByIsSuccess(userId, request); + dailyChallengeFacade.changeDailyChallengeStatusByIsSuccess(userId, request); return ResponseEntity .status(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS, new EmptyJsonResponse())); diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index dea2c475..e6b85131 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -8,7 +8,9 @@ import sopt.org.hmh.domain.app.service.HistoryAppService; import sopt.org.hmh.domain.challenge.service.ChallengeService; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; +import sopt.org.hmh.domain.dailychallenge.domain.Status; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; import sopt.org.hmh.domain.user.service.UserService; @Service @@ -31,4 +33,17 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); }); } + + public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { + requests.finishedDailyChallenges().forEach(request -> { + DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); + if (request.isSuccess()) { + dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); + dailyChallenge.changeStatus(Status.UNEARNED); + } else { + dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE, Status.FAILURE)); + dailyChallenge.changeStatus(Status.FAILURE); + } + }); + } } 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 000e6646..2b9c9fbe 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 @@ -11,7 +11,6 @@ import sopt.org.hmh.domain.dailychallenge.domain.Status; import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeError; import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeException; -import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; import sopt.org.hmh.domain.dailychallenge.repository.DailyChallengeRepository; @Service @@ -55,19 +54,6 @@ private void handleAlreadyProcessedDailyChallenge(DailyChallenge dailyChallenge) throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED); } - public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { - requests.finishedDailyChallenges().forEach(request -> { - DailyChallenge dailyChallenge = this.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); - if (request.isSuccess()) { - this.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); - dailyChallenge.changeStatus(Status.UNEARNED); - } else { - this.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE, Status.FAILURE)); - dailyChallenge.changeStatus(Status.FAILURE); - } - }); - } - public void addDailyChallenge(Long userId, LocalDate startDate, Challenge challenge) { dailyChallengeRepository.saveAll(IntStream.range(0, challenge.getPeriod()) .mapToObj(i -> DailyChallenge.builder() From 2d770bc56ef65858c9d41641cf13f0928d4f9452 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:23:56 +0900 Subject: [PATCH 031/100] =?UTF-8?q?refactor=20-=20#122=20toEntity=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=9D=B4=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EA=B0=80=EB=8F=85=EC=84=B1=20=ED=96=A5?= =?UTF-8?q?=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/dto/request/SocialSignUpRequest.java | 25 ++++++++++++++++--- .../hmh/domain/user/service/UserService.java | 16 ++---------- 2 files changed, 24 insertions(+), 17 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 166c194d..1dcd82da 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 @@ -3,8 +3,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import java.util.List; import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.request.ChallengeSignUpRequest; +import sopt.org.hmh.domain.user.domain.OnboardingInfo; +import sopt.org.hmh.domain.user.domain.OnboardingProblem; import sopt.org.hmh.global.auth.social.SocialPlatform; public record SocialSignUpRequest( @@ -17,7 +20,23 @@ public record SocialSignUpRequest( @JsonProperty(value = "challenge") ChallengeSignUpRequest challengeSignUpRequest ) { - public ChallengeRequest toChallengeRequest() { - return new ChallengeRequest(challengeSignUpRequest.period(), challengeSignUpRequest.goalTime()); - } + + public ChallengeRequest toChallengeRequest() { + return new ChallengeRequest(challengeSignUpRequest.period(), challengeSignUpRequest.goalTime()); + } + + public OnboardingInfo toOnboardingInfo() { + return OnboardingInfo.builder() + .averageUseTime(onboardingRequest.averageUseTime()) + .build(); + } + + public List toProblemList(Long onboardingInfoId) { + return onboardingRequest.problemList().stream() + .map(problem -> OnboardingProblem.builder() + .onboardingInfoId(onboardingInfoId) + .problem(problem) + .build() + ).toList(); + } } \ No newline at end of file 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 54466c4d..a3a40cd9 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 @@ -1,7 +1,6 @@ package sopt.org.hmh.domain.user.service; import java.time.LocalDate; -import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -13,8 +12,6 @@ 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.user.domain.OnboardingInfo; -import sopt.org.hmh.domain.user.domain.OnboardingProblem; 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; @@ -75,17 +72,8 @@ private String validateName(String name) { } public void registerOnboardingInfo(SocialSignUpRequest request) { - OnboardingInfo onboardingInfo = OnboardingInfo.builder() - .averageUseTime(request.onboardingRequest().averageUseTime()) - .build(); - Long onboardingInfoId = onboardingInfoRepository.save(onboardingInfo).getId(); - - List problemList = request.onboardingRequest().problemList().stream() - .map(problem -> OnboardingProblem.builder() - .onboardingInfoId(onboardingInfoId) - .problem(problem).build()) - .toList(); - problemRepository.saveAll(problemList); + Long onboardingInfoId = onboardingInfoRepository.save(request.toOnboardingInfo()).getId(); + problemRepository.saveAll(request.toProblemList(onboardingInfoId)); } public User findBySocialPlatformAndSocialIdOrThrowException(SocialPlatform socialPlatform, String socialId) { From 376a540387412bbd11fcbac2137c6bf3eb004d11 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:27:43 +0900 Subject: [PATCH 032/100] =?UTF-8?q?refactor=20-=20#122=20userService=20?= =?UTF-8?q?=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EA=B4=80=EB=A6=AC?= 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, 3 insertions(+), 3 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 a3a40cd9..c04ae2f1 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 @@ -23,19 +23,18 @@ @Service @RequiredArgsConstructor -@Transactional(readOnly = true) public class UserService { private final UserRepository userRepository; private final OnboardingInfoRepository onboardingInfoRepository; private final ProblemRepository problemRepository; - @Transactional public void withdraw(Long userId) { this.findByIdOrThrowException(userId).softDelete(); } + @Transactional(readOnly = true) public UserInfoResponse getUserInfo(Long userId) { return UserInfoResponse.of(this.findByIdOrThrowException(userId)); } @@ -76,7 +75,7 @@ public void registerOnboardingInfo(SocialSignUpRequest request) { problemRepository.saveAll(request.toProblemList(onboardingInfoId)); } - public User findBySocialPlatformAndSocialIdOrThrowException(SocialPlatform socialPlatform, String socialId) { + private User findBySocialPlatformAndSocialIdOrThrowException(SocialPlatform socialPlatform, String socialId) { return userRepository.findBySocialPlatformAndSocialId(socialPlatform, socialId).orElseThrow( () -> new AuthException(AuthError.NOT_SIGNUP_USER)); } @@ -96,6 +95,7 @@ public void changeRecentLockDate(Long userId, LocalDate localDate) { this.findByIdOrThrowException(userId).changeRecentLockDate(localDate); } + @Transactional(readOnly = true) public IsLockTodayResponse checkIsTodayLock(Long userId, LocalDate lockCheckDate) { LocalDate userRecentLockDate = this.findByIdOrThrowException(userId).getRecentLockDate(); From b720f6e8a74324b38b0261fd157412342e1b9361 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:30:00 +0900 Subject: [PATCH 033/100] =?UTF-8?q?refactor=20-=20#122=20PointFacade=20?= =?UTF-8?q?=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/point/service/PointFacade.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java b/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java index a21ec8fc..0dbca3d2 100644 --- a/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java +++ b/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java @@ -18,13 +18,13 @@ @Service @RequiredArgsConstructor -@Transactional public class PointFacade { private final UserService userService; private final DailyChallengeService dailyChallengeService; private final ChallengeService challengeService; + @Transactional public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challengeDate) { DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); @@ -39,6 +39,7 @@ public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challe ); } + @Transactional public EarnPointResponse earnPointAndChallengeEarned(Long userId, LocalDate challengeDate) { DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); @@ -50,6 +51,7 @@ public EarnPointResponse earnPointAndChallengeEarned(Long userId, LocalDate chal return new EarnPointResponse(user.increasePoint(ChallengeConstants.EARNED_POINT)); } + @Transactional(readOnly = true) public ChallengePointStatusListResponse getChallengePointStatusList(Long userId) { User user = userService.findByIdOrThrowException(userId); Challenge challenge = challengeService.findByIdOrElseThrow(user.getCurrentChallengeId()); From 0aeb0fbddf31588b5f9dc93ff7d9c4007c12cf57 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:31:42 +0900 Subject: [PATCH 034/100] =?UTF-8?q?refactor=20-=20#122=20DailyChallengeCon?= =?UTF-8?q?troller=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dailychallenge/service/DailyChallengeFacade.java | 3 ++- .../domain/dailychallenge/service/DailyChallengeService.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index e6b85131..122b52fc 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -15,7 +15,6 @@ @Service @RequiredArgsConstructor -@Transactional public class DailyChallengeFacade { private final DailyChallengeService dailyChallengeService; @@ -23,6 +22,7 @@ public class DailyChallengeFacade { private final ChallengeService challengeService; private final UserService userService; + @Transactional public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequest requests, String os) { Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); List currentChallengeApps = challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); @@ -34,6 +34,7 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge }); } + @Transactional public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { requests.finishedDailyChallenges().forEach(request -> { DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); 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 2b9c9fbe..50a3ede8 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 @@ -15,7 +15,6 @@ @Service @RequiredArgsConstructor -@Transactional public class DailyChallengeService { private final DailyChallengeRepository dailyChallengeRepository; From 49808af8c4065c5c787d8763228cb1c6e3adb0ff Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:37:32 +0900 Subject: [PATCH 035/100] =?UTF-8?q?refactor=20-=20#122=20ChallengeControll?= =?UTF-8?q?er=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/controller/ChallengeController.java | 6 ++---- .../hmh/domain/challenge/service/ChallengeFacade.java | 10 ++++++++-- .../hmh/domain/challenge/service/ChallengeService.java | 1 - 3 files changed, 10 insertions(+), 7 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 7487ce03..4fcccc82 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 @@ -61,8 +61,7 @@ public ResponseEntity> orderGetDailyChallen public ResponseEntity> orderAddApps(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeAppArrayRequest requests) { - Challenge challenge = challengeFacade.findCurrentChallengeByUserId(userId); - challengeFacade.addApps(challenge, requests.apps(), os); + challengeFacade.addApps(userId, requests.apps(), os); return ResponseEntity .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) @@ -75,8 +74,7 @@ public ResponseEntity> orderAddApps(@UserId final Long userId, public ResponseEntity> orderRemoveApp(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final AppRemoveRequest request) { - Challenge challenge = challengeFacade.findCurrentChallengeByUserId(userId); - challengeFacade.removeApp(challenge, request.appCode(), os); + challengeFacade.removeApp(userId, request.appCode(), os); return ResponseEntity .status(AppSuccess.REMOVE_APP_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 c78ff61f..fadf76f0 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 @@ -53,6 +53,7 @@ private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId } } + @Transactional(readOnly = true) public ChallengeResponse getChallenge(Long userId) { Challenge challenge = this.findCurrentChallengeByUserId(userId); Integer todayIndex = this.calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod()); @@ -71,6 +72,7 @@ public ChallengeResponse getChallenge(Long userId) { .build(); } + @Transactional(readOnly = true) public DailyChallengeResponse getDailyChallenge(Long userId) { Challenge challenge = this.findCurrentChallengeByUserId(userId); @@ -91,11 +93,15 @@ private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) return (daysBetween >= period) ? -1 : daysBetween; } - public void addApps(Challenge challenge, List requests, String os) { + @Transactional + public void addApps(Long userId, List requests, String os) { + Challenge challenge = this.findCurrentChallengeByUserId(userId); challengeAppService.addApps(challenge, requests, os); } - public void removeApp(Challenge challenge, String appCode, String os) { + @Transactional + public void removeApp(Long userId, String appCode, String os) { + Challenge challenge = this.findCurrentChallengeByUserId(userId); challengeAppService.removeApp(challenge, appCode, os); } } \ No newline at end of file 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 3472f34c..bad6e8ff 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 @@ -16,7 +16,6 @@ public class ChallengeService { private final ChallengeRepository challengeRepository; - @Transactional public void deleteChallengeRelatedByUserId(List expiredUserIdList) { challengeRepository.deleteByUserIdIn(expiredUserIdList); } From 1a1d46ab885e4e922f507da4422e79f7ed16d8e3 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:37:49 +0900 Subject: [PATCH 036/100] =?UTF-8?q?refactor=20-=20#122=20ExpiredUserDelete?= =?UTF-8?q?Scheduler=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java b/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java index 578445b3..055fa30f 100644 --- a/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java +++ b/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java @@ -11,13 +11,13 @@ @Component @RequiredArgsConstructor -@Transactional public class ExpiredUserDeleteScheduler { private final UserRepository userRepository; private final ChallengeService challengeService; @Scheduled(cron = "0 0 4 * * ?") + @Transactional public void deleteExpiredUser() { deleteExpiredUser(LocalDateTime.now()); } From bd6a6747c65d2ab23c028afb1d5ad2060558e14b Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:40:18 +0900 Subject: [PATCH 037/100] =?UTF-8?q?refactor=20-=20#122=20AuthService?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20Tra?= =?UTF-8?q?nsactional=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/auth/service/AuthService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java b/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java index 00ecd938..46ce65a9 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java +++ b/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java @@ -22,7 +22,6 @@ @Service @RequiredArgsConstructor -@Transactional(readOnly = true) public class AuthService { private final KakaoLoginService kakaoLoginService; @@ -33,7 +32,7 @@ public class AuthService { private final TokenService tokenService; private final UserService userService; - @Transactional + @Transactional(readOnly = true) public LoginResponse login(String socialAccessToken, SocialPlatformRequest request) { SocialPlatform socialPlatform = request.socialPlatform(); From e509d2573a2a6b7ebe0f3af93101560c82c276a3 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:40:42 +0900 Subject: [PATCH 038/100] =?UTF-8?q?refactor=20-=20#122=20AppService?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20Tra?= =?UTF-8?q?nsactional=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/hmh/domain/app/service/ChallengeAppService.java | 2 -- .../java/sopt/org/hmh/domain/app/service/HistoryAppService.java | 2 -- 2 files changed, 4 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 771f3fa3..366272f4 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 @@ -3,7 +3,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; 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; @@ -13,7 +12,6 @@ @Service @RequiredArgsConstructor -@Transactional public class ChallengeAppService { private final ChallengeAppRepository challengeAppRepository; diff --git a/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java b/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java index ca7a17eb..c4a79d9a 100644 --- a/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java +++ b/src/main/java/sopt/org/hmh/domain/app/service/HistoryAppService.java @@ -3,7 +3,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.app.domain.HistoryApp; import sopt.org.hmh.domain.app.domain.exception.AppError; @@ -14,7 +13,6 @@ @Service @RequiredArgsConstructor -@Transactional public class HistoryAppService { private final HistoryAppRepository historyAppRepository; From a7accadd7af3e1215d9fc71825c9ec7094d075f4 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 00:43:11 +0900 Subject: [PATCH 039/100] =?UTF-8?q?refactor=20-=20#122=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20of=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java | 2 +- src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java index dceb8aba..a1933e0f 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java @@ -11,7 +11,7 @@ public class JwtProvider { private final JwtGenerator jwtGenerator; public TokenResponse issueToken(Long userId) { - return TokenResponse.of(jwtGenerator.generateToken(userId, false), + return new TokenResponse(jwtGenerator.generateToken(userId, false), jwtGenerator.generateToken(userId, true)); } diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java index d23e0086..a0751843 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java @@ -4,7 +4,4 @@ public record TokenResponse( String accessToken, String refreshToken ) { - public static TokenResponse of(String accessToken, String refreshToken) { - return new TokenResponse(accessToken, refreshToken); - } } \ No newline at end of file From 29ed909f8167eab56bb522d832bc14c16888be6d Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 02:26:53 +0900 Subject: [PATCH 040/100] =?UTF-8?q?refactor=20-=20#122=20Domain=20sql=20?= =?UTF-8?q?=EB=82=B4=EB=B6=80=20nullable=20=EC=97=AC=EB=B6=80=20=EB=AA=85?= =?UTF-8?q?=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/domain/app/domain/App.java | 3 +++ .../java/sopt/org/hmh/domain/app/domain/ChallengeApp.java | 1 + src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java | 3 +++ .../java/sopt/org/hmh/domain/challenge/domain/Challenge.java | 5 +++++ .../org/hmh/domain/dailychallenge/domain/DailyChallenge.java | 4 ++++ 5 files changed, 16 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/App.java b/src/main/java/sopt/org/hmh/domain/app/domain/App.java index 87212392..70f01a46 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/App.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/App.java @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.app.domain; +import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -14,7 +15,9 @@ public abstract class App { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(nullable = false) protected String os; + @Column(nullable = false) protected String appCode; } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java b/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java index 4e10f79e..5471a06e 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java @@ -16,6 +16,7 @@ public class ChallengeApp extends App { @JoinColumn(name = "challenge_id") private Challenge challenge; + @Column(nullable = false) private Long goalTime; @Builder diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java b/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java index 8425641d..eaa0e03b 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java @@ -16,7 +16,10 @@ public class HistoryApp extends App { @JoinColumn(name = "daily_challenge_id") private DailyChallenge dailyChallenge; + @Column(nullable = false) private Long usageTime; + + @Column(nullable = false) private Long goalTime; @Builder diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java index a4ab2e9e..4ce7044a 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java @@ -22,8 +22,13 @@ public class Challenge extends BaseTimeEntity { @GeneratedValue(strategy = IDENTITY) private Long id; + @Column(nullable = false) private Long userId; + + @Column(nullable = false) private Integer period; + + @Column(nullable = false) private Long goalTime; @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java index 440c92ac..edaa192a 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java @@ -31,12 +31,16 @@ public class DailyChallenge extends BaseTimeEntity { private List apps; @Enumerated(EnumType.STRING) + @Column(nullable = false) private Status status; + @Column(nullable = false) private Long userId; + @Column(nullable = false) private Long goalTime; + @Column(nullable = false) private LocalDate challengeDate; @Builder From 4893720eede48e83307916f8b18b3f59668ad1cc Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 02:37:48 +0900 Subject: [PATCH 041/100] =?UTF-8?q?refactor=20-=20#122=20Domain=20?= =?UTF-8?q?=EB=82=B4=EB=B6=80=20@NotNull=20=EC=A0=9C=EC=95=BD=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20validation?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/app/domain/App.java | 5 +++-- .../org/hmh/domain/app/domain/ChallengeApp.java | 3 ++- .../org/hmh/domain/app/domain/HistoryApp.java | 5 +++-- .../hmh/domain/challenge/domain/Challenge.java | 7 ++++--- .../dailychallenge/domain/DailyChallenge.java | 15 ++++++--------- .../sopt/org/hmh/domain/user/domain/User.java | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/App.java b/src/main/java/sopt/org/hmh/domain/app/domain/App.java index 70f01a46..4a3b5fca 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/App.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/App.java @@ -5,6 +5,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import jakarta.validation.constraints.NotNull; import lombok.Getter; @Getter @@ -15,9 +16,9 @@ public abstract class App { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false) + @NotNull(message = "os는 null일 수 없습니다.") protected String os; - @Column(nullable = false) + @NotNull(message = "appCode는 null일 수 없습니다.") protected String appCode; } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java b/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java index 5471a06e..3534a27c 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/ChallengeApp.java @@ -1,6 +1,7 @@ package sopt.org.hmh.domain.app.domain; import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -16,7 +17,7 @@ public class ChallengeApp extends App { @JoinColumn(name = "challenge_id") private Challenge challenge; - @Column(nullable = false) + @NotNull(message = "목표 시간은 null일 수 없습니다.") private Long goalTime; @Builder diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java b/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java index eaa0e03b..addda272 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/HistoryApp.java @@ -1,6 +1,7 @@ package sopt.org.hmh.domain.app.domain; import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -16,10 +17,10 @@ public class HistoryApp extends App { @JoinColumn(name = "daily_challenge_id") private DailyChallenge dailyChallenge; - @Column(nullable = false) + @NotNull(message = "사용 시간은 null일 수 없습니다.") private Long usageTime; - @Column(nullable = false) + @NotNull(message = "목표 시간은 null일 수 없습니다.") private Long goalTime; @Builder diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java index 4ce7044a..8723cd05 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java @@ -3,6 +3,7 @@ import static jakarta.persistence.GenerationType.*; import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -22,13 +23,13 @@ public class Challenge extends BaseTimeEntity { @GeneratedValue(strategy = IDENTITY) private Long id; - @Column(nullable = false) + @NotNull(message = "유저 아이디는 null일 수 없습니다.") private Long userId; - @Column(nullable = false) + @NotNull(message = "챌린지 기간은 null일 수 없습니다.") private Integer period; - @Column(nullable = false) + @NotNull(message = "목표 시간은 null일 수 없습니다.") private Long goalTime; @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java index edaa192a..d62ac340 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java @@ -3,6 +3,7 @@ import static jakarta.persistence.GenerationType.*; import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import java.time.LocalDate; import lombok.AccessLevel; import lombok.Builder; @@ -25,31 +26,27 @@ public class DailyChallenge extends BaseTimeEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "challenge_id") + @NotNull(message = "챌린지는 null일 수 없습니다.") private Challenge challenge; @OneToMany(mappedBy = "dailyChallenge", cascade = CascadeType.REMOVE, orphanRemoval = true) private List apps; @Enumerated(EnumType.STRING) - @Column(nullable = false) + @NotNull(message = "status값은 null일 수 없습니다.") private Status status; - @Column(nullable = false) + @NotNull(message = "유저 아이디는 null일 수 없습니다.") private Long userId; - @Column(nullable = false) + @NotNull(message = "목표 시간은 null일 수 없습니다.") private Long goalTime; - @Column(nullable = false) + @NotNull(message = "챌린지 날짜는 null일 수 없습니다.") private LocalDate challengeDate; @Builder DailyChallenge(Challenge challenge, Long userId, Long goalTime, LocalDate challengeDate) { - Assert.notNull(challenge, "Challenge must not be null"); - Assert.notNull(userId, "UserId must not be null"); - Assert.notNull(goalTime, "GoalTime must not be null"); - Assert.notNull(challengeDate, "ChallengeDate must not be null"); - this.challenge = challenge; this.userId = userId; this.goalTime = goalTime; diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/User.java b/src/main/java/sopt/org/hmh/domain/user/domain/User.java index 0423f5c2..f19f3978 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/User.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/User.java @@ -11,6 +11,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import java.time.LocalDate; import java.time.LocalDateTime; import lombok.AccessLevel; @@ -32,13 +33,12 @@ public class User extends BaseTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false) private String name; private Long currentChallengeId; @Enumerated(EnumType.STRING) - @Column(nullable = false) + @NotNull(message = "소셜 플랫폼은 null일 수 없습니다.") private SocialPlatform socialPlatform; @Column(unique = true) From 43543898a93f43d5f453cb9dc31aaf0ae06383ac Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 02:39:38 +0900 Subject: [PATCH 042/100] =?UTF-8?q?refactor=20-=20#122=20nickname=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=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/domain/User.java | 3 ++- .../hmh/global/auth/social/kakao/fegin/KakaoLoginService.java | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/User.java b/src/main/java/sopt/org/hmh/domain/user/domain/User.java index f19f3978..0ed66780 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/User.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/User.java @@ -45,6 +45,7 @@ public class User extends BaseTimeEntity { private String socialId; @Min(value = 0) + @NotNull(message = "포인트는 기본 값이 설정되어야 합니다.") private Integer point; private LocalDate recentLockDate; @@ -60,7 +61,7 @@ public User(SocialPlatform socialPlatform, String socialId, String name) { this.point = UserConstants.INITIAL_POINT; } - public void updateSocialInfo(String nickname) { + public void updateNickname(String nickname) { this.name = nickname; } diff --git a/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java b/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java index af480f48..8311b6e8 100644 --- a/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java +++ b/src/main/java/sopt/org/hmh/global/auth/social/kakao/fegin/KakaoLoginService.java @@ -5,7 +5,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.global.auth.jwt.exception.JwtError; import sopt.org.hmh.global.auth.jwt.exception.JwtException; @@ -36,7 +35,7 @@ public void updateUserInfoByKakao(User loginUser, final String socialAccessToken KakaoUserResponse userRequest = getKakaoUserRequest(socialAccessToken); try { - loginUser.updateSocialInfo(userRequest.kakaoAccount().profile().nickname()); + loginUser.updateNickname(userRequest.kakaoAccount().profile().nickname()); } catch (NullPointerException exception) { throw new JwtException(JwtError.INVALID_SOCIAL_ACCESS_TOKEN_FORMAT); } From 89edffc8ae0fd0122ac3fc740c0d2b1d1d176e8c Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 02:43:16 +0900 Subject: [PATCH 043/100] =?UTF-8?q?refactor=20-=20#122=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=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 --- src/main/java/sopt/org/hmh/domain/app/domain/App.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/app/domain/App.java b/src/main/java/sopt/org/hmh/domain/app/domain/App.java index 4a3b5fca..a4731b54 100644 --- a/src/main/java/sopt/org/hmh/domain/app/domain/App.java +++ b/src/main/java/sopt/org/hmh/domain/app/domain/App.java @@ -1,6 +1,5 @@ package sopt.org.hmh.domain.app.domain; -import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; From 72deb6b8829b4d8cee2c648ca07858197ce96371 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 02:43:28 +0900 Subject: [PATCH 044/100] =?UTF-8?q?refactor=20-=20#122=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/challenge/domain/Challenge.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java b/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java index 8723cd05..a33a1f61 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/domain/Challenge.java @@ -33,10 +33,10 @@ public class Challenge extends BaseTimeEntity { private Long goalTime; @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true) - private List apps = new ArrayList<>(); + private List apps; @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true) - private final List historyDailyChallenges = new ArrayList<>(); + private List historyDailyChallenges; @Builder private Challenge(Integer period, Long userId, Long goalTime, List apps) { From d6f60aa81bbf73ee55b81eb2ab108d8353b86cc9 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:19:17 +0900 Subject: [PATCH 045/100] =?UTF-8?q?refactor=20-=20#122=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=B3=80=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/hmh/domain/challenge/service/ChallengeFacade.java | 3 +-- 1 file changed, 1 insertion(+), 2 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 fadf76f0..b8158b16 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 @@ -56,7 +56,6 @@ private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId @Transactional(readOnly = true) public ChallengeResponse getChallenge(Long userId) { Challenge challenge = this.findCurrentChallengeByUserId(userId); - Integer todayIndex = this.calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod()); return ChallengeResponse.builder() .period(challenge.getPeriod()) @@ -64,7 +63,7 @@ public ChallengeResponse getChallenge(Long userId) { .stream() .map(DailyChallenge::getStatus) .toList()) - .todayIndex(todayIndex) + .todayIndex(this.calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod())) .startDate(challenge.getCreatedAt().toLocalDate().toString()) .goalTime(challenge.getGoalTime()) .apps(challenge.getApps().stream() From 56df3039c7968709434a781eb24ac58995b39e3d Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:19:32 +0900 Subject: [PATCH 046/100] =?UTF-8?q?refactor=20-=20#122=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=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 --- .../sopt/org/hmh/domain/challenge/service/ChallengeService.java | 2 -- 1 file changed, 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 bad6e8ff..569a4684 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 @@ -3,7 +3,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; @@ -32,5 +31,4 @@ public List getCurrentChallengeAppByChallengeId(Long challengeId) public Challenge save(Challenge challenge) { return challengeRepository.save(challenge); } - } From 08af31c86596d0bc102fe03cd7ef4d0aeabde8fa Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:19:58 +0900 Subject: [PATCH 047/100] =?UTF-8?q?refactor=20-=20#122=20cotains=EB=A5=BC?= =?UTF-8?q?=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20=ED=95=A8=EC=88=98=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 --- .../dailychallenge/service/DailyChallengeService.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) 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 50a3ede8..7062cae1 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 @@ -5,7 +5,6 @@ import java.util.stream.IntStream; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; import sopt.org.hmh.domain.dailychallenge.domain.Status; @@ -25,15 +24,7 @@ public DailyChallenge findByChallengeDateAndUserIdOrThrowException(LocalDate cha } public void validateDailyChallengeStatus(Status dailyChallengeStatus, List expectedStatuses) { - boolean isAlreadyProcessed = true; - for (Status expected : expectedStatuses) { - if (dailyChallengeStatus == expected) { - isAlreadyProcessed = false; - break; - } - } - - if (isAlreadyProcessed) { + if (!expectedStatuses.contains(dailyChallengeStatus)) { throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED); } } From 78a12bfa649eced625d54d5c53ac7fd266795456 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:20:20 +0900 Subject: [PATCH 048/100] =?UTF-8?q?refactor=20-=20#122=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20of=20=ED=95=A8=EC=88=98=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 --- .../org/hmh/domain/auth/dto/response/LoginResponse.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/dto/response/LoginResponse.java b/src/main/java/sopt/org/hmh/domain/auth/dto/response/LoginResponse.java index e3049c57..e5c16e3c 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/dto/response/LoginResponse.java +++ b/src/main/java/sopt/org/hmh/domain/auth/dto/response/LoginResponse.java @@ -1,7 +1,6 @@ package sopt.org.hmh.domain.auth.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; -import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.global.auth.jwt.TokenResponse; public record LoginResponse( @@ -9,12 +8,4 @@ public record LoginResponse( @JsonProperty(value = "token") TokenResponse tokenResponse ){ - - public static LoginResponse of(User loginUser, TokenResponse tokenResponse) { - return new LoginResponse( - loginUser.getId(), - tokenResponse - ); - } - } \ No newline at end of file From ce890e11f3b187f14c5cea43cc08a1718bbe181e Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:21:00 +0900 Subject: [PATCH 049/100] =?UTF-8?q?refactor=20-=20#122=20=EC=98=A8?= =?UTF-8?q?=EB=B3=B4=EB=94=A9=20=EC=A0=95=EB=B3=B4=20domain=EC=97=90=20Not?= =?UTF-8?q?Null=20=EC=A0=9C=EC=95=BD=20=EC=A1=B0=EA=B1=B4=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 --- .../java/sopt/org/hmh/domain/user/domain/OnboardingInfo.java | 4 ++++ .../sopt/org/hmh/domain/user/domain/OnboardingProblem.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingInfo.java b/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingInfo.java index 08db01bb..4fbb39a9 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingInfo.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingInfo.java @@ -4,6 +4,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -18,7 +19,10 @@ public class OnboardingInfo { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @NotNull(message = "평균 사용 시간은 null일 수 없습니다.") private String averageUseTime; + + @NotNull(message = "유저 아이디는 null일 수 없습니다.") private Long userId; @Builder diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingProblem.java b/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingProblem.java index 5220bd5b..81844d1c 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingProblem.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/OnboardingProblem.java @@ -5,6 +5,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -20,7 +21,9 @@ public class OnboardingProblem { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @NotNull(message = "온보딩 정보 아이디는 null일 수 없습니다.") private Long onboardingInfoId; + @NotNull(message = "문제 항목은 null일 수 없습니다.") private String problem; @Builder From dc904c71b75826b0639f39dead32dafa181df2be Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:21:59 +0900 Subject: [PATCH 050/100] =?UTF-8?q?refactor=20-=20#122=20validate=20?= =?UTF-8?q?=EB=8B=A8=EC=88=9C=ED=99=94=20=EB=B0=8F=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=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/user/service/UserService.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 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 c04ae2f1..12e2bfa9 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 @@ -70,8 +70,8 @@ private String validateName(String name) { return name; } - public void registerOnboardingInfo(SocialSignUpRequest request) { - Long onboardingInfoId = onboardingInfoRepository.save(request.toOnboardingInfo()).getId(); + public void registerOnboardingInfo(SocialSignUpRequest request, Long userId) { + Long onboardingInfoId = onboardingInfoRepository.save(request.toOnboardingInfo(userId)).getId(); problemRepository.saveAll(request.toProblemList(onboardingInfoId)); } @@ -91,18 +91,13 @@ public Long getCurrentChallengeIdByUserId(Long userId) { } @Transactional - public void changeRecentLockDate(Long userId, LocalDate localDate) { - this.findByIdOrThrowException(userId).changeRecentLockDate(localDate); + public void changeRecentLockDate(Long userId, LocalDate lockDate) { + this.findByIdOrThrowException(userId).changeRecentLockDate(lockDate); } @Transactional(readOnly = true) public IsLockTodayResponse checkIsTodayLock(Long userId, LocalDate lockCheckDate) { LocalDate userRecentLockDate = this.findByIdOrThrowException(userId).getRecentLockDate(); - - if (userRecentLockDate == null) { - return new IsLockTodayResponse(false); - } - - return new IsLockTodayResponse(userRecentLockDate.equals(lockCheckDate)); + return new IsLockTodayResponse(lockCheckDate.equals(userRecentLockDate)); } } \ No newline at end of file From 195ce2357c924c6d7371eb26c49a37a037f1d71a Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:22:15 +0900 Subject: [PATCH 051/100] =?UTF-8?q?refactor=20-=20#122=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=EB=90=9C=20userId=20=ED=95=84=EB=93=9C=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 --- .../org/hmh/domain/auth/dto/request/SocialSignUpRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 1dcd82da..dc399a22 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 @@ -25,9 +25,10 @@ public ChallengeRequest toChallengeRequest() { return new ChallengeRequest(challengeSignUpRequest.period(), challengeSignUpRequest.goalTime()); } - public OnboardingInfo toOnboardingInfo() { + public OnboardingInfo toOnboardingInfo(Long userId) { return OnboardingInfo.builder() .averageUseTime(onboardingRequest.averageUseTime()) + .userId(userId) .build(); } From abdcc8d027fd79350134292ab2ed02ecea401ee2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:23:08 +0900 Subject: [PATCH 052/100] =?UTF-8?q?refactor=20-=20#122=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20userService=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=ED=98=B8=EC=B6=9C=20=EC=A4=84=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/point/service/PointFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java b/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java index 0dbca3d2..295caa80 100644 --- a/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java +++ b/src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java @@ -62,7 +62,7 @@ public ChallengePointStatusListResponse getChallengePointStatusList(Long userId) dailyChallenge.getStatus())).toList(); return new ChallengePointStatusListResponse( - userService.getUserInfo(userId).point(), + user.getPoint(), challenge.getPeriod(), challengePointStatusResponseList ); From db0b82be0a36631c9b8d509c98005cd08bbf837a Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:24:49 +0900 Subject: [PATCH 053/100] =?UTF-8?q?refactor=20-=20#122=20AuthFacade=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthController.java | 12 +++++------ .../{AuthService.java => AuthFacade.java} | 21 +++++++------------ 2 files changed, 14 insertions(+), 19 deletions(-) rename src/main/java/sopt/org/hmh/domain/auth/service/{AuthService.java => AuthFacade.java} (86%) 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 792bdbc9..29eacd95 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 @@ -13,7 +13,7 @@ import sopt.org.hmh.domain.auth.exception.AuthSuccess; import sopt.org.hmh.domain.auth.dto.request.SocialPlatformRequest; import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest; -import sopt.org.hmh.domain.auth.service.AuthService; +import sopt.org.hmh.domain.auth.service.AuthFacade; import sopt.org.hmh.global.auth.social.SocialAccessTokenResponse; import sopt.org.hmh.global.common.response.BaseResponse; @@ -22,7 +22,7 @@ @RequestMapping("/api/v1/user") public class AuthController implements AuthApi { - private final AuthService authService; + private final AuthFacade authFacade; @PostMapping("/login") @Override @@ -32,7 +32,7 @@ public ResponseEntity> orderLogin( ) { return ResponseEntity .status(AuthSuccess.LOGIN_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.LOGIN_SUCCESS, authService.login(socialAccessToken, request))); + .body(BaseResponse.success(AuthSuccess.LOGIN_SUCCESS, authFacade.login(socialAccessToken, request))); } @PostMapping("/signup") @@ -44,7 +44,7 @@ public ResponseEntity> orderSignup( ) { return ResponseEntity .status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.SIGNUP_SUCCESS, authService.signup(socialAccessToken, request, os))); + .body(BaseResponse.success(AuthSuccess.SIGNUP_SUCCESS, authFacade.signup(socialAccessToken, request, os))); } @PostMapping("/reissue") @@ -54,7 +54,7 @@ public ResponseEntity> orderReissue( ) { return ResponseEntity .status(AuthSuccess.REISSUE_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.REISSUE_SUCCESS, authService.reissueToken(refreshToken))); + .body(BaseResponse.success(AuthSuccess.REISSUE_SUCCESS, authFacade.reissueToken(refreshToken))); } @GetMapping("/social/token/kakao") @@ -63,6 +63,6 @@ public ResponseEntity> orderGetKakaoAcce ) { return ResponseEntity .status(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS, authService.getSocialAccessTokenByAuthorizationCode(code))); + .body(BaseResponse.success(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS, authFacade.getSocialAccessTokenByAuthorizationCode(code))); } } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java b/src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java similarity index 86% rename from src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java rename to src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java index 46ce65a9..c4bcbab0 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/service/AuthService.java +++ b/src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java @@ -22,7 +22,7 @@ @Service @RequiredArgsConstructor -public class AuthService { +public class AuthFacade { private final KakaoLoginService kakaoLoginService; private final AppleOAuthProvider appleOAuthProvider; @@ -34,10 +34,8 @@ public class AuthService { @Transactional(readOnly = true) public LoginResponse login(String socialAccessToken, SocialPlatformRequest request) { - SocialPlatform socialPlatform = request.socialPlatform(); - String socialId = getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken); - + String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken); User loginUser = userService.getUserBySocialPlatformAndSocialId(socialPlatform, socialId); return performLogin(socialAccessToken, socialPlatform, loginUser); @@ -45,18 +43,16 @@ public LoginResponse login(String socialAccessToken, SocialPlatformRequest reque @Transactional public LoginResponse signup(String socialAccessToken, SocialSignUpRequest request, String os) { - SocialPlatform socialPlatform = request.socialPlatform(); - String socialId = getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken); + 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); - Challenge challenge = challengeFacade.addChallenge(user.getId(), request.toChallengeRequest() , os); + Challenge challenge = challengeFacade.addChallenge(userId, request.toChallengeRequest() , os); challengeAppService.addApps(challenge, request.challengeSignUpRequest().apps(), os); - - userService.registerOnboardingInfo(request); return performLogin(socialAccessToken, socialPlatform, user); } @@ -73,16 +69,15 @@ public ReissueResponse reissueToken(String refreshToken) { return tokenService.reissueToken(refreshToken); } - private LoginResponse performLogin(String socialAccessToken, SocialPlatform socialPlatform, User loginUser) { if (socialPlatform == SocialPlatform.KAKAO) { kakaoLoginService.updateUserInfoByKakao(loginUser, socialAccessToken); } - return LoginResponse.of(loginUser, tokenService.issueToken(loginUser.getId())); + Long userId = loginUser.getId(); + return new LoginResponse(userId, tokenService.issueToken(userId)); } public SocialAccessTokenResponse getSocialAccessTokenByAuthorizationCode(String code) { return kakaoLoginService.getKakaoAccessToken(code); } - } \ No newline at end of file From 6c3eb8db04275daa8de81043eccbf060a9f81f94 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:34:04 +0900 Subject: [PATCH 054/100] =?UTF-8?q?refactor=20-=20#122=20Optinal=EC=9D=84?= =?UTF-8?q?=20=EC=9D=B4=EC=9A=A9=ED=95=B4=20null=EB=A1=9C=EB=B6=80?= =?UTF-8?q?=ED=84=B0=20=EC=95=88=EC=A0=84=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 --- .../challenge/service/ChallengeFacade.java | 16 +++++++++------- 1 file changed, 9 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 b8158b16..eb8d7615 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,5 +1,6 @@ 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,21 +32,22 @@ public class ChallengeFacade { @Transactional public Challenge addChallenge(Long userId, ChallengeRequest challengeRequest, String os) { - Challenge challenge = challengeService.save(challengeRequest.toEntity(userId)); - LocalDate startDate = challenge.getCreatedAt().toLocalDate(); - User user = userService.findByIdOrThrowException(userId); - this.addAppsIfPreviousChallengeExist(os, user.getCurrentChallengeId(), challenge); + Optional previousChallengeId = Optional.of(user.getCurrentChallengeId()); + + Challenge challenge = challengeService.save(challengeRequest.toEntity(userId)); user.changeCurrentChallengeId(challenge.getId()); + LocalDate startDate = challenge.getCreatedAt().toLocalDate(); dailyChallengeService.addDailyChallenge(userId, startDate, challenge); + this.addAppsIfPreviousChallengeExist(os, previousChallengeId, challenge); return challenge; } - private void addAppsIfPreviousChallengeExist(String os, Long previousChallengeId, Challenge challenge) { - if (previousChallengeId != null) { - Challenge previousChallenge = challengeService.findByIdOrElseThrow(previousChallengeId); + 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(); From 00425ac315820e65c42458dc44f12c67c02d8b34 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:49:47 +0900 Subject: [PATCH 055/100] =?UTF-8?q?refactor=20-=20#122=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=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 | 3 +-- .../sopt/org/hmh/domain/challenge/service/ChallengeFacade.java | 2 +- 2 files changed, 2 insertions(+), 3 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 4fcccc82..c26283ba 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 @@ -7,7 +7,6 @@ import sopt.org.hmh.domain.app.domain.exception.AppSuccess; import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; -import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeSuccess; import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; @@ -43,7 +42,7 @@ public ResponseEntity> orderGetChallenge(@UserId return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, - challengeFacade.getChallenge(userId))); + challengeFacade.getCurrentChallengeInfo(userId))); } @GetMapping("/home") 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 eb8d7615..7229cb3a 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 @@ -56,7 +56,7 @@ private void addAppsIfPreviousChallengeExist(String os, Optional previousC } @Transactional(readOnly = true) - public ChallengeResponse getChallenge(Long userId) { + public ChallengeResponse getCurrentChallengeInfo(Long userId) { Challenge challenge = this.findCurrentChallengeByUserId(userId); return ChallengeResponse.builder() From d4eb82ab3f9504b7dbf8ead36bf479d017a64521 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 03:59:33 +0900 Subject: [PATCH 056/100] =?UTF-8?q?refactor=20-=20#122=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=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 +- .../sopt/org/hmh/domain/challenge/service/ChallengeFacade.java | 2 +- 2 files changed, 2 insertions(+), 2 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 c26283ba..a640249b 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 @@ -52,7 +52,7 @@ public ResponseEntity> orderGetDailyChallen return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, - challengeFacade.getDailyChallenge(userId))); + challengeFacade.getDailyChallengeInfo(userId))); } @PostMapping("/app") 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 7229cb3a..cbe31915 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 @@ -74,7 +74,7 @@ public ChallengeResponse getCurrentChallengeInfo(Long userId) { } @Transactional(readOnly = true) - public DailyChallengeResponse getDailyChallenge(Long userId) { + public DailyChallengeResponse getDailyChallengeInfo(Long userId) { Challenge challenge = this.findCurrentChallengeByUserId(userId); return DailyChallengeResponse.builder() From d71231586b6cc7ee00dc2be7d79a03066f2e52e6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 19 Jun 2024 04:06:48 +0900 Subject: [PATCH 057/100] =?UTF-8?q?refactor=20-=20#122=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/auth/service/AuthFacade.java | 1 - .../hmh/domain/challenge/controller/ChallengeController.java | 4 ++-- .../org/hmh/domain/challenge/service/ChallengeFacade.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) 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 c4bcbab0..fbc2725a 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 @@ -26,7 +26,6 @@ public class AuthFacade { private final KakaoLoginService kakaoLoginService; private final AppleOAuthProvider appleOAuthProvider; - private final ChallengeFacade challengeFacade; private final ChallengeAppService challengeAppService; private final TokenService tokenService; 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 a640249b..6dd9f363 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 @@ -60,7 +60,7 @@ public ResponseEntity> orderGetDailyChallen public ResponseEntity> orderAddApps(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeAppArrayRequest requests) { - challengeFacade.addApps(userId, requests.apps(), os); + challengeFacade.addAppsToCurrentChallenge(userId, requests.apps(), os); return ResponseEntity .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) @@ -73,7 +73,7 @@ public ResponseEntity> orderAddApps(@UserId final Long userId, public ResponseEntity> orderRemoveApp(@UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final AppRemoveRequest request) { - challengeFacade.removeApp(userId, request.appCode(), os); + challengeFacade.removeAppFromCurrentChallenge(userId, request.appCode(), os); return ResponseEntity .status(AppSuccess.REMOVE_APP_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 cbe31915..f49bbbc7 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 @@ -95,13 +95,13 @@ private Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) } @Transactional - public void addApps(Long userId, List requests, String os) { + public void addAppsToCurrentChallenge(Long userId, List requests, String os) { Challenge challenge = this.findCurrentChallengeByUserId(userId); challengeAppService.addApps(challenge, requests, os); } @Transactional - public void removeApp(Long userId, String appCode, String os) { + public void removeAppFromCurrentChallenge(Long userId, String appCode, String os) { Challenge challenge = this.findCurrentChallengeByUserId(userId); challengeAppService.removeApp(challenge, appCode, os); } From 0a832ae5c0c089060e469617b687aa8d8cdc1192 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 4 Jul 2024 23:26:53 +0900 Subject: [PATCH 058/100] =?UTF-8?q?feat=20-=20#171=20AdminController=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20orderAdminLogin=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 --- .../hmh/domain/admin/controller/AdminApi.java | 11 +++++++ .../admin/controller/AdminController.java | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java create mode 100644 src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java new file mode 100644 index 00000000..ac863117 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -0,0 +1,11 @@ +package sopt.org.hmh.domain.admin.controller; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.http.ResponseEntity; +import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; +import sopt.org.hmh.global.common.response.BaseResponse; + +public interface AdminApi { + @Operation(summary = "소셜 로그인") + ResponseEntity> orderAdminLogin(AdminLoginRequest request); +} diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java new file mode 100644 index 00000000..5bdaae4e --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -0,0 +1,29 @@ +package sopt.org.hmh.domain.admin.controller; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; +import sopt.org.hmh.domain.admin.exception.AdminSuccess; +import sopt.org.hmh.domain.admin.service.AdminFacade; +import sopt.org.hmh.global.common.response.BaseResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/admin") +public class AdminController implements AdminApi{ + @Override + @PostMapping("/login") + public ResponseEntity> orderAdminLogin( + @RequestBody @Valid final AdminLoginRequest request) + { + return ResponseEntity + .status(AdminSuccess.ADMIN_LOGIN_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AdminSuccess.ADMIN_LOGIN_SUCCESS, AdminFacade.adminLogin(request.authCode()))); + } + +} From be36779d042031becab1207636c76abb39863cb4 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 4 Jul 2024 23:27:15 +0900 Subject: [PATCH 059/100] =?UTF-8?q?feat=20-=20#171=20Admin=20exception=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/admin/exception/AdminError.java | 31 +++++++++++++++++++ .../admin/exception/AdminException.java | 11 +++++++ .../domain/admin/exception/AdminSuccess.java | 31 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java create mode 100644 src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java create mode 100644 src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java new file mode 100644 index 00000000..c078a957 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java @@ -0,0 +1,31 @@ +package sopt.org.hmh.domain.admin.exception; + +import lombok.AllArgsConstructor; +import org.springframework.http.HttpStatus; +import sopt.org.hmh.global.common.exception.base.ErrorBase; + +@AllArgsConstructor +public enum AdminError implements ErrorBase { + + // 401 UNAUTHORIZED + INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."), + ; + + private final HttpStatus status; + private final String errorMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getErrorMessage() { + return this.errorMessage; + } +} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java new file mode 100644 index 00000000..0a54ebeb --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java @@ -0,0 +1,11 @@ +package sopt.org.hmh.domain.admin.exception; + +import sopt.org.hmh.domain.auth.exception.AuthError; +import sopt.org.hmh.global.common.exception.base.ExceptionBase; + +public class AdminException extends ExceptionBase { + + public AdminException(AuthError errorBase) { + super(errorBase); + } +} diff --git a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java new file mode 100644 index 00000000..147dcd22 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java @@ -0,0 +1,31 @@ +package sopt.org.hmh.domain.admin.exception; + +import lombok.AllArgsConstructor; +import org.springframework.http.HttpStatus; +import sopt.org.hmh.global.common.exception.base.SuccessBase; + +@AllArgsConstructor +public enum AdminSuccess implements SuccessBase { + + // 200 OK + ADMIN_LOGIN_SUCCESS(HttpStatus.OK, "관리자 로그인에 성공했습니다."), + ; + + private final HttpStatus status; + private final String successMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getSuccessMessage() { + return this.successMessage; + } +} From 09e04d8e834f299dc877eb06696f8b23d01964e0 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 4 Jul 2024 23:27:29 +0900 Subject: [PATCH 060/100] =?UTF-8?q?feat=20-=20#171=20AdminLoginRequest=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 --- .../hmh/domain/admin/dto/request/AdminLoginRequest.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminLoginRequest.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminLoginRequest.java b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminLoginRequest.java new file mode 100644 index 00000000..a280bdab --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminLoginRequest.java @@ -0,0 +1,7 @@ +package sopt.org.hmh.domain.admin.dto.request; + +public record AdminLoginRequest( + String authCode +) { + +} From 22eae0c3e121302599dc3175a46262db62fd213f Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 4 Jul 2024 23:48:17 +0900 Subject: [PATCH 061/100] =?UTF-8?q?modify=20-=20#171=20Admin=20exception?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/admin/exception/AdminError.java | 2 +- .../sopt/org/hmh/domain/admin/exception/AdminException.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java index c078a957..61bdcb71 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java +++ b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.java @@ -8,7 +8,7 @@ public enum AdminError implements ErrorBase { // 401 UNAUTHORIZED - INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."), + INVALID_ADMIN_AUTH_CODE(HttpStatus.UNAUTHORIZED, "관리자 인증 번호가 일치하지 않습니다."), ; private final HttpStatus status; diff --git a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java index 0a54ebeb..7c0ecfd8 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java +++ b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.java @@ -1,11 +1,10 @@ package sopt.org.hmh.domain.admin.exception; -import sopt.org.hmh.domain.auth.exception.AuthError; import sopt.org.hmh.global.common.exception.base.ExceptionBase; public class AdminException extends ExceptionBase { - public AdminException(AuthError errorBase) { + public AdminException(AdminError errorBase) { super(errorBase); } } From b898776c90f68968b2ab7635ab9284eccfbdd9ea Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 4 Jul 2024 23:49:49 +0900 Subject: [PATCH 062/100] =?UTF-8?q?fix=20-=20#171=20=EC=9E=98=EB=AA=BB=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=ED=95=9C=20controller=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/admin/controller/AdminController.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index 5bdaae4e..868b140a 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -15,15 +15,18 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/admin") -public class AdminController implements AdminApi{ +public class AdminController implements AdminApi { + + private final AdminFacade adminFacade; + @Override @PostMapping("/login") public ResponseEntity> orderAdminLogin( - @RequestBody @Valid final AdminLoginRequest request) - { + @RequestBody @Valid final AdminLoginRequest request) { return ResponseEntity .status(AdminSuccess.ADMIN_LOGIN_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AdminSuccess.ADMIN_LOGIN_SUCCESS, AdminFacade.adminLogin(request.authCode()))); + .body(BaseResponse.success(AdminSuccess.ADMIN_LOGIN_SUCCESS, + adminFacade.adminLogin(request.authCode()))); } } From 9632cceb480cec1beaf58528602d864036be9fb7 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 4 Jul 2024 23:50:07 +0900 Subject: [PATCH 063/100] =?UTF-8?q?feat=20-=20#171=20AdminTokenResponse=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/admin/dto/response/AdminTokenResponse.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/dto/response/AdminTokenResponse.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/dto/response/AdminTokenResponse.java b/src/main/java/sopt/org/hmh/domain/admin/dto/response/AdminTokenResponse.java new file mode 100644 index 00000000..8c6458a1 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/dto/response/AdminTokenResponse.java @@ -0,0 +1,6 @@ +package sopt.org.hmh.domain.admin.dto.response; + +public record AdminTokenResponse( + String accessToken +) { +} From 94d3c5f63dcb8713903be3e57ac5b67bc407f33b Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 00:14:52 +0900 Subject: [PATCH 064/100] =?UTF-8?q?feat=20-=20#171=20Admin=20Token=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=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 --- .../sopt/org/hmh/global/auth/jwt/JwtGenerator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java index 5da40648..1c1758db 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java @@ -22,6 +22,8 @@ public class JwtGenerator { private Long ACCESS_TOKEN_EXPIRATION_TIME; @Value("${jwt.refresh-token-expiration-time}") private Long REFRESH_TOKEN_EXPIRATION_TIME; + @Value("${jwt.admin-access-token-expiration-time}") + private Long ADMIN_ACCESS_TOKEN_EXPIRATION_TIME; public String generateToken(Long userId, boolean isRefreshToken) { final Date now = generateNowDate(); @@ -36,6 +38,18 @@ public String generateToken(Long userId, boolean isRefreshToken) { .compact(); } + public String generateAdminToken() { + final Date now = generateNowDate(); + + return Jwts.builder() + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .setSubject("ADMIN") + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + ADMIN_ACCESS_TOKEN_EXPIRATION_TIME)) + .signWith(getSigningKey()) + .compact(); + } + public JwtParser getJwtParser() { return Jwts.parserBuilder() .setSigningKey(getSigningKey()) From a746d7873a1c1414461e0abda36d23ed51fc1eb2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 00:15:11 +0900 Subject: [PATCH 065/100] =?UTF-8?q?feat=20-=20#171=20JwtProvider=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Admin=20Token=20=EC=A0=9C=EA=B3=B5=20=EB=A1=9C?= =?UTF-8?q?=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 --- src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java index a1933e0f..b55d5ac7 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java @@ -21,4 +21,8 @@ public Long getSubject(String token) { .getBody() .getSubject()); } + + public String issueAdminToken() { + return jwtGenerator.generateAdminToken(); + } } \ No newline at end of file From a18180234969de6c07571687a6eae2f1447a12fb Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 00:18:06 +0900 Subject: [PATCH 066/100] =?UTF-8?q?feat=20-=20#171=20JwtConstants=EC=97=90?= =?UTF-8?q?=EC=84=9C=20ADMIN=5FROLE=20=EC=83=81=EC=88=98=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/global/auth/jwt/JwtConstants.java | 1 + .../org/hmh/global/auth/jwt/JwtValidator.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtConstants.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtConstants.java index 792d2ee9..4e5ee2b8 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtConstants.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtConstants.java @@ -8,4 +8,5 @@ public abstract class JwtConstants { public static final String AUTHORIZATION = "Authorization"; public static final String BEARER = "Bearer "; public static final String CHARACTER_ENCODING = "UTF-8"; + public static final String ADMIN_ROLE = "ADMIN"; } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java index b8ed8b24..03f35758 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java @@ -1,6 +1,10 @@ package sopt.org.hmh.global.auth.jwt; +import static sopt.org.hmh.global.auth.jwt.JwtConstants.ADMIN_ROLE; + +import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; +import io.jsonwebtoken.Jws; import io.jsonwebtoken.JwtParser; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -32,8 +36,15 @@ public void validateRefreshToken(String refreshToken) { } } - private void parseToken(String token) { + private Jws parseToken(String token) { JwtParser jwtParser = jwtGenerator.getJwtParser(); - jwtParser.parseClaimsJws(token); + return jwtParser.parseClaimsJws(token); + } + + public void validateAdminToken(String token) { + String subject = parseToken(token).getBody().getSubject(); + if (!subject.equals(ADMIN_ROLE)) { + throw new JwtException(JwtError.INVALID_ADMIN_TOKEN); + } } } \ No newline at end of file From 53cec3bbf89837b20d5723843bc3714bbcfefb94 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:21:11 +0900 Subject: [PATCH 067/100] =?UTF-8?q?feat=20-=20#171=20JwtError=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=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/global/auth/jwt/exception/JwtError.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtError.java b/src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtError.java index 845d98a6..9006d88c 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtError.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtError.java @@ -26,11 +26,14 @@ public enum JwtError implements ErrorBase { INVALID_IDENTITY_TOKEN_CLAIMS(HttpStatus.UNAUTHORIZED, "유효하지 않은 애플 아이덴티티 토큰 클레임입니다."), UNABLE_TO_CREATE_APPLE_PUBLIC_KEY(HttpStatus.UNAUTHORIZED, "애플 로그인 중 퍼블릭 키 생성에 문제가 발생했습니다."), + INVALID_ADMIN_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 관리자 액세스 토큰입니다."), + // 404 NOT FOUND NOT_FOUND_REFRESH_TOKEN_ERROR(HttpStatus.NOT_FOUND, "존재하지 않는 리프레시 토큰입니다."), // 500 INTERNAL ERROR INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다."); + private final HttpStatus status; private final String errorMessage; From d4e52a78248acc776962500e206caa20850d5d3b Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:21:31 +0900 Subject: [PATCH 068/100] =?UTF-8?q?feat=20-=20#171=20admin=20token=20?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EB=A9=94=EC=84=9C=EB=93=9C=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 --- src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java index 64e2f6b9..e590c1f4 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java @@ -34,4 +34,8 @@ public TokenResponse issueToken(Long userId) { return jwtProvider.issueToken(userId); } + public String issueAdminToken() { + return jwtProvider.issueAdminToken(); + } + } From ecd41cf5ff951ccdcd5cc83680b021afe712dec8 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:34:35 +0900 Subject: [PATCH 069/100] =?UTF-8?q?feat=20-=20#171=20SecurityConfig?= =?UTF-8?q?=EC=97=90=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/global/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java b/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java index 5c7e1203..7a8a4908 100644 --- a/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java +++ b/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java @@ -38,6 +38,7 @@ public class SecurityConfig { // Authentication "/api/v1/user/login", + "/api/v1/admin/login", "/api/v1/user/reissue", "/api/v1/user/signup", "/api/v1/user/social/token/kakao", From 39dc44fc0ed91eb10d479d79d4907fe8390df822 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:35:26 +0900 Subject: [PATCH 070/100] =?UTF-8?q?refactor=20-=20#171=20=ED=95=98?= =?UTF-8?q?=EB=93=9C=20=EC=BD=94=EB=94=A9=EB=90=9C=20String=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java index 1c1758db..1b85849e 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java @@ -1,5 +1,7 @@ package sopt.org.hmh.global.auth.jwt; +import static sopt.org.hmh.global.auth.jwt.JwtConstants.ADMIN_ROLE; + import io.jsonwebtoken.Header; import io.jsonwebtoken.JwtParser; import io.jsonwebtoken.Jwts; @@ -43,7 +45,7 @@ public String generateAdminToken() { return Jwts.builder() .setHeaderParam(Header.TYPE, Header.JWT_TYPE) - .setSubject("ADMIN") + .setSubject(ADMIN_ROLE) .setIssuedAt(now) .setExpiration(new Date(now.getTime() + ADMIN_ACCESS_TOKEN_EXPIRATION_TIME)) .signWith(getSigningKey()) From c10203798d6f6085ebdc6f63b05aac42aeae35e8 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:36:12 +0900 Subject: [PATCH 071/100] =?UTF-8?q?feat=20-=20#171=20admin=20facade?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=B4=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=9E=90=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/admin/service/AdminFacade.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java new file mode 100644 index 00000000..8c815ed2 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java @@ -0,0 +1,30 @@ +package sopt.org.hmh.domain.admin.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; +import sopt.org.hmh.domain.admin.exception.AdminError; +import sopt.org.hmh.domain.admin.exception.AdminException; +import sopt.org.hmh.global.auth.jwt.TokenService; + +@Service +@RequiredArgsConstructor +public class AdminFacade { + + @Value("${jwt.admin-auth-code}") + private String adminAuthCode; + + private final TokenService tokenService; + + public AdminTokenResponse adminLogin(String authCode) { + validateAdminAuthCode(authCode); + return new AdminTokenResponse(tokenService.issueAdminToken()); + } + + private void validateAdminAuthCode(String authCode) { + if (!adminAuthCode.equals(authCode)) { + throw new AdminException(AdminError.INVALID_ADMIN_AUTH_CODE); + } + } +} From e5c7af4cec763f8f0f4164d6f4c70103a8a4bb43 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:42:56 +0900 Subject: [PATCH 072/100] =?UTF-8?q?feat=20-=20#171=20=EB=B0=98=ED=99=98=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EC=97=90=20=EC=99=80=EC=9D=BC=EB=93=9C=20?= =?UTF-8?q?=EC=B9=B4=EB=93=9C=20=EC=A7=80=EC=96=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/admin/controller/AdminApi.java | 3 ++- .../sopt/org/hmh/domain/admin/controller/AdminController.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java index ac863117..17b7c311 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -3,9 +3,10 @@ import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.ResponseEntity; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; +import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.global.common.response.BaseResponse; public interface AdminApi { @Operation(summary = "소셜 로그인") - ResponseEntity> orderAdminLogin(AdminLoginRequest request); + ResponseEntity> orderAdminLogin(AdminLoginRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index 868b140a..ba075c42 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; +import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminSuccess; import sopt.org.hmh.domain.admin.service.AdminFacade; import sopt.org.hmh.global.common.response.BaseResponse; @@ -21,7 +22,7 @@ public class AdminController implements AdminApi { @Override @PostMapping("/login") - public ResponseEntity> orderAdminLogin( + public ResponseEntity> orderAdminLogin( @RequestBody @Valid final AdminLoginRequest request) { return ResponseEntity .status(AdminSuccess.ADMIN_LOGIN_SUCCESS.getHttpStatus()) From 0d0980e5cbfa1ef8480804668165b8089dba02e8 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 15:43:43 +0900 Subject: [PATCH 073/100] =?UTF-8?q?feat=20-=20#171=20=EC=A6=89=EC=8B=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EB=A5=BC=20=EC=82=AD=EC=A0=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=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 --- .../java/sopt/org/hmh/domain/user/service/UserService.java | 5 +++++ 1 file changed, 5 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 12e2bfa9..ac1719e0 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 @@ -100,4 +100,9 @@ public IsLockTodayResponse checkIsTodayLock(Long userId, LocalDate lockCheckDate LocalDate userRecentLockDate = this.findByIdOrThrowException(userId).getRecentLockDate(); return new IsLockTodayResponse(lockCheckDate.equals(userRecentLockDate)); } + + @Transactional + public void withdrawImmediately(Long userId) { + userRepository.deleteById(userId); + } } \ No newline at end of file From 46fb3a51035bf3ca5b58cb5eb2e3ca67c5dea804 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 16:51:14 +0900 Subject: [PATCH 074/100] =?UTF-8?q?feat=20-=20#171=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=9E=90=20=EC=9C=A0=EC=A0=80=20=EC=A6=89=EC=8B=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20controller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/admin/controller/AdminController.java | 11 ++++++++++- .../org/hmh/domain/admin/exception/AdminSuccess.java | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index ba075c42..c7fd4a59 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -3,6 +3,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -23,11 +24,19 @@ public class AdminController implements AdminApi { @Override @PostMapping("/login") public ResponseEntity> orderAdminLogin( - @RequestBody @Valid final AdminLoginRequest request) { + @RequestBody final AdminLoginRequest request) { return ResponseEntity .status(AdminSuccess.ADMIN_LOGIN_SUCCESS.getHttpStatus()) .body(BaseResponse.success(AdminSuccess.ADMIN_LOGIN_SUCCESS, adminFacade.adminLogin(request.authCode()))); } + @Override + @DeleteMapping("/user") + public ResponseEntity orderAdminWithdrawImmediately(@RequestBody @Valid final Long userId) { + adminFacade.withdrawImmediately(userId); + return ResponseEntity + .noContent() + .build(); + } } diff --git a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java index 147dcd22..fc9ba43c 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java +++ b/src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.java @@ -9,6 +9,9 @@ public enum AdminSuccess implements SuccessBase { // 200 OK ADMIN_LOGIN_SUCCESS(HttpStatus.OK, "관리자 로그인에 성공했습니다."), + + // 204 NO CONTENT + ADMIN_WITHDRAW_IMMEDIATELY_SUCCESS(HttpStatus.NO_CONTENT, "관리자 권한으로 유저 즉시 삭제에 성공했습니다."), ; private final HttpStatus status; From 3e606ebc9eb46ba097f660f2778392bfe6f9a657 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 16:51:30 +0900 Subject: [PATCH 075/100] =?UTF-8?q?feat=20-=20#171=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=9E=90=20=EC=9C=A0=EC=A0=80=20=EC=A6=89=EC=8B=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20AdminApi=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/admin/controller/AdminApi.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java index 17b7c311..90c7fda5 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -7,6 +7,9 @@ import sopt.org.hmh.global.common.response.BaseResponse; public interface AdminApi { - @Operation(summary = "소셜 로그인") + @Operation(summary = "관리자 로그인") ResponseEntity> orderAdminLogin(AdminLoginRequest request); + + @Operation(summary = "관리자 권한으로 유저 즉시 삭제") + ResponseEntity orderAdminWithdrawImmediately(Long userId); } From 2b3df313bf69b5c35e41e40fb7b44eb2fdb233b0 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 16:52:06 +0900 Subject: [PATCH 076/100] =?UTF-8?q?feat=20-=20#171=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=9E=90=20=EC=9C=A0=EC=A0=80=20=EC=A6=89=EC=8B=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20service=20=EB=A9=94=EC=84=9C=EB=93=9C=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 --- .../java/sopt/org/hmh/domain/admin/service/AdminFacade.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java index 8c815ed2..053db66c 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java +++ b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java @@ -6,6 +6,7 @@ import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminError; import sopt.org.hmh.domain.admin.exception.AdminException; +import sopt.org.hmh.domain.user.service.UserService; import sopt.org.hmh.global.auth.jwt.TokenService; @Service @@ -15,6 +16,7 @@ public class AdminFacade { @Value("${jwt.admin-auth-code}") private String adminAuthCode; + private final UserService userService; private final TokenService tokenService; public AdminTokenResponse adminLogin(String authCode) { @@ -27,4 +29,8 @@ private void validateAdminAuthCode(String authCode) { throw new AdminException(AdminError.INVALID_ADMIN_AUTH_CODE); } } + + public void withdrawImmediately(Long userId) { + userService.withdrawImmediately(userId); + } } From ea3eb9e220257c38cc7dae65c67fcad4d192485d Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 21:13:05 +0900 Subject: [PATCH 077/100] =?UTF-8?q?modify=20-=20#171=20doAuthentication?= =?UTF-8?q?=EC=8B=9C=EC=97=90=20subject=EB=A5=BC=20String=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=9B=EB=8F=84=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/global/auth/UserIdArgumentResolver.java | 8 +++++--- .../sopt/org/hmh/global/auth/jwt/JwtGenerator.java | 4 ++-- .../sopt/org/hmh/global/auth/jwt/JwtProvider.java | 12 ++++++------ .../sopt/org/hmh/global/auth/jwt/TokenService.java | 6 +++--- .../auth/security/JwtAuthenticationFilter.java | 4 ++-- .../hmh/global/auth/security/UserAuthentication.java | 4 ++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/sopt/org/hmh/global/auth/UserIdArgumentResolver.java b/src/main/java/sopt/org/hmh/global/auth/UserIdArgumentResolver.java index 87c5dd1e..0318b423 100644 --- a/src/main/java/sopt/org/hmh/global/auth/UserIdArgumentResolver.java +++ b/src/main/java/sopt/org/hmh/global/auth/UserIdArgumentResolver.java @@ -21,9 +21,11 @@ public boolean supportsParameter(MethodParameter parameter) { } @Override - public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { - return SecurityContextHolder.getContext() + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { + return Long.parseLong(SecurityContextHolder.getContext() .getAuthentication() - .getPrincipal(); + .getPrincipal() + .toString()); } } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java index 1b85849e..f30eba8e 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java @@ -27,13 +27,13 @@ public class JwtGenerator { @Value("${jwt.admin-access-token-expiration-time}") private Long ADMIN_ACCESS_TOKEN_EXPIRATION_TIME; - public String generateToken(Long userId, boolean isRefreshToken) { + public String generateToken(String subjectId, boolean isRefreshToken) { final Date now = generateNowDate(); final Date expiration = generateExpirationDate(isRefreshToken, now); return Jwts.builder() .setHeaderParam(Header.TYPE, Header.JWT_TYPE) - .setSubject(String.valueOf(userId)) + .setSubject(subjectId) .setIssuedAt(now) .setExpiration(expiration) .signWith(getSigningKey()) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java index b55d5ac7..70c5babc 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java @@ -10,16 +10,16 @@ public class JwtProvider { private final JwtGenerator jwtGenerator; - public TokenResponse issueToken(Long userId) { - return new TokenResponse(jwtGenerator.generateToken(userId, false), - jwtGenerator.generateToken(userId, true)); + public TokenResponse issueToken(String subjectId) { + return new TokenResponse(jwtGenerator.generateToken(subjectId, false), + jwtGenerator.generateToken(subjectId, true)); } - public Long getSubject(String token) { + public String getSubject(String token) { JwtParser jwtParser = jwtGenerator.getJwtParser(); - return Long.valueOf(jwtParser.parseClaimsJws(token) + return jwtParser.parseClaimsJws(token) .getBody() - .getSubject()); + .getSubject(); } public String issueAdminToken() { diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java index e590c1f4..9abc4f36 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java @@ -17,7 +17,7 @@ public class TokenService { @Transactional public ReissueResponse reissueToken(String refreshToken) { String parsedRefreshToken = parseTokenString(refreshToken); - Long userId = jwtProvider.getSubject(parsedRefreshToken); + String userId = jwtProvider.getSubject(parsedRefreshToken); jwtValidator.validateRefreshToken(parsedRefreshToken); return ReissueResponse.of(jwtProvider.issueToken(userId)); } @@ -30,8 +30,8 @@ private String parseTokenString(String tokenString) { return parsedTokens[1]; } - public TokenResponse issueToken(Long userId) { - return jwtProvider.issueToken(userId); + public TokenResponse issueToken(String subjectId) { + return jwtProvider.issueToken(subjectId); } public String issueAdminToken() { diff --git a/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java b/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java index cffc553e..fe360d0c 100644 --- a/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java +++ b/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java @@ -41,8 +41,8 @@ private String getAccessToken(HttpServletRequest request) { throw new JwtException(JwtError.INVALID_ACCESS_TOKEN); } - private void doAuthentication(HttpServletRequest request, Long userId) { - UserAuthentication authentication = createUserAuthentication(userId); + private void doAuthentication(HttpServletRequest request, String subjectId) { + UserAuthentication authentication = createUserAuthentication(subjectId); createAndSetWebAuthenticationDetails(request, authentication); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(authentication); diff --git a/src/main/java/sopt/org/hmh/global/auth/security/UserAuthentication.java b/src/main/java/sopt/org/hmh/global/auth/security/UserAuthentication.java index 7f5d5983..e3be2a1b 100644 --- a/src/main/java/sopt/org/hmh/global/auth/security/UserAuthentication.java +++ b/src/main/java/sopt/org/hmh/global/auth/security/UserAuthentication.java @@ -10,7 +10,7 @@ private UserAuthentication(Object principal, Object credentials, Collection Date: Fri, 5 Jul 2024 21:14:27 +0900 Subject: [PATCH 078/100] =?UTF-8?q?modify=20-=20#171=20doAuthentication?= =?UTF-8?q?=EC=8B=9C=EC=97=90=20subject=EB=A5=BC=20String=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=9B=EB=8F=84=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 --- src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fbc2725a..5e314308 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 @@ -73,7 +73,7 @@ private LoginResponse performLogin(String socialAccessToken, SocialPlatform soci kakaoLoginService.updateUserInfoByKakao(loginUser, socialAccessToken); } Long userId = loginUser.getId(); - return new LoginResponse(userId, tokenService.issueToken(userId)); + return new LoginResponse(userId, tokenService.issueToken(userId.toString())); } public SocialAccessTokenResponse getSocialAccessTokenByAuthorizationCode(String code) { From 4f68e935735d1b2014728515964d7ee7928dc984 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 21:14:50 +0900 Subject: [PATCH 079/100] =?UTF-8?q?feat=20-=20#171=20admin=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EA=B8=B0=EB=8A=A5=20controller=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/admin/controller/AdminApi.java | 3 ++- .../org/hmh/domain/admin/controller/AdminController.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java index 90c7fda5..208dcda0 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -3,6 +3,7 @@ import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.ResponseEntity; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; +import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.global.common.response.BaseResponse; @@ -11,5 +12,5 @@ public interface AdminApi { ResponseEntity> orderAdminLogin(AdminLoginRequest request); @Operation(summary = "관리자 권한으로 유저 즉시 삭제") - ResponseEntity orderAdminWithdrawImmediately(Long userId); + ResponseEntity orderAdminWithdrawImmediately(AdminUserIdRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index c7fd4a59..5ed17311 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; +import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminSuccess; import sopt.org.hmh.domain.admin.service.AdminFacade; @@ -33,8 +34,9 @@ public ResponseEntity> orderAdminLogin( @Override @DeleteMapping("/user") - public ResponseEntity orderAdminWithdrawImmediately(@RequestBody @Valid final Long userId) { - adminFacade.withdrawImmediately(userId); + public ResponseEntity orderAdminWithdrawImmediately( + @RequestBody @Valid final AdminUserIdRequest request) { + adminFacade.withdrawImmediately(request.userId()); return ResponseEntity .noContent() .build(); From 31bd4d51ea6bc90a4aca2a7946f82d8bc898115f Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 21:15:02 +0900 Subject: [PATCH 080/100] =?UTF-8?q?feat=20-=20#171=20AdminUserIdRequest=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 --- .../hmh/domain/admin/dto/request/AdminUserIdRequest.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserIdRequest.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserIdRequest.java b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserIdRequest.java new file mode 100644 index 00000000..c1d513c3 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserIdRequest.java @@ -0,0 +1,7 @@ +package sopt.org.hmh.domain.admin.dto.request; + +public record AdminUserIdRequest( + Long userId +) { + +} From b7f8e0a9ee12965f322c022b8e9312739ef4ac7f Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 21:24:41 +0900 Subject: [PATCH 081/100] =?UTF-8?q?modify=20-=20#171=20=EC=99=80=EC=9D=BC?= =?UTF-8?q?=EB=93=9C=20=EC=B9=B4=EB=93=9C=20=EC=A7=80=EC=96=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/admin/controller/AdminApi.java | 2 +- .../sopt/org/hmh/domain/admin/controller/AdminController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java index 208dcda0..17ac83f9 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -12,5 +12,5 @@ public interface AdminApi { ResponseEntity> orderAdminLogin(AdminLoginRequest request); @Operation(summary = "관리자 권한으로 유저 즉시 삭제") - ResponseEntity orderAdminWithdrawImmediately(AdminUserIdRequest request); + ResponseEntity orderAdminWithdrawImmediately(AdminUserIdRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index 5ed17311..f2eeb20e 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -34,7 +34,7 @@ public ResponseEntity> orderAdminLogin( @Override @DeleteMapping("/user") - public ResponseEntity orderAdminWithdrawImmediately( + public ResponseEntity orderAdminWithdrawImmediately( @RequestBody @Valid final AdminUserIdRequest request) { adminFacade.withdrawImmediately(request.userId()); return ResponseEntity From fe6a8f04db24df8184f901b247713a649a8bc6b3 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 21:49:23 +0900 Subject: [PATCH 082/100] =?UTF-8?q?modify=20-=20#171=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=9C=A0=EC=A0=80=EB=A5=BC?= =?UTF-8?q?=20=EC=B0=BE=EC=A7=80=20=EB=AA=BB=ED=95=98=EB=A9=B4=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=9C=EC=83=9D=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/admin/service/AdminFacade.java | 3 +++ .../sopt/org/hmh/domain/user/service/UserService.java | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java index 053db66c..0bb899f9 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java +++ b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminError; import sopt.org.hmh.domain.admin.exception.AdminException; @@ -30,7 +31,9 @@ private void validateAdminAuthCode(String authCode) { } } + @Transactional public void withdrawImmediately(Long userId) { + userService.checkIsExistUserId(userId); userService.withdrawImmediately(userId); } } 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 ac1719e0..992f4e29 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 @@ -85,6 +85,16 @@ public User findByIdOrThrowException(Long userId) { () -> new UserException(UserError.NOT_FOUND_USER)); } + private boolean isExistUserId(Long userId) { + return userRepository.existsById(userId); + } + + public void checkIsExistUserId(Long userId) { + if (isExistUserId(userId)) { + throw new UserException(UserError.NOT_FOUND_USER); + } + } + public Long getCurrentChallengeIdByUserId(Long userId) { return Optional.ofNullable(this.findByIdOrThrowException(userId).getCurrentChallengeId()) .orElseThrow(() -> new UserException(UserError.NOT_FOUND_CURRENT_CHALLENGE_ID)); @@ -101,7 +111,6 @@ public IsLockTodayResponse checkIsTodayLock(Long userId, LocalDate lockCheckDate return new IsLockTodayResponse(lockCheckDate.equals(userRecentLockDate)); } - @Transactional public void withdrawImmediately(Long userId) { userRepository.deleteById(userId); } From a8d3de9b6426763f667d1f9cc8eed9dd5417d8b0 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 21:49:55 +0900 Subject: [PATCH 083/100] =?UTF-8?q?modify=20-=20#171=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=9C=A0=EC=A0=80=EB=A5=BC?= =?UTF-8?q?=20=EC=B0=BE=EC=A7=80=20=EB=AA=BB=ED=95=98=EB=A9=B4=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=9C=EC=83=9D=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 --- src/main/java/sopt/org/hmh/domain/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 992f4e29..397c5252 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 @@ -90,7 +90,7 @@ private boolean isExistUserId(Long userId) { } public void checkIsExistUserId(Long userId) { - if (isExistUserId(userId)) { + if (!isExistUserId(userId)) { throw new UserException(UserError.NOT_FOUND_USER); } } From b522b85f12809f943cb84ba134dcd10de437656d Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 22:19:11 +0900 Subject: [PATCH 084/100] =?UTF-8?q?feat=20-=20#171=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=B3=80=EA=B2=BD=20controller=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 --- .../org/hmh/domain/admin/controller/AdminApi.java | 4 ++++ .../hmh/domain/admin/controller/AdminController.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java index 17ac83f9..7944cfdc 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -4,6 +4,7 @@ import org.springframework.http.ResponseEntity; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; +import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.global.common.response.BaseResponse; @@ -13,4 +14,7 @@ public interface AdminApi { @Operation(summary = "관리자 권한으로 유저 즉시 삭제") ResponseEntity orderAdminWithdrawImmediately(AdminUserIdRequest request); + + @Operation(summary = "관리자 권한으로 유저 정보 변경") + ResponseEntity orderAdminChangeUserInfo(AdminUserInfoRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index f2eeb20e..80db9323 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -4,12 +4,14 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; +import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminSuccess; import sopt.org.hmh.domain.admin.service.AdminFacade; @@ -41,4 +43,14 @@ public ResponseEntity orderAdminWithdrawImmediately( .noContent() .build(); } + + @Override + @PatchMapping("/user") + public ResponseEntity orderAdminChangeUserInfo( + @RequestBody @Valid final AdminUserInfoRequest request) { + adminFacade.ChangeUserInfo(request); + return ResponseEntity + .noContent() + .build(); + } } From 0cf8f929af271bd4d7a4ccb536289268ab39d2d6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 5 Jul 2024 22:19:23 +0900 Subject: [PATCH 085/100] =?UTF-8?q?feat=20-=20#171=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=B3=80=EA=B2=BD=20request=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 --- .../domain/admin/dto/request/AdminUserInfoRequest.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserInfoRequest.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserInfoRequest.java b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserInfoRequest.java new file mode 100644 index 00000000..ab7c2969 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserInfoRequest.java @@ -0,0 +1,9 @@ +package sopt.org.hmh.domain.admin.dto.request; + +public record AdminUserInfoRequest( + Long userId, + String name, + Integer point +) { + +} From 6dbf1d9aa9fc73c4140c27061ebc1200536531f0 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 02:13:03 +0900 Subject: [PATCH 086/100] =?UTF-8?q?refactor=20-=20#171=20code=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=20=ED=96=A5=EC=83=81=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=A4=84=20=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChallengeController.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 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 6dd9f363..3c503397 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 @@ -25,9 +25,10 @@ public class ChallengeController implements ChallengeApi { @PostMapping @Override - public ResponseEntity> orderAddChallenge(@UserId final Long userId, - @RequestHeader("OS") final String os, - @RequestBody @Valid final ChallengeRequest request) { + public ResponseEntity> orderAddChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestBody @Valid final ChallengeRequest request) { challengeFacade.addChallenge(userId, request, os); return ResponseEntity @@ -37,8 +38,9 @@ public ResponseEntity> orderAddChallenge(@UserId final Long user @GetMapping @Override - public ResponseEntity> orderGetChallenge(@UserId final Long userId, - @RequestHeader("OS") final String os) { + public ResponseEntity> orderGetChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os) { return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, @@ -47,8 +49,9 @@ public ResponseEntity> orderGetChallenge(@UserId @GetMapping("/home") @Override - public ResponseEntity> orderGetDailyChallenge(@UserId final Long userId, - @RequestHeader("OS") final String os) { + public ResponseEntity> orderGetDailyChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os) { return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, @@ -57,9 +60,10 @@ public ResponseEntity> orderGetDailyChallen @PostMapping("/app") @Override - public ResponseEntity> orderAddApps(@UserId final Long userId, - @RequestHeader("OS") final String os, - @RequestBody @Valid final ChallengeAppArrayRequest requests) { + public ResponseEntity> orderAddApps( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestBody @Valid final ChallengeAppArrayRequest requests) { challengeFacade.addAppsToCurrentChallenge(userId, requests.apps(), os); return ResponseEntity @@ -70,9 +74,10 @@ public ResponseEntity> orderAddApps(@UserId final Long userId, @DeleteMapping("/app") @Override - public ResponseEntity> orderRemoveApp(@UserId final Long userId, - @RequestHeader("OS") final String os, - @RequestBody @Valid final AppRemoveRequest request) { + public ResponseEntity> orderRemoveApp( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestBody @Valid final AppRemoveRequest request) { challengeFacade.removeAppFromCurrentChallenge(userId, request.appCode(), os); return ResponseEntity From a98eb47f8535e077cd37be35ab4cf7452fedaf2b Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 05:27:20 +0900 Subject: [PATCH 087/100] =?UTF-8?q?feat=20-=20#171=20admin=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20interceptor=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/ValidateAdminInterceptor.java | 23 +++++++++++++++++++ .../sopt/org/hmh/global/config/WebConfig.java | 15 ++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/global/auth/security/ValidateAdminInterceptor.java diff --git a/src/main/java/sopt/org/hmh/global/auth/security/ValidateAdminInterceptor.java b/src/main/java/sopt/org/hmh/global/auth/security/ValidateAdminInterceptor.java new file mode 100644 index 00000000..4a08fac4 --- /dev/null +++ b/src/main/java/sopt/org/hmh/global/auth/security/ValidateAdminInterceptor.java @@ -0,0 +1,23 @@ +package sopt.org.hmh.global.auth.security; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; +import sopt.org.hmh.global.auth.jwt.JwtConstants; +import sopt.org.hmh.global.auth.jwt.TokenService; + +@Component +@RequiredArgsConstructor +public class ValidateAdminInterceptor implements HandlerInterceptor { + + private final TokenService tokenService; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + String accessToken = request.getHeader(JwtConstants.AUTHORIZATION); + tokenService.validateAdminToken(accessToken); + return true; + } +} diff --git a/src/main/java/sopt/org/hmh/global/config/WebConfig.java b/src/main/java/sopt/org/hmh/global/config/WebConfig.java index 63262f86..d4a64745 100644 --- a/src/main/java/sopt/org/hmh/global/config/WebConfig.java +++ b/src/main/java/sopt/org/hmh/global/config/WebConfig.java @@ -1,15 +1,23 @@ package sopt.org.hmh.global.config; import java.util.List; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import sopt.org.hmh.global.auth.UserIdArgumentResolver; +import sopt.org.hmh.global.auth.security.ValidateAdminInterceptor; @Configuration +@EnableWebMvc +@RequiredArgsConstructor public class WebConfig implements WebMvcConfigurer { + private final ValidateAdminInterceptor validateAdminInterceptor; + @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") @@ -23,4 +31,11 @@ public void addCorsMappings(CorsRegistry registry) { public void addArgumentResolvers(List resolvers) { resolvers.add(new UserIdArgumentResolver()); } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(validateAdminInterceptor) + .addPathPatterns("/api/v1/admin/**") + .excludePathPatterns("/api/v1/admin/login"); + } } \ No newline at end of file From 901c14c19b9658a98904636be6712a52b8ddd35f Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 05:29:02 +0900 Subject: [PATCH 088/100] =?UTF-8?q?feat=20-=20#171=20JwtPrefixExtractor=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 --- .../global/auth/jwt/JwtPrefixExtractor.java | 19 +++++++++++++++++++ .../security/JwtAuthenticationFilter.java | 9 +-------- 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java new file mode 100644 index 00000000..bf825e6b --- /dev/null +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java @@ -0,0 +1,19 @@ +package sopt.org.hmh.global.auth.jwt; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.util.StringUtils; +import sopt.org.hmh.global.auth.jwt.exception.JwtError; +import sopt.org.hmh.global.auth.jwt.exception.JwtException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class JwtPrefixExtractor { + + public static String extractPrefix(String accessToken) { + if (StringUtils.hasText(accessToken) && accessToken.startsWith(JwtConstants.BEARER)) { + return accessToken.substring(JwtConstants.BEARER.length()); + } + throw new JwtException(JwtError.INVALID_ACCESS_TOKEN); + } + +} diff --git a/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java b/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java index fe360d0c..db01f72f 100644 --- a/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java +++ b/src/main/java/sopt/org/hmh/global/auth/security/JwtAuthenticationFilter.java @@ -11,14 +11,11 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; -import org.springframework.util.StringUtils; import org.springframework.web.filter.OncePerRequestFilter; import java.io.IOException; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.auth.jwt.JwtProvider; import sopt.org.hmh.global.auth.jwt.JwtValidator; -import sopt.org.hmh.global.auth.jwt.exception.JwtError; -import sopt.org.hmh.global.auth.jwt.exception.JwtException; @RequiredArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { @@ -34,11 +31,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse } private String getAccessToken(HttpServletRequest request) { - String accessToken = request.getHeader(JwtConstants.AUTHORIZATION); - if (StringUtils.hasText(accessToken) && accessToken.startsWith(JwtConstants.BEARER)) { - return accessToken.substring(JwtConstants.BEARER.length()); - } - throw new JwtException(JwtError.INVALID_ACCESS_TOKEN); + return request.getHeader(JwtConstants.AUTHORIZATION); } private void doAuthentication(HttpServletRequest request, String subjectId) { From 407978a73161379c11393082077f2e45f1bdf162 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 05:29:30 +0900 Subject: [PATCH 089/100] =?UTF-8?q?feat=20-=20#171=20JwtPrefixExtractor=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 --- .../org/hmh/global/auth/jwt/JwtProvider.java | 5 ++++- .../org/hmh/global/auth/jwt/JwtValidator.java | 4 +++- .../org/hmh/global/auth/jwt/TokenService.java | 18 +++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java index 70c5babc..ade8b1df 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java @@ -1,5 +1,7 @@ package sopt.org.hmh.global.auth.jwt; +import static sopt.org.hmh.global.auth.jwt.JwtPrefixExtractor.extractPrefix; + import io.jsonwebtoken.JwtParser; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -16,8 +18,9 @@ public TokenResponse issueToken(String subjectId) { } public String getSubject(String token) { + String extractedToken = extractPrefix(token); JwtParser jwtParser = jwtGenerator.getJwtParser(); - return jwtParser.parseClaimsJws(token) + return jwtParser.parseClaimsJws(extractedToken) .getBody() .getSubject(); } diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java index 03f35758..c964c791 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java @@ -1,6 +1,7 @@ package sopt.org.hmh.global.auth.jwt; import static sopt.org.hmh.global.auth.jwt.JwtConstants.ADMIN_ROLE; +import static sopt.org.hmh.global.auth.jwt.JwtPrefixExtractor.extractPrefix; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -37,8 +38,9 @@ public void validateRefreshToken(String refreshToken) { } private Jws parseToken(String token) { + String extractedToken = extractPrefix(token); JwtParser jwtParser = jwtGenerator.getJwtParser(); - return jwtParser.parseClaimsJws(token); + return jwtParser.parseClaimsJws(extractedToken); } public void validateAdminToken(String token) { diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java index 9abc4f36..b589abac 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java @@ -1,11 +1,11 @@ package sopt.org.hmh.global.auth.jwt; +import static sopt.org.hmh.global.auth.jwt.JwtPrefixExtractor.extractPrefix; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.auth.dto.response.ReissueResponse; -import sopt.org.hmh.global.auth.jwt.exception.JwtError; -import sopt.org.hmh.global.auth.jwt.exception.JwtException; @Service @RequiredArgsConstructor @@ -16,20 +16,12 @@ public class TokenService { @Transactional public ReissueResponse reissueToken(String refreshToken) { - String parsedRefreshToken = parseTokenString(refreshToken); + String parsedRefreshToken = extractPrefix(refreshToken); String userId = jwtProvider.getSubject(parsedRefreshToken); jwtValidator.validateRefreshToken(parsedRefreshToken); return ReissueResponse.of(jwtProvider.issueToken(userId)); } - private String parseTokenString(String tokenString) { - String[] parsedTokens = tokenString.split(" "); - if (parsedTokens.length != 2) { - throw new JwtException(JwtError.INVALID_TOKEN_HEADER); - } - return parsedTokens[1]; - } - public TokenResponse issueToken(String subjectId) { return jwtProvider.issueToken(subjectId); } @@ -38,4 +30,8 @@ public String issueAdminToken() { return jwtProvider.issueAdminToken(); } + public void validateAdminToken(String token){ + jwtValidator.validateAdminToken(token); + } + } From 252a6fc291fc8c3ab60d373cd93e195a5f7c73f1 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 05:41:08 +0900 Subject: [PATCH 090/100] =?UTF-8?q?feat=20-=20#171=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=9E=90=20=ED=9A=8C=EC=9B=90=20=EC=A0=95=EB=B3=B4=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/admin/controller/AdminController.java | 2 +- .../org/hmh/domain/admin/service/AdminFacade.java | 14 ++++++++++++++ .../java/sopt/org/hmh/domain/user/domain/User.java | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index 80db9323..2ea375bb 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -48,7 +48,7 @@ public ResponseEntity orderAdminWithdrawImmediately( @PatchMapping("/user") public ResponseEntity orderAdminChangeUserInfo( @RequestBody @Valid final AdminUserInfoRequest request) { - adminFacade.ChangeUserInfo(request); + adminFacade.changeUserInfo(request); return ResponseEntity .noContent() .build(); diff --git a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java index 0bb899f9..022e41f5 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java +++ b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java @@ -1,12 +1,15 @@ package sopt.org.hmh.domain.admin.service; +import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminError; import sopt.org.hmh.domain.admin.exception.AdminException; +import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.domain.user.service.UserService; import sopt.org.hmh.global.auth.jwt.TokenService; @@ -36,4 +39,15 @@ public void withdrawImmediately(Long userId) { userService.checkIsExistUserId(userId); userService.withdrawImmediately(userId); } + + @Transactional + public void changeUserInfo(AdminUserInfoRequest request) { + User user = userService.findByIdOrThrowException(request.userId()); + if (Objects.nonNull(request.point())) { + user.changePoint(request.point()); + } + if (Objects.nonNull(request.name())) { + user.changeName(request.name()); + } + } } diff --git a/src/main/java/sopt/org/hmh/domain/user/domain/User.java b/src/main/java/sopt/org/hmh/domain/user/domain/User.java index 0ed66780..fb831734 100644 --- a/src/main/java/sopt/org/hmh/domain/user/domain/User.java +++ b/src/main/java/sopt/org/hmh/domain/user/domain/User.java @@ -89,6 +89,14 @@ public Integer increasePoint(Integer earnedPoint) { return this.point; } + public void changePoint(Integer point) { + this.point = point; + } + + public void changeName(String name) { + this.name = name; + } + public void changeCurrentChallengeId(Long currentChallengeId) { this.currentChallengeId = currentChallengeId; } From 98efb1eeacfb27a70a4379fa4fb6d35173780efb Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 05:54:07 +0900 Subject: [PATCH 091/100] =?UTF-8?q?refactor=20-=20#171=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=20=ED=96=A5=EC=83=81=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 --- .../dailychallenge/service/DailyChallengeFacade.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index 122b52fc..b4ba716e 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -25,10 +25,12 @@ public class DailyChallengeFacade { @Transactional public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequest requests, String os) { Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); - List currentChallengeApps = challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); + List currentChallengeApps = + challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); requests.finishedDailyChallenges().forEach(request -> { - DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); + DailyChallenge dailyChallenge = + dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); }); @@ -37,12 +39,14 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge @Transactional public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { requests.finishedDailyChallenges().forEach(request -> { - DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); + DailyChallenge dailyChallenge = + dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); if (request.isSuccess()) { dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); dailyChallenge.changeStatus(Status.UNEARNED); } else { - dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE, Status.FAILURE)); + dailyChallengeService.validateDailyChallengeStatus( + dailyChallenge.getStatus(), List.of(Status.NONE, Status.FAILURE)); dailyChallenge.changeStatus(Status.FAILURE); } }); From f857322ad926893a1be9dd9becc107255bdabd01 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 06:29:56 +0900 Subject: [PATCH 092/100] =?UTF-8?q?feat=20-=20#171=20AdminDailyChallengeRe?= =?UTF-8?q?quest=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/AdminDailyChallengeRequest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminDailyChallengeRequest.java diff --git a/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminDailyChallengeRequest.java b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminDailyChallengeRequest.java new file mode 100644 index 00000000..ccd4e389 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminDailyChallengeRequest.java @@ -0,0 +1,12 @@ +package sopt.org.hmh.domain.admin.dto.request; + +import java.time.LocalDate; +import java.util.List; +import sopt.org.hmh.domain.dailychallenge.domain.Status; + +public record AdminDailyChallengeRequest( + Long userId, + LocalDate startDate, + List statuses +) { +} From 178f17ab35ce7bb3f0640ca7fb6629e4a212f16b Mon Sep 17 00:00:00 2001 From: kseysh Date: Sat, 6 Jul 2024 06:30:27 +0900 Subject: [PATCH 093/100] =?UTF-8?q?feat=20-=20#171=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=A0=95=EB=B3=B4=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20controller=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/admin/controller/AdminApi.java | 4 ++++ .../hmh/domain/admin/controller/AdminController.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java index 7944cfdc..51b57e3f 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.ResponseEntity; +import sopt.org.hmh.domain.admin.dto.request.AdminDailyChallengeRequest; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; @@ -17,4 +18,7 @@ public interface AdminApi { @Operation(summary = "관리자 권한으로 유저 정보 변경") ResponseEntity orderAdminChangeUserInfo(AdminUserInfoRequest request); + + @Operation(summary = "관리자 권한으로 유저 챌린지 정보 변경") + ResponseEntity orderAdminChangeDailyChallengeInfo(AdminDailyChallengeRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java index 2ea375bb..647cea23 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java +++ b/src/main/java/sopt/org/hmh/domain/admin/controller/AdminController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import sopt.org.hmh.domain.admin.dto.request.AdminDailyChallengeRequest; import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; @@ -53,4 +54,14 @@ public ResponseEntity orderAdminChangeUserInfo( .noContent() .build(); } + + @Override + @PatchMapping("/challenge/daily") + public ResponseEntity orderAdminChangeDailyChallengeInfo( + @RequestBody @Valid final AdminDailyChallengeRequest request) { + adminFacade.changeDailyChallengeInfo(request); + return ResponseEntity + .noContent() + .build(); + } } From 8bb97903910d824fd47a2253effbe6dfd7d570dd Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 18:09:33 +0900 Subject: [PATCH 094/100] =?UTF-8?q?feat=20-=20#171=20challenge=20id?= =?UTF-8?q?=EB=A1=9C=20dailyChallenge=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20?= =?UTF-8?q?=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 --- .../dailychallenge/repository/DailyChallengeRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java index e08921fd..ca5bd335 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java @@ -1,10 +1,14 @@ package sopt.org.hmh.domain.dailychallenge.repository; import java.time.LocalDate; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; public interface DailyChallengeRepository extends JpaRepository { + Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); + + List findAllByChallengeId(Long challengeId); } \ No newline at end of file From 88726fee3a8526f149a7cb3f02c21685139f0a28 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 18:10:12 +0900 Subject: [PATCH 095/100] =?UTF-8?q?feat=20-=20#171=20dailyChallenge?= =?UTF-8?q?=EC=9D=98=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B0=94=EA=BE=B8?= =?UTF-8?q?=EB=8A=94=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 --- .../dailychallenge/domain/DailyChallenge.java | 5 +++- .../service/DailyChallengeService.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java index d62ac340..2d568237 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/domain/DailyChallenge.java @@ -9,7 +9,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.springframework.util.Assert; import sopt.org.hmh.domain.app.domain.HistoryApp; import sopt.org.hmh.global.common.domain.BaseTimeEntity; import sopt.org.hmh.domain.challenge.domain.Challenge; @@ -54,6 +53,10 @@ public class DailyChallenge extends BaseTimeEntity { this.status = Status.NONE; } + public void changeChallengeDate(LocalDate challengeDate) { + this.challengeDate = challengeDate; + } + public void changeStatus(Status status) { this.status = status; } 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 7062cae1..76d81a8a 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 @@ -53,4 +53,28 @@ public void addDailyChallenge(Long userId, LocalDate startDate, Challenge challe .goalTime(challenge.getGoalTime()).build()) .toList()); } + + public List getDailyChallengesByChallengeId(Long challengeId) { + return dailyChallengeRepository.findAllByChallengeId(challengeId); + } + + public void changeInfoOfDailyChallenges(Long challengeId, List statuses, LocalDate challengeDate) { + List dailyChallenges = getDailyChallengesByChallengeId(challengeId); + changeStatusOfDailyChallenges(dailyChallenges, statuses); + changeChallengeDateOfDailyChallenges(dailyChallenges, challengeDate); + } + + private void changeStatusOfDailyChallenges(List dailyChallenges, List statuses) { + int challengePeriod = dailyChallenges.size(); + for (int i = 0; i < challengePeriod; i++) { + dailyChallenges.get(i).changeStatus(statuses.get(i)); + } + } + + private void changeChallengeDateOfDailyChallenges(List dailyChallenges, LocalDate challengeDate) { + int challengePeriod = dailyChallenges.size(); + for (int i = 0; i < challengePeriod; i++) { + dailyChallenges.get(i).changeChallengeDate(challengeDate.plusDays(i)); + } + } } \ No newline at end of file From 7ba10f46d2ebd8510c2f21b497ecd66b9bb09fc5 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 18:10:25 +0900 Subject: [PATCH 096/100] =?UTF-8?q?feat=20-=20#171=20challenge=20=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=EC=9D=84=20=EC=B0=BE=EB=8A=94=20=EB=A1=9C=EC=A7=81=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 --- .../org/hmh/domain/challenge/service/ChallengeService.java | 4 ++++ 1 file changed, 4 insertions(+) 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 569a4684..efd2e311 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 @@ -31,4 +31,8 @@ public List getCurrentChallengeAppByChallengeId(Long challengeId) public Challenge save(Challenge challenge) { return challengeRepository.save(challenge); } + + public Integer getChallengePeriod(Long challengeId) { + return findByIdOrElseThrow(challengeId).getPeriod(); + } } From a1b41fbfe0be18ec363352c87ca9e6c565a137df Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 18:10:48 +0900 Subject: [PATCH 097/100] =?UTF-8?q?feat=20-=20#171=20dailyChallenge=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20facade=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 --- .../hmh/domain/admin/service/AdminFacade.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java index 022e41f5..fa1ff3b7 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java +++ b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java @@ -1,14 +1,22 @@ package sopt.org.hmh.domain.admin.service; +import java.time.LocalDate; +import java.util.List; import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import sopt.org.hmh.domain.admin.dto.request.AdminDailyChallengeRequest; import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; import sopt.org.hmh.domain.admin.exception.AdminError; import sopt.org.hmh.domain.admin.exception.AdminException; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; +import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; +import sopt.org.hmh.domain.challenge.service.ChallengeService; +import sopt.org.hmh.domain.dailychallenge.domain.Status; +import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService; import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.domain.user.service.UserService; import sopt.org.hmh.global.auth.jwt.TokenService; @@ -22,6 +30,8 @@ public class AdminFacade { private final UserService userService; private final TokenService tokenService; + private final ChallengeService challengeService; + private final DailyChallengeService dailyChallengeService; public AdminTokenResponse adminLogin(String authCode) { validateAdminAuthCode(authCode); @@ -50,4 +60,21 @@ public void changeUserInfo(AdminUserInfoRequest request) { user.changeName(request.name()); } } + + @Transactional + public void changeDailyChallengeInfo(AdminDailyChallengeRequest request) { + Long currentChallengeId = userService.getCurrentChallengeIdByUserId(request.userId()); + List statuses = request.statuses(); + LocalDate challengeDate = request.startDate(); + + validateStatusesPeriod(currentChallengeId, statuses); + dailyChallengeService.changeInfoOfDailyChallenges(currentChallengeId, statuses, challengeDate); + } + + private void validateStatusesPeriod(Long challengeId, List statuses) { + Integer challengePeriod = challengeService.getChallengePeriod(challengeId); + if (challengePeriod != statuses.size()) { + throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC); + } + } } From 16cb21e6e39dca70a89edb4c9c0584f12c3d2f23 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 22:33:37 +0900 Subject: [PATCH 098/100] =?UTF-8?q?refactor=20-=20#171=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=95=84=EC=9D=B4=EB=94=94=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A1=9C=20=EC=97=AC=EB=9F=AC=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=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 --- .../org/hmh/domain/challenge/service/ChallengeService.java | 6 +++++- .../hmh/domain/user/service/ExpiredUserDeleteScheduler.java | 2 +- 2 files changed, 6 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 efd2e311..ccf0cf02 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 @@ -15,10 +15,14 @@ public class ChallengeService { private final ChallengeRepository challengeRepository; - public void deleteChallengeRelatedByUserId(List expiredUserIdList) { + public void deleteChallengeRelatedByUserIds(List expiredUserIdList) { challengeRepository.deleteByUserIdIn(expiredUserIdList); } + public void deleteChallengeRelatedByUserId(Long userId) { + challengeRepository.deleteByUserId(userId); + } + public Challenge findByIdOrElseThrow(Long challengeId) { return challengeRepository.findById(challengeId).orElseThrow( () -> new ChallengeException(ChallengeError.CHALLENGE_NOT_FOUND)); diff --git a/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java b/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java index 055fa30f..e3f096f8 100644 --- a/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java +++ b/src/main/java/sopt/org/hmh/domain/user/service/ExpiredUserDeleteScheduler.java @@ -25,6 +25,6 @@ public void deleteExpiredUser() { public void deleteExpiredUser(LocalDateTime currentDate) { List expiredUserList = userRepository.findIdByDeletedAtBeforeAndIsDeletedIsTrue(currentDate); userRepository.deleteAllById(expiredUserList); - challengeService.deleteChallengeRelatedByUserId(expiredUserList); + challengeService.deleteChallengeRelatedByUserIds(expiredUserList); } } From 65247c9a11bf67492af9a0e55cc7dbf9b565ea44 Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 22:34:53 +0900 Subject: [PATCH 099/100] =?UTF-8?q?modify=20-=20#171=20user=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=A0=20=EB=95=8C=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=99=80=20=EC=97=B0=EA=B4=80=EB=90=9C=20challenge=EB=8F=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/admin/service/AdminFacade.java | 1 + .../hmh/domain/challenge/repository/ChallengeRepository.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java index fa1ff3b7..6fbdc22d 100644 --- a/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java +++ b/src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.java @@ -47,6 +47,7 @@ private void validateAdminAuthCode(String authCode) { @Transactional public void withdrawImmediately(Long userId) { userService.checkIsExistUserId(userId); + challengeService.deleteChallengeRelatedByUserId(userId); userService.withdrawImmediately(userId); } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepository.java b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepository.java index b426c20f..1126f585 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepository.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepository.java @@ -10,4 +10,6 @@ public interface ChallengeRepository extends JpaRepository { Optional findById(Long id); void deleteByUserIdIn(List userId); + + void deleteByUserId(Long userId); } \ No newline at end of file From bbb95e8d194ba45b924f69be1c4e8a270e5614bf Mon Sep 17 00:00:00 2001 From: kseysh Date: Sun, 7 Jul 2024 22:54:15 +0900 Subject: [PATCH 100/100] =?UTF-8?q?refactor=20-=20#171=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20int=20=EB=B3=80=EC=88=98=EB=A5=BC?= =?UTF-8?q?=20for=EB=AC=B8=20=EC=95=88=EC=9C=BC=EB=A1=9C=20=EB=84=A3?= =?UTF-8?q?=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dailychallenge/service/DailyChallengeService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 76d81a8a..c5ee346e 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 @@ -65,15 +65,13 @@ public void changeInfoOfDailyChallenges(Long challengeId, List statuses, } private void changeStatusOfDailyChallenges(List dailyChallenges, List statuses) { - int challengePeriod = dailyChallenges.size(); - for (int i = 0; i < challengePeriod; i++) { + for (int i = 0; i < dailyChallenges.size(); i++) { dailyChallenges.get(i).changeStatus(statuses.get(i)); } } private void changeChallengeDateOfDailyChallenges(List dailyChallenges, LocalDate challengeDate) { - int challengePeriod = dailyChallenges.size(); - for (int i = 0; i < challengePeriod; i++) { + for (int i = 0; i < dailyChallenges.size(); i++) { dailyChallenges.get(i).changeChallengeDate(challengeDate.plusDays(i)); } }