From 4d59091e37fa2dfa8d574d8bcb630083d3ffcb3c Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 20:51:38 +0900 Subject: [PATCH 01/41] =?UTF-8?q?modify=20-=20#175=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Controller=20=EC=BD=94=EB=93=9C=EB=A5=BC=20Deprecated=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=9B=84=20v2=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChallengeController.java | 2 +- .../ChallengeControllerDeprecated.java | 87 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java 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 5c44f385..a9e33528 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 @@ -18,7 +18,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/challenge") +@RequestMapping("/api/v2/challenge") public class ChallengeController implements ChallengeApi { private final ChallengeFacade challengeFacade; diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java new file mode 100644 index 00000000..6d5d77a4 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -0,0 +1,87 @@ +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.*; +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.exception.ChallengeSuccess; +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.ChallengeFacade; +import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/challenge") +public class ChallengeControllerDeprecated implements ChallengeApi { + + private final ChallengeFacade challengeFacade; + + @PostMapping + @Override + public ResponseEntity> orderAddChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestBody @Valid final ChallengeRequest request) { + challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os); + + return ResponseEntity + .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(ChallengeSuccess.ADD_CHALLENGE_SUCCESS, new EmptyJsonResponse())); + } + + @GetMapping + @Override + 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, + challengeFacade.getCurrentChallengeInfo(userId))); + } + + @GetMapping("/home") + @Override + 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, + challengeFacade.getDailyChallengeInfo(userId))); + } + + @PostMapping("/app") + @Override + 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 + .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse())); + + } + + @DeleteMapping("/app") + @Override + 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 + .status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse())); + } +} \ No newline at end of file From 2c2cb0b051cd6eee7f24cbe69a2ac4ffc5321220 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 20:58:44 +0900 Subject: [PATCH 02/41] =?UTF-8?q?modify=20-=20#175=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Controller=20=EC=BD=94=EB=93=9C=EB=A5=BC=20Deprecated=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=9B=84=20v2=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/controller/ChallengeApi.java | 22 ++-- .../controller/ChallengeApiDeprecated.java | 121 ++++++++++++++++++ .../controller/ChallengeController.java | 87 ------------- .../ChallengeControllerDeprecated.java | 8 +- 4 files changed, 137 insertions(+), 101 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java delete mode 100644 src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java index ffad1577..b9c6533b 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java @@ -16,6 +16,7 @@ import sopt.org.hmh.global.auth.UserId; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; @Tag(name = "챌린지 관련 API") @SecurityRequirement(name = JwtConstants.AUTHORIZATION) @@ -36,10 +37,11 @@ public interface ChallengeApi { responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderAddChallenge( - @UserId @Parameter(hidden = true) final Long userId, - @RequestHeader("OS") final String os, - @RequestBody final ChallengeRequest request); + ResponseEntity> orderAddChallenge( + @Parameter(hidden = true) final Long userId, + final String os, + final String timeZone, + final ChallengeRequest request); @GetMapping @Operation( @@ -94,9 +96,9 @@ ResponseEntity> orderGetDailyChallenge( responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderAddApps(@UserId @Parameter(hidden = true) Long userId, - @RequestHeader("OS") String os, - @RequestBody ChallengeAppArrayRequest requests); + ResponseEntity> orderAddApps(@UserId @Parameter(hidden = true) Long userId, + @RequestHeader("OS") String os, + @RequestBody ChallengeAppArrayRequest requests); @GetMapping("/app") @Operation( @@ -113,8 +115,8 @@ ResponseEntity> orderAddApps(@UserId @Parameter(hidden = true) L responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderRemoveApp(@UserId Long userId, - @RequestHeader("OS") String os, - @RequestBody AppRemoveRequest request); + ResponseEntity> orderRemoveApp(@UserId Long userId, + @RequestHeader("OS") String os, + @RequestBody AppRemoveRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java new file mode 100644 index 00000000..3475430c --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java @@ -0,0 +1,121 @@ +package sopt.org.hmh.domain.challenge.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; +import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; +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.global.auth.UserId; +import sopt.org.hmh.global.auth.jwt.JwtConstants; +import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; + +@Tag(name = "챌린지 관련 API") +@SecurityRequirement(name = JwtConstants.AUTHORIZATION) +public interface ChallengeApiDeprecated { + + @PostMapping + @Operation( + summary = "챌린지가 끝난 후 새 챌린지 생성하는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지가 성공적으로 추가되었습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderAddChallenge( + @UserId @Parameter(hidden = true) final Long userId, + @RequestHeader("OS") final String os, + @RequestBody final ChallengeRequest request); + + @GetMapping + @Operation( + summary = "달성현황뷰 챌린지 정보를 불러오는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지 정보 조회에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderGetChallenge( + @UserId @Parameter(hidden = true) final Long userId, + @RequestHeader("OS") final String os); + + @GetMapping("/home") + @Operation( + summary = "이용시간 통계 정보를 불러오는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지 정보 조회에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderGetDailyChallenge( + @UserId @Parameter(hidden = true) final Long userId, + @RequestHeader("OS") final String os); + + @PostMapping("/app") + @Operation( + summary = "스크린타임 설정할 앱을 추가하는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지 정보 조회에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderAddApps(@UserId @Parameter(hidden = true) Long userId, + @RequestHeader("OS") String os, + @RequestBody ChallengeAppArrayRequest requests); + + @GetMapping("/app") + @Operation( + summary = "스크린타임 설정한 앱을 삭제하는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지 정보 조회에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderRemoveApp(@UserId Long userId, + @RequestHeader("OS") String os, + @RequestBody AppRemoveRequest 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 deleted file mode 100644 index a9e33528..00000000 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java +++ /dev/null @@ -1,87 +0,0 @@ -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.*; -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.exception.ChallengeSuccess; -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.ChallengeFacade; -import sopt.org.hmh.global.auth.UserId; -import sopt.org.hmh.global.common.response.BaseResponse; -import sopt.org.hmh.global.common.response.EmptyJsonResponse; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/v2/challenge") -public class ChallengeController implements ChallengeApi { - - private final ChallengeFacade challengeFacade; - - @PostMapping - @Override - public ResponseEntity> orderAddChallenge( - @UserId final Long userId, - @RequestHeader("OS") final String os, - @RequestBody @Valid final ChallengeRequest request) { - challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os); - - return ResponseEntity - .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(ChallengeSuccess.ADD_CHALLENGE_SUCCESS, new EmptyJsonResponse())); - } - - @GetMapping - @Override - 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, - challengeFacade.getCurrentChallengeInfo(userId))); - } - - @GetMapping("/home") - @Override - 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, - challengeFacade.getDailyChallengeInfo(userId))); - } - - @PostMapping("/app") - @Override - 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 - .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse())); - - } - - @DeleteMapping("/app") - @Override - 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 - .status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse())); - } -} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 6d5d77a4..9ab54231 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -19,13 +19,13 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/challenge") -public class ChallengeControllerDeprecated implements ChallengeApi { +public class ChallengeControllerDeprecated implements ChallengeApiDeprecated { private final ChallengeFacade challengeFacade; @PostMapping @Override - public ResponseEntity> orderAddChallenge( + public ResponseEntity> orderAddChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeRequest request) { @@ -60,7 +60,7 @@ public ResponseEntity> orderGetDailyChallen @PostMapping("/app") @Override - public ResponseEntity> orderAddApps( + public ResponseEntity> orderAddApps( @UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeAppArrayRequest requests) { @@ -74,7 +74,7 @@ public ResponseEntity> orderAddApps( @DeleteMapping("/app") @Override - public ResponseEntity> orderRemoveApp( + public ResponseEntity> orderRemoveApp( @UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final AppRemoveRequest request) { From 3cb5567c7a09a775e9ae6b48a4a60dbfde30c206 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 20:58:50 +0900 Subject: [PATCH 03/41] =?UTF-8?q?modify=20-=20#175=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Controller=20=EC=BD=94=EB=93=9C=EB=A5=BC=20Deprecated=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=9B=84=20v2=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChallengeController.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java 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 new file mode 100644 index 00000000..a381e659 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeController.java @@ -0,0 +1,88 @@ +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.*; +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.exception.ChallengeSuccess; +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.ChallengeFacade; +import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v2/challenge") +public class ChallengeController implements ChallengeApi { + + private final ChallengeFacade challengeFacade; + + @PostMapping + @Override + public ResponseEntity> orderAddChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestHeader("Time-Zone") final String timeZone, + @RequestBody @Valid final ChallengeRequest request) { + challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os); + + return ResponseEntity + .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(ChallengeSuccess.ADD_CHALLENGE_SUCCESS, new EmptyJsonResponse())); + } + + @GetMapping + @Override + 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, + challengeFacade.getCurrentChallengeInfo(userId))); + } + + @GetMapping("/home") + @Override + 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, + challengeFacade.getDailyChallengeInfo(userId))); + } + + @PostMapping("/app") + @Override + 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 + .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse())); + + } + + @DeleteMapping("/app") + @Override + 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 + .status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse())); + } +} \ No newline at end of file From 505c8469e526bf0f794846373c19fc903854a8b2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 21:00:38 +0900 Subject: [PATCH 04/41] =?UTF-8?q?modify=20-=20#175=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EC=97=90=20@Deprecated=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/controller/ChallengeControllerDeprecated.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 9ab54231..6f7f0293 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -25,6 +25,7 @@ public class ChallengeControllerDeprecated implements ChallengeApiDeprecated { @PostMapping @Override + @Deprecated public ResponseEntity> orderAddChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, @@ -38,6 +39,7 @@ public ResponseEntity> orderAddChallenge( @GetMapping @Override + @Deprecated public ResponseEntity> orderGetChallenge( @UserId final Long userId, @RequestHeader("OS") final String os) { @@ -49,6 +51,7 @@ public ResponseEntity> orderGetChallenge( @GetMapping("/home") @Override + @Deprecated public ResponseEntity> orderGetDailyChallenge( @UserId final Long userId, @RequestHeader("OS") final String os) { @@ -60,6 +63,7 @@ public ResponseEntity> orderGetDailyChallen @PostMapping("/app") @Override + @Deprecated public ResponseEntity> orderAddApps( @UserId final Long userId, @RequestHeader("OS") final String os, @@ -74,6 +78,7 @@ public ResponseEntity> orderAddApps( @DeleteMapping("/app") @Override + @Deprecated public ResponseEntity> orderRemoveApp( @UserId final Long userId, @RequestHeader("OS") final String os, From 63e78bbf5268c39f24c0a5caf851e75a97a56917 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 21:03:38 +0900 Subject: [PATCH 05/41] =?UTF-8?q?feat=20-=20#175=20Challenge=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=97=90=20startDate=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/domain/challenge/domain/Challenge.java | 8 ++++++-- 1 file changed, 6 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 a33a1f61..53ce7817 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 @@ -4,6 +4,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.LocalDate; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -11,7 +12,6 @@ import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.global.common.domain.BaseTimeEntity; import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; -import java.util.ArrayList; import java.util.List; @Entity @@ -32,6 +32,9 @@ public class Challenge extends BaseTimeEntity { @NotNull(message = "목표 시간은 null일 수 없습니다.") private Long goalTime; + @NotNull(message = "시작 날짜는 null일 수 없습니다.") + private LocalDate startDate; + @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true) private List apps; @@ -39,10 +42,11 @@ public class Challenge extends BaseTimeEntity { private List historyDailyChallenges; @Builder - private Challenge(Integer period, Long userId, Long goalTime, List apps) { + private Challenge(Integer period, Long userId, Long goalTime, List apps, LocalDate startDate) { this.period = period; this.userId = userId; this.goalTime = goalTime; this.apps = apps; + this.startDate = startDate; } } \ No newline at end of file From 1fee966dc3ee274b91cc79d3ff7481eece191758 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 22:22:58 +0900 Subject: [PATCH 06/41] =?UTF-8?q?feat=20-=20#175=20dailyChallenge=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=8B=9C=20challenge=EC=9D=98=20startDate?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=B4=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dailychallenge/service/DailyChallengeService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 1932deeb..c2e10421 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 @@ -45,14 +45,18 @@ private void handleAlreadyProcessedDailyChallenge(DailyChallenge dailyChallenge) } public void addDailyChallenge(Long userId, Challenge challenge) { - LocalDate startDate = challenge.getCreatedAt().toLocalDate(); // TODO: startDate CreatedAt에서 가져오지 않고 새로 만들기 - dailyChallengeRepository.saveAll(IntStream.range(0, challenge.getPeriod()) + dailyChallengeRepository.saveAll(createDailyChallengeByChallengePeriod(userId, challenge)); + } + + private List createDailyChallengeByChallengePeriod(Long userId, Challenge challenge) { + LocalDate startDate = challenge.getStartDate(); + return IntStream.range(0, challenge.getPeriod()) .mapToObj(i -> DailyChallenge.builder() .challengeDate(startDate.plusDays(i)) .challenge(challenge) .userId(userId) .goalTime(challenge.getGoalTime()).build()) - .toList()); + .toList(); } public List getDailyChallengesByChallengeId(Long challengeId) { From 06e0c8839beb2d86a363a9de76e575e867ecfc54 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 17 Jul 2024 22:24:55 +0900 Subject: [PATCH 07/41] =?UTF-8?q?feat=20-=20#175=20dailyChallenge=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=8B=9C=20userId=EB=A5=BC=20challenge=20?= =?UTF-8?q?=EA=B0=92=EC=97=90=EC=84=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=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/domain/challenge/service/ChallengeFacade.java | 4 ++-- .../dailychallenge/service/DailyChallengeService.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 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 64fd461a..9665bb08 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 @@ -38,7 +38,7 @@ public void startNewChallengeByPreviousChallenge(Long userId, ChallengeRequest c Challenge newChallenge = challengeService.addChallengeAndUpdateUserCurrentChallenge( challengeRequest.toEntity(userId), user); - dailyChallengeService.addDailyChallenge(userId, newChallenge); + dailyChallengeService.addDailyChallenge(newChallenge); challengeAppService.addAppsByPreviousChallengeApp(os, previousChallengeId, newChallenge); } @@ -51,7 +51,7 @@ public void startFirstChallengeWithChallengeSignUpRequest( Challenge newChallenge = challengeService.addChallengeAndUpdateUserCurrentChallenge( challengeSignUpRequest.toChallengeRequest().toEntity(userId), user); - dailyChallengeService.addDailyChallenge(userId, newChallenge); + dailyChallengeService.addDailyChallenge(newChallenge); challengeAppService.addApps( challengeSignUpRequest.apps().stream() 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 c2e10421..66b5de9c 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java @@ -44,12 +44,13 @@ private void handleAlreadyProcessedDailyChallenge(DailyChallenge dailyChallenge) throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED); } - public void addDailyChallenge(Long userId, Challenge challenge) { - dailyChallengeRepository.saveAll(createDailyChallengeByChallengePeriod(userId, challenge)); + public void addDailyChallenge(Challenge challenge) { + dailyChallengeRepository.saveAll(createDailyChallengeByChallengePeriod(challenge)); } - private List createDailyChallengeByChallengePeriod(Long userId, Challenge challenge) { + private List createDailyChallengeByChallengePeriod(Challenge challenge) { LocalDate startDate = challenge.getStartDate(); + Long userId = challenge.getUserId(); return IntStream.range(0, challenge.getPeriod()) .mapToObj(i -> DailyChallenge.builder() .challengeDate(startDate.plusDays(i)) From 73e9eb251d7f9c0f1d440d5a946c1e95ca1abd94 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 14:33:56 +0900 Subject: [PATCH 08/41] =?UTF-8?q?modify=20-=20#175=20DailyChallengeRespons?= =?UTF-8?q?e=EC=9D=98=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 --- .../challenge/dto/response/DailyChallengeResponse.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/response/DailyChallengeResponse.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/response/DailyChallengeResponse.java index 35e4ef40..7a47e49c 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/response/DailyChallengeResponse.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/response/DailyChallengeResponse.java @@ -1,5 +1,6 @@ package sopt.org.hmh.domain.challenge.dto.response; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; import sopt.org.hmh.domain.dailychallenge.domain.Status; @@ -8,8 +9,8 @@ @Builder public record DailyChallengeResponse( - Status status, - Long goalTime, + @NotNull(message = "상태 값은 null일 수 없습니다.") Status status, + @NotNull(message = "목표시간은 null일 수 없습니다.") Long goalTime, List apps ) { } \ No newline at end of file From 76b5b4ee04113a39a34ba2c6166630399ae14f0b Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 15:48:27 +0900 Subject: [PATCH 09/41] =?UTF-8?q?refactor=20-=20#175=20challengeRepository?= =?UTF-8?q?=20=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ChallengeJpaRepository.java | 15 ++++++++++ .../repository/ChallengeRepository.java | 4 +-- .../repository/ChallengeRepositoryImpl.java | 29 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeJpaRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java diff --git a/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeJpaRepository.java b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeJpaRepository.java new file mode 100644 index 00000000..452aaeb0 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeJpaRepository.java @@ -0,0 +1,15 @@ +package sopt.org.hmh.domain.challenge.repository; + +import java.util.List; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import sopt.org.hmh.domain.challenge.domain.Challenge; + +public interface ChallengeJpaRepository extends JpaRepository { + + Optional findById(Long id); + + void deleteByUserIdIn(List userId); + + void deleteByUserId(Long 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 1126f585..996aac8e 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 @@ -2,11 +2,9 @@ import java.util.List; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; import sopt.org.hmh.domain.challenge.domain.Challenge; -public interface ChallengeRepository extends JpaRepository { - +public interface ChallengeRepository { Optional findById(Long id); void deleteByUserIdIn(List userId); diff --git a/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java new file mode 100644 index 00000000..075eecd6 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java @@ -0,0 +1,29 @@ +package sopt.org.hmh.domain.challenge.repository; + +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import sopt.org.hmh.domain.challenge.domain.Challenge; + +@Repository +@RequiredArgsConstructor +public class ChallengeRepositoryImpl implements ChallengeRepository{ + + private final ChallengeJpaRepository challengeJpaRepository; + + @Override + public Optional findById(Long id) { + return challengeJpaRepository.findById(id); + } + + @Override + public void deleteByUserIdIn(List userId) { + challengeJpaRepository.deleteByUserIdIn(userId); + } + + @Override + public void deleteByUserId(Long userId) { + challengeJpaRepository.deleteByUserId(userId); + } +} From a0dbbc2240f2f5413264b831f5e9673c5d2b7236 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:01:29 +0900 Subject: [PATCH 10/41] =?UTF-8?q?modify=20-=20#175=20Controller=EC=97=90?= =?UTF-8?q?=EC=84=9C=20NewChallengeOrder=20dto=EB=A5=BC=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EC=96=B4=20=EC=84=9C=EB=B9=84=EC=8A=A4=EB=A5=BC=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../challenge/controller/ChallengeApi.java | 14 +++-- .../controller/ChallengeApiDeprecated.java | 28 ++++------ .../controller/ChallengeController.java | 11 ++-- .../ChallengeControllerDeprecated.java | 10 ++-- .../challenge/dto/NewChallengeOrder.java | 53 +++++++++++++++++++ 5 files changed, 80 insertions(+), 36 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java index b9c6533b..b3819167 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java @@ -13,7 +13,6 @@ 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.global.auth.UserId; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -59,8 +58,7 @@ ResponseEntity> orderAddChallenge( description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderGetChallenge( - @UserId @Parameter(hidden = true) final Long userId, - @RequestHeader("OS") final String os); + @Parameter(hidden = true) final Long userId); @GetMapping("/home") @Operation( @@ -78,10 +76,8 @@ ResponseEntity> orderGetChallenge( description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderGetDailyChallenge( - @UserId @Parameter(hidden = true) final Long userId, - @RequestHeader("OS") final String os); + @Parameter(hidden = true) final Long userId); - @PostMapping("/app") @Operation( summary = "스크린타임 설정할 앱을 추가하는 API", responses = { @@ -96,7 +92,8 @@ ResponseEntity> orderGetDailyChallenge( responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderAddApps(@UserId @Parameter(hidden = true) Long userId, + ResponseEntity> orderAddApps( + @Parameter(hidden = true) Long userId, @RequestHeader("OS") String os, @RequestBody ChallengeAppArrayRequest requests); @@ -115,7 +112,8 @@ ResponseEntity> orderAddApps(@UserId @Parameter( responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderRemoveApp(@UserId Long userId, + ResponseEntity> orderRemoveApp( + @Parameter(hidden = true)Long userId, @RequestHeader("OS") String os, @RequestBody AppRemoveRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java index 3475430c..a6105d9b 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java @@ -13,7 +13,6 @@ 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.global.auth.UserId; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -22,7 +21,6 @@ @SecurityRequirement(name = JwtConstants.AUTHORIZATION) public interface ChallengeApiDeprecated { - @PostMapping @Operation( summary = "챌린지가 끝난 후 새 챌린지 생성하는 API", responses = { @@ -38,11 +36,10 @@ public interface ChallengeApiDeprecated { description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderAddChallenge( - @UserId @Parameter(hidden = true) final Long userId, + @Parameter(hidden = true) final Long userId, @RequestHeader("OS") final String os, @RequestBody final ChallengeRequest request); - @GetMapping @Operation( summary = "달성현황뷰 챌린지 정보를 불러오는 API", responses = { @@ -58,10 +55,8 @@ ResponseEntity> orderAddChallenge( description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderGetChallenge( - @UserId @Parameter(hidden = true) final Long userId, - @RequestHeader("OS") final String os); + @Parameter(hidden = true) final Long userId); - @GetMapping("/home") @Operation( summary = "이용시간 통계 정보를 불러오는 API", responses = { @@ -77,10 +72,8 @@ ResponseEntity> orderGetChallenge( description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderGetDailyChallenge( - @UserId @Parameter(hidden = true) final Long userId, - @RequestHeader("OS") final String os); + @Parameter(hidden = true) final Long userId); - @PostMapping("/app") @Operation( summary = "스크린타임 설정할 앱을 추가하는 API", responses = { @@ -95,11 +88,11 @@ ResponseEntity> orderGetDailyChallenge( responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderAddApps(@UserId @Parameter(hidden = true) Long userId, - @RequestHeader("OS") String os, - @RequestBody ChallengeAppArrayRequest requests); + ResponseEntity> orderAddApps( + @Parameter(hidden = true) Long userId, + @RequestHeader("OS") String os, + @RequestBody ChallengeAppArrayRequest requests); - @GetMapping("/app") @Operation( summary = "스크린타임 설정한 앱을 삭제하는 API", responses = { @@ -114,8 +107,9 @@ ResponseEntity> orderAddApps(@UserId @Parameter( responseCode = "500", description = "서버 내부 오류입니다.", content = @Content)}) - ResponseEntity> orderRemoveApp(@UserId Long userId, - @RequestHeader("OS") String os, - @RequestBody AppRemoveRequest request); + ResponseEntity> orderRemoveApp( + @Parameter(hidden = true) Long userId, + @RequestHeader("OS") String os, + @RequestBody AppRemoveRequest 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 a381e659..eeed2962 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,7 @@ package sopt.org.hmh.domain.challenge.controller; +import static sopt.org.hmh.domain.challenge.dto.NewChallengeOrder.createNextChallengeOrder; + import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -30,8 +32,7 @@ public ResponseEntity> orderAddChallenge( @RequestHeader("OS") final String os, @RequestHeader("Time-Zone") final String timeZone, @RequestBody @Valid final ChallengeRequest request) { - challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os); - + challengeFacade.startNewChallenge(createNextChallengeOrder(request, userId, os, timeZone)); return ResponseEntity .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.ADD_CHALLENGE_SUCCESS, new EmptyJsonResponse())); @@ -40,8 +41,7 @@ public ResponseEntity> orderAddChallenge( @GetMapping @Override public ResponseEntity> orderGetChallenge( - @UserId final Long userId, - @RequestHeader("OS") final String os) { + @UserId final Long userId) { return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, @@ -51,8 +51,7 @@ public ResponseEntity> orderGetChallenge( @GetMapping("/home") @Override public ResponseEntity> orderGetDailyChallenge( - @UserId final Long userId, - @RequestHeader("OS") final String os) { + @UserId final Long userId) { return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 6f7f0293..607587a3 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -1,5 +1,7 @@ package sopt.org.hmh.domain.challenge.controller; +import static sopt.org.hmh.domain.challenge.dto.NewChallengeOrder.createNextChallengeOrder; + import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -30,7 +32,7 @@ public ResponseEntity> orderAddChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, @RequestBody @Valid final ChallengeRequest request) { - challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os); + challengeFacade.startNewChallenge(createNextChallengeOrder(request, userId, os, "Asia/Seoul")); return ResponseEntity .status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus()) @@ -41,8 +43,7 @@ public ResponseEntity> orderAddChallenge( @Override @Deprecated public ResponseEntity> orderGetChallenge( - @UserId final Long userId, - @RequestHeader("OS") final String os) { + @UserId final Long userId) { return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, @@ -53,8 +54,7 @@ public ResponseEntity> orderGetChallenge( @Override @Deprecated public ResponseEntity> orderGetDailyChallenge( - @UserId final Long userId, - @RequestHeader("OS") final String os) { + @UserId final Long userId) { return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java new file mode 100644 index 00000000..f9ca0cce --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java @@ -0,0 +1,53 @@ +package sopt.org.hmh.domain.challenge.dto; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import sopt.org.hmh.domain.app.domain.ChallengeApp; +import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; +import sopt.org.hmh.domain.challenge.domain.Challenge; +import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class NewChallengeOrder { + + private final ChallengeRequest challengeRequest; + private final List challengeAppRequests; + private final Long userId; + private final String os; + private final ZoneId zoneId; + private final boolean isFirstChallenge; + + public static NewChallengeOrder createFirstChallengeOrder( + ChallengeRequest challengeRequest, List challengeAppRequests, + Long userId, String os, String timeZone) { + return new NewChallengeOrder(challengeRequest, challengeAppRequests, + userId, os, ZoneId.of(timeZone), true); + } + + public static NewChallengeOrder createNextChallengeOrder( + ChallengeRequest challengeRequest, Long userId, String os, String timeZone + ) { + return new NewChallengeOrder( + challengeRequest, List.of(), userId, os, ZoneId.of(timeZone), false); + } + + public Challenge toChallengeEntity() { + return Challenge.builder() + .period(challengeRequest.period()) + .userId(userId) + .goalTime(challengeRequest.goalTime()) + .startDate(ZonedDateTime.now(zoneId).toLocalDate()) + .build(); + } + + public List toChallengeAppEntities(Challenge challenge) { + return challengeAppRequests.stream() + .map(challengeAppRequest -> challengeAppRequest.toEntity(challenge, os)) + .toList(); + } +} From 8fb5e4a5e41e25e1b866c86eaf3d5db5cb87d4ac Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:03:00 +0900 Subject: [PATCH 11/41] =?UTF-8?q?modify=20-=20#175=20of=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=B4=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BD=94=EB=93=9C=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=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 --- .../dto/response/ChallengeResponse.java | 24 +++++++ .../challenge/service/ChallengeFacade.java | 63 +++++-------------- 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java index 62406901..c5194b3c 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java @@ -1,7 +1,12 @@ package sopt.org.hmh.domain.challenge.dto.response; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import lombok.Builder; import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; +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 java.util.List; @@ -15,4 +20,23 @@ public record ChallengeResponse( Long goalTime, List apps ) { + public static ChallengeResponse of(Challenge challenge) { + return ChallengeResponse.builder() + .period(challenge.getPeriod()) + .statuses(challenge.getHistoryDailyChallenges() + .stream() + .map(DailyChallenge::getStatus) + .toList()) + .todayIndex(calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod())) + .startDate(challenge.getCreatedAt().toLocalDate().toString()) + .goalTime(challenge.getGoalTime()) + .apps(challenge.getApps().stream() + .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) + .build(); + } + + private static Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) { + int daysBetween = (int) ChronoUnit.DAYS.between(challengeCreateAt.toLocalDate(), LocalDate.now()); + return (daysBetween >= period) ? -1 : daysBetween; + } } \ No newline at end of file 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 9665bb08..0bdd8ecf 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 @@ -7,18 +7,12 @@ 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.request.ChallengeSignUpRequest; +import sopt.org.hmh.domain.challenge.dto.NewChallengeOrder; 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 @@ -31,51 +25,29 @@ public class ChallengeFacade { private final ChallengeAppService challengeAppService; @Transactional - public void startNewChallengeByPreviousChallenge(Long userId, ChallengeRequest challengeRequest, String os) { - User user = userService.findByIdOrThrowException(userId); - Long previousChallengeId = userService.getCurrentChallengeIdByUser(user); - - Challenge newChallenge = challengeService.addChallengeAndUpdateUserCurrentChallenge( - challengeRequest.toEntity(userId), user); + public void startNewChallenge(NewChallengeOrder newChallengeOrder) { + Challenge newChallenge = challengeService.addChallenge(newChallengeOrder.toChallengeEntity()); + userService.changeCurrentChallengeIdByUserId(newChallengeOrder.getUserId(), newChallenge.getId()); dailyChallengeService.addDailyChallenge(newChallenge); - challengeAppService.addAppsByPreviousChallengeApp(os, previousChallengeId, newChallenge); + this.addAppsByNewChallengeOrder(newChallengeOrder, newChallenge); } - @Transactional - public void startFirstChallengeWithChallengeSignUpRequest( - ChallengeSignUpRequest challengeSignUpRequest, User user, String os) { - Long userId = user.getId(); - - Challenge newChallenge = challengeService.addChallengeAndUpdateUserCurrentChallenge( - challengeSignUpRequest.toChallengeRequest().toEntity(userId), user); - - dailyChallengeService.addDailyChallenge(newChallenge); - - challengeAppService.addApps( - challengeSignUpRequest.apps().stream() - .map(challengeAppRequest -> challengeAppRequest.toEntity(newChallenge, os)) - .toList() - ); + private void addAppsByNewChallengeOrder(NewChallengeOrder newChallengeOrder, Challenge newChallenge) { + if (newChallengeOrder.isFirstChallenge()) { + challengeAppService.addApps(newChallengeOrder.toChallengeAppEntities(newChallenge)); + return; + } + Long previousChallengeId = userService.getCurrentChallengeIdByUserId(newChallengeOrder.getUserId()); + challengeAppService.addAppsByPreviousChallengeApp(newChallengeOrder.getOs(), previousChallengeId, newChallenge); + // TODO: userId를 이용해 previousChallengeId를 찾아서 그 ChallengeApp을 가져오는 로직을 join을 이용해 한 번에 처리하도록 변경 + // 그 후, challengeAppService로 메서드 책임 이전 } @Transactional(readOnly = true) public ChallengeResponse getCurrentChallengeInfo(Long userId) { - Challenge challenge = this.findCurrentChallengeByUserId(userId); - - return ChallengeResponse.builder() - .period(challenge.getPeriod()) - .statuses(challenge.getHistoryDailyChallenges() - .stream() - .map(DailyChallenge::getStatus) - .toList()) - .todayIndex(this.calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod())) - .startDate(challenge.getCreatedAt().toLocalDate().toString()) - .goalTime(challenge.getGoalTime()) - .apps(challenge.getApps().stream() - .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) - .build(); + return ChallengeResponse.of(this.findCurrentChallengeByUserId(userId)); } @Transactional(readOnly = true) @@ -94,11 +66,6 @@ public Challenge findCurrentChallengeByUserId(Long 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; - } - @Transactional public void addAppsToCurrentChallenge(Long userId, List requests, String os) { Challenge challenge = this.findCurrentChallengeByUserId(userId); From 4672741367b9f22c60ab4bd1597c31f406b8091b Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:03:44 +0900 Subject: [PATCH 12/41] =?UTF-8?q?refactor=20-=20#175=20user=EC=9D=98=20cur?= =?UTF-8?q?rentChallengeId=20=EB=B3=80=EA=B2=BD=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B1=85=EC=9E=84=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/challenge/service/ChallengeService.java | 7 ++----- 1 file changed, 2 insertions(+), 5 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 2576fea1..4c99eafc 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeService.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/service/ChallengeService.java @@ -8,7 +8,6 @@ import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; import sopt.org.hmh.domain.challenge.repository.ChallengeRepository; -import sopt.org.hmh.domain.user.domain.User; @Service @RequiredArgsConstructor @@ -33,10 +32,8 @@ public List getCurrentChallengeAppByChallengeId(Long challengeId) return this.findByIdOrElseThrow(challengeId).getApps(); } - public Challenge addChallengeAndUpdateUserCurrentChallenge(Challenge challenge, User user) { - Challenge newChallenge = challengeRepository.save(challenge); - user.changeCurrentChallengeId(newChallenge.getId()); - return newChallenge; + public Challenge addChallenge(Challenge challenge) { + return challengeRepository.save(challenge); } public Integer getChallengePeriod(Long challengeId) { From 01e9ef08dea59120d494c9b1e8fbe9012faea03d Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:03:53 +0900 Subject: [PATCH 13/41] =?UTF-8?q?refactor=20-=20#175=20repository=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/challenge/repository/ChallengeRepository.java | 2 ++ .../challenge/repository/ChallengeRepositoryImpl.java | 6 ++++++ 2 files changed, 8 insertions(+) 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 996aac8e..23972380 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 { void deleteByUserIdIn(List userId); void deleteByUserId(Long userId); + + Challenge save(Challenge challenge); } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java index 075eecd6..d4f69d3d 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/repository/ChallengeRepositoryImpl.java @@ -12,6 +12,11 @@ public class ChallengeRepositoryImpl implements ChallengeRepository{ private final ChallengeJpaRepository challengeJpaRepository; + @Override + public Challenge save(Challenge challenge) { + return challengeJpaRepository.save(challenge); + } + @Override public Optional findById(Long id) { return challengeJpaRepository.findById(id); @@ -26,4 +31,5 @@ public void deleteByUserIdIn(List userId) { public void deleteByUserId(Long userId) { challengeJpaRepository.deleteByUserId(userId); } + } From 387df5fe3f22177132f14f5513cbd9ccfc33bc43 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:10:29 +0900 Subject: [PATCH 14/41] =?UTF-8?q?refactor=20-=20#175=20currentChallengeId?= =?UTF-8?q?=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20=EB=A1=9C=EC=A7=81=EC=9D=84=20?= =?UTF-8?q?=EC=95=88=EC=A0=84=ED=95=9C=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/challenge/service/ChallengeFacade.java | 7 ++----- 1 file changed, 2 insertions(+), 5 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 0bdd8ecf..39646d6a 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 @@ -11,7 +11,6 @@ import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; 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.util.List; @@ -41,8 +40,6 @@ private void addAppsByNewChallengeOrder(NewChallengeOrder newChallengeOrder, Cha } Long previousChallengeId = userService.getCurrentChallengeIdByUserId(newChallengeOrder.getUserId()); challengeAppService.addAppsByPreviousChallengeApp(newChallengeOrder.getOs(), previousChallengeId, newChallenge); - // TODO: userId를 이용해 previousChallengeId를 찾아서 그 ChallengeApp을 가져오는 로직을 join을 이용해 한 번에 처리하도록 변경 - // 그 후, challengeAppService로 메서드 책임 이전 } @Transactional(readOnly = true) @@ -62,8 +59,8 @@ public DailyChallengeResponse getDailyChallengeInfo(Long userId) { } public Challenge findCurrentChallengeByUserId(Long userId) { - User user = userService.findByIdOrThrowException(userId); - return challengeService.findByIdOrElseThrow(user.getCurrentChallengeId()); + Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); + return challengeService.findByIdOrElseThrow(currentChallengeId); } @Transactional From 039e56297c9cc6534790d85b47fed2a38dfb70d0 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:10:43 +0900 Subject: [PATCH 15/41] =?UTF-8?q?refactor=20-=20#175=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20this=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 --- .../sopt/org/hmh/domain/challenge/service/ChallengeService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4c99eafc..1a986df7 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 @@ -37,6 +37,6 @@ public Challenge addChallenge(Challenge challenge) { } public Integer getChallengePeriod(Long challengeId) { - return findByIdOrElseThrow(challengeId).getPeriod(); + return this.findByIdOrElseThrow(challengeId).getPeriod(); } } From be21c0b4c8ecd6d0baaf9eb1a218b9124592f5e2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:11:36 +0900 Subject: [PATCH 16/41] =?UTF-8?q?refactor=20-=20#175=20=ED=98=84=EC=9E=AC?= =?UTF-8?q?=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20id=EB=A5=BC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=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/service/UserService.java | 5 ++--- 1 file changed, 2 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 3c9bf910..263d8bab 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 @@ -106,9 +106,8 @@ public Long getCurrentChallengeIdByUserId(Long userId) { .orElseThrow(() -> new UserException(UserError.NOT_FOUND_CURRENT_CHALLENGE_ID)); } - public Long getCurrentChallengeIdByUser(User user) { - return Optional.ofNullable(user.getCurrentChallengeId()) - .orElseThrow(() -> new ChallengeException(ChallengeError.CHALLENGE_NOT_FOUND)); + public void changeCurrentChallengeIdByUserId(Long userId, Long challengeId) { + this.findByIdOrThrowException(userId).changeCurrentChallengeId(challengeId); } @Transactional From f3f4737d4e0a6e7023a66c6fce2fd72299318ee4 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:43:34 +0900 Subject: [PATCH 17/41] =?UTF-8?q?feat=20-=20#175=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20v2=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/auth/controller/AuthApi.java | 17 +++++-- .../auth/controller/AuthController.java | 44 ++++++++++++++----- .../hmh/domain/auth/service/AuthFacade.java | 8 +++- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/auth/controller/AuthApi.java b/src/main/java/sopt/org/hmh/domain/auth/controller/AuthApi.java index 77878853..fb41a48f 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/controller/AuthApi.java +++ b/src/main/java/sopt/org/hmh/domain/auth/controller/AuthApi.java @@ -9,7 +9,8 @@ import org.springframework.web.bind.annotation.RequestHeader; import sopt.org.hmh.domain.auth.dto.request.SocialPlatformRequest; import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest; -import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.domain.auth.dto.response.LoginResponse; +import sopt.org.hmh.domain.auth.dto.response.ReissueResponse; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.common.response.BaseResponse; @@ -18,20 +19,28 @@ public interface AuthApi { @Operation(summary = "소셜 로그인") - ResponseEntity> orderLogin( + ResponseEntity> orderLogin( @Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, @RequestBody final SocialPlatformRequest request ); @Operation(summary = "회원 가입") - ResponseEntity> orderSignup( + ResponseEntity> orderSignupDeprecated( @Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, @RequestHeader("OS") final String os, @RequestBody final SocialSignUpRequest request ); + @Operation(summary = "회원 가입 V2") + ResponseEntity> orderSignup( + @Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, + @RequestHeader("OS") final String os, + @RequestHeader("Time-Zone") final String timeZone, + @RequestBody final SocialSignUpRequest request + ); + @Operation(summary = "토큰 재발급") - ResponseEntity> orderReissue( + ResponseEntity> orderReissue( @Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String refreshToken ); } 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 39a86dcd..6187908b 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 @@ -10,24 +10,27 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import sopt.org.hmh.domain.auth.dto.response.LoginResponse; +import sopt.org.hmh.domain.auth.dto.response.ReissueResponse; 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.AuthFacade; +import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.auth.social.SocialAccessTokenResponse; import sopt.org.hmh.global.common.response.BaseResponse; @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/user") +@RequestMapping("/api") public class AuthController implements AuthApi { private final AuthFacade authFacade; - @PostMapping("/login") + @PostMapping("/v1/user/login") @Override - public ResponseEntity> orderLogin( - @RequestHeader("Authorization") final String socialAccessToken, + public ResponseEntity> orderLogin( + @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, @RequestBody final SocialPlatformRequest request ) { return ResponseEntity @@ -38,10 +41,11 @@ public ResponseEntity> orderLogin( )); } - @PostMapping("/signup") @Override - public ResponseEntity> orderSignup( - @RequestHeader("Authorization") final String socialAccessToken, + @Deprecated + @PostMapping("/v1/user/signup") + public ResponseEntity> orderSignupDeprecated( + @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, @RequestHeader("OS") final String os, @RequestBody @Valid final SocialSignUpRequest request ) { @@ -49,14 +53,30 @@ public ResponseEntity> orderSignup( .status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus()) .body(BaseResponse.success( AuthSuccess.SIGNUP_SUCCESS, - authFacade.signup(request, socialAccessToken, os) + authFacade.signup(request, socialAccessToken, os, "Asia/Seoul") )); } - @PostMapping("/reissue") @Override - public ResponseEntity> orderReissue( - @RequestHeader("Authorization") final String refreshToken + @PostMapping("/v2/user/signup") + public ResponseEntity> orderSignup( + @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, + @RequestHeader("OS") final String os, + @RequestHeader("Time-Zone") final String timeZone, + @RequestBody @Valid final SocialSignUpRequest request + ) { + return ResponseEntity + .status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success( + AuthSuccess.SIGNUP_SUCCESS, + authFacade.signup(request, socialAccessToken, os, timeZone) + )); + } + + @Override + @PostMapping("/v1/user/reissue") + public ResponseEntity> orderReissue( + @RequestHeader(JwtConstants.AUTHORIZATION) final String refreshToken ) { return ResponseEntity .status(AuthSuccess.REISSUE_SUCCESS.getHttpStatus()) @@ -66,7 +86,7 @@ public ResponseEntity> orderReissue( )); } - @GetMapping("/social/token/kakao") + @GetMapping("/v1/user/social/token/kakao") public ResponseEntity> orderGetKakaoAccessToken( @RequestParam("code") final String code ) { 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 d52f691d..f3658be7 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 @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import sopt.org.hmh.domain.auth.dto.response.ReissueResponse; +import sopt.org.hmh.domain.challenge.dto.request.NewChallengeOrder; import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest; @@ -36,7 +37,7 @@ public LoginResponse login(String socialAccessToken, SocialPlatform socialPlatfo } @Transactional - public LoginResponse signup(SocialSignUpRequest request, String socialAccessToken, String os) { + public LoginResponse signup(SocialSignUpRequest request, String socialAccessToken, String os, String timeZone) { SocialPlatform socialPlatform = request.socialPlatform(); String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken); @@ -45,7 +46,10 @@ public LoginResponse signup(SocialSignUpRequest request, String socialAccessToke userService.registerOnboardingInfo(request, newUserId); - challengeFacade.startFirstChallengeWithChallengeSignUpRequest(request.challenge(), newUser , os); + challengeFacade.startNewChallenge(NewChallengeOrder.createFirstChallengeOrder( + request.challenge().toChallengeRequest(), request.challenge().apps(), + newUserId, os, timeZone + )); return performLogin(newUser, socialAccessToken, socialPlatform); } From aaadf6a939ab86fe41a6fe4628a15a09b2ccbc30 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 16:46:06 +0900 Subject: [PATCH 18/41] =?UTF-8?q?feat=20-=20#175=20=ED=99=88=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=EC=8B=9C=EA=B0=84=20=ED=86=B5=EA=B3=84=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=A4=20v2=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/controller/ChallengeApi.java | 3 ++- .../controller/ChallengeController.java | 7 ++++--- .../ChallengeControllerDeprecated.java | 4 ++-- .../challenge/service/ChallengeFacade.java | 16 +++++++++++++--- .../service/DailyChallengeFacade.java | 4 ++-- .../service/DailyChallengeService.java | 9 ++++++++- .../hmh/domain/point/service/PointFacade.java | 4 ++-- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java index b3819167..5e76b330 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java @@ -76,7 +76,8 @@ ResponseEntity> orderGetChallenge( description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderGetDailyChallenge( - @Parameter(hidden = true) final Long userId); + @Parameter(hidden = true) final Long userId, + @RequestHeader final String timeZone); @Operation( summary = "스크린타임 설정할 앱을 추가하는 API", 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 eeed2962..173bd59f 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,6 +1,6 @@ package sopt.org.hmh.domain.challenge.controller; -import static sopt.org.hmh.domain.challenge.dto.NewChallengeOrder.createNextChallengeOrder; +import static sopt.org.hmh.domain.challenge.dto.request.NewChallengeOrder.createNextChallengeOrder; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -51,11 +51,12 @@ public ResponseEntity> orderGetChallenge( @GetMapping("/home") @Override public ResponseEntity> orderGetDailyChallenge( - @UserId final Long userId) { + @UserId final Long userId, + @RequestHeader final String timeZone) { return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, - challengeFacade.getDailyChallengeInfo(userId))); + challengeFacade.getDailyChallengeInfo(userId, timeZone))); } @PostMapping("/app") diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 607587a3..c3ae3682 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -1,6 +1,6 @@ package sopt.org.hmh.domain.challenge.controller; -import static sopt.org.hmh.domain.challenge.dto.NewChallengeOrder.createNextChallengeOrder; +import static sopt.org.hmh.domain.challenge.dto.request.NewChallengeOrder.createNextChallengeOrder; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -58,7 +58,7 @@ public ResponseEntity> orderGetDailyChallen return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, - challengeFacade.getDailyChallengeInfo(userId))); + challengeFacade.getDailyChallengeInfo(userId, "Asia/Seoul"))); } @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 39646d6a..bf4e8e88 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,7 @@ package sopt.org.hmh.domain.challenge.service; +import java.time.LocalDate; +import java.time.ZoneId; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -7,9 +9,10 @@ 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.NewChallengeOrder; +import sopt.org.hmh.domain.challenge.dto.request.NewChallengeOrder; 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.service.UserService; import java.util.List; @@ -48,13 +51,20 @@ public ChallengeResponse getCurrentChallengeInfo(Long userId) { } @Transactional(readOnly = true) - public DailyChallengeResponse getDailyChallengeInfo(Long userId) { + public DailyChallengeResponse getDailyChallengeInfo(Long userId, String timeZone) { Challenge challenge = this.findCurrentChallengeByUserId(userId); + LocalDate localDateNow = LocalDate.now(ZoneId.of(timeZone)); + DailyChallenge todayChallenge = + dailyChallengeService.findDailyChallengeByChallengeAndChallengeDate(challenge, localDateNow); return DailyChallengeResponse.builder() + .status(todayChallenge.getStatus()) .goalTime(challenge.getGoalTime()) .apps(challenge.getApps().stream() - .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) + .map(challengeApp -> new ChallengeAppResponse( + challengeApp.getAppCode(), + challengeApp.getGoalTime() + )).toList()) .build(); } 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 b4ba716e..eb227178 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 @@ -30,7 +30,7 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge requests.finishedDailyChallenges().forEach(request -> { DailyChallenge dailyChallenge = - dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(request.challengeDate(), userId); dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); }); @@ -40,7 +40,7 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { requests.finishedDailyChallenges().forEach(request -> { DailyChallenge dailyChallenge = - dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(request.challengeDate(), userId); if (request.isSuccess()) { dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); dailyChallenge.changeStatus(Status.UNEARNED); 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 66b5de9c..f5aa4d85 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 @@ -18,11 +18,18 @@ public class DailyChallengeService { private final DailyChallengeRepository dailyChallengeRepository; - public DailyChallenge findByChallengeDateAndUserIdOrThrowException(LocalDate challengeDate, Long userId) { + public DailyChallenge findDailyChallengeByChallengeDateAndUserIdOrElseThrow(LocalDate challengeDate, Long userId) { return dailyChallengeRepository.findByChallengeDateAndUserId(challengeDate, userId) .orElseThrow(() -> new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_NOT_FOUND)); } + public DailyChallenge findDailyChallengeByChallengeAndChallengeDate(Challenge challenge, LocalDate challengeDate) { + return challenge.getHistoryDailyChallenges().stream() + .filter(dailyChallenge -> dailyChallenge.getChallengeDate().equals(challengeDate)) + .findFirst() + .orElseThrow(() -> new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_NOT_FOUND)); + } + public void validateDailyChallengeStatus(Status dailyChallengeStatus, List expectedStatuses) { if (!expectedStatuses.contains(dailyChallengeStatus)) { throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED); 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 295caa80..c9c54f3b 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 @@ -27,7 +27,7 @@ public class PointFacade { @Transactional public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challengeDate) { DailyChallenge dailyChallenge = - dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(challengeDate, userId); User user = userService.findByIdOrThrowException(userId); dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); @@ -42,7 +42,7 @@ public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challe @Transactional public EarnPointResponse earnPointAndChallengeEarned(Long userId, LocalDate challengeDate) { DailyChallenge dailyChallenge = - dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId); + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(challengeDate, userId); User user = userService.findByIdOrThrowException(userId); dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.UNEARNED)); From d48c64f104ed409e852fe0b65a0077ec4d0d241a Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:06:44 +0900 Subject: [PATCH 19/41] =?UTF-8?q?feat=20-=20#175=20=EB=8B=AC=EC=84=B1?= =?UTF-8?q?=ED=98=84=ED=99=A9=20=EC=A0=95=EB=B3=B4=20=EB=B6=88=EB=9F=AC?= =?UTF-8?q?=EC=98=A4=EA=B8=B0=20v2=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/controller/ChallengeApi.java | 7 ++----- .../controller/ChallengeController.java | 15 ++++++++------- .../ChallengeControllerDeprecated.java | 2 +- .../dto/{ => request}/NewChallengeOrder.java | 7 +++---- .../dto/response/ChallengeResponse.java | 17 +++++++++-------- .../challenge/service/ChallengeFacade.java | 5 +++-- 6 files changed, 26 insertions(+), 27 deletions(-) rename src/main/java/sopt/org/hmh/domain/challenge/dto/{ => request}/NewChallengeOrder.java (89%) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java index 5e76b330..806249de 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java @@ -21,7 +21,6 @@ @SecurityRequirement(name = JwtConstants.AUTHORIZATION) public interface ChallengeApi { - @PostMapping @Operation( summary = "챌린지가 끝난 후 새 챌린지 생성하는 API", responses = { @@ -42,7 +41,6 @@ ResponseEntity> orderAddChallenge( final String timeZone, final ChallengeRequest request); - @GetMapping @Operation( summary = "달성현황뷰 챌린지 정보를 불러오는 API", responses = { @@ -58,9 +56,9 @@ ResponseEntity> orderAddChallenge( description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderGetChallenge( - @Parameter(hidden = true) final Long userId); + @Parameter(hidden = true) final Long userId, + @RequestHeader final String timeZone); - @GetMapping("/home") @Operation( summary = "이용시간 통계 정보를 불러오는 API", responses = { @@ -98,7 +96,6 @@ ResponseEntity> orderAddApps( @RequestHeader("OS") String os, @RequestBody ChallengeAppArrayRequest requests); - @GetMapping("/app") @Operation( summary = "스크린타임 설정한 앱을 삭제하는 API", responses = { 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 173bd59f..3a00b09e 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,8 +25,8 @@ public class ChallengeController implements ChallengeApi { private final ChallengeFacade challengeFacade; - @PostMapping @Override + @PostMapping public ResponseEntity> orderAddChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, @@ -38,18 +38,19 @@ public ResponseEntity> orderAddChallenge( .body(BaseResponse.success(ChallengeSuccess.ADD_CHALLENGE_SUCCESS, new EmptyJsonResponse())); } - @GetMapping @Override + @GetMapping public ResponseEntity> orderGetChallenge( - @UserId final Long userId) { + @UserId final Long userId, + @RequestHeader final String timeZone) { return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, - challengeFacade.getCurrentChallengeInfo(userId))); + challengeFacade.getCurrentChallengeInfo(userId, timeZone))); } - @GetMapping("/home") @Override + @GetMapping("/home") public ResponseEntity> orderGetDailyChallenge( @UserId final Long userId, @RequestHeader final String timeZone) { @@ -59,8 +60,8 @@ public ResponseEntity> orderGetDailyChallen challengeFacade.getDailyChallengeInfo(userId, timeZone))); } - @PostMapping("/app") @Override + @PostMapping("/app") public ResponseEntity> orderAddApps( @UserId final Long userId, @RequestHeader("OS") final String os, @@ -73,8 +74,8 @@ public ResponseEntity> orderAddApps( } - @DeleteMapping("/app") @Override + @DeleteMapping("/app") public ResponseEntity> orderRemoveApp( @UserId final Long userId, @RequestHeader("OS") final String os, diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index c3ae3682..0db9a28d 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -47,7 +47,7 @@ public ResponseEntity> orderGetChallenge( return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, - challengeFacade.getCurrentChallengeInfo(userId))); + challengeFacade.getCurrentChallengeInfo(userId, "Asia/Seoul"))); } @GetMapping("/home") diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/NewChallengeOrder.java similarity index 89% rename from src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java rename to src/main/java/sopt/org/hmh/domain/challenge/dto/request/NewChallengeOrder.java index f9ca0cce..61cb274e 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/NewChallengeOrder.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/request/NewChallengeOrder.java @@ -1,7 +1,7 @@ -package sopt.org.hmh.domain.challenge.dto; +package sopt.org.hmh.domain.challenge.dto.request; +import java.time.LocalDate; import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.List; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -9,7 +9,6 @@ import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest; import sopt.org.hmh.domain.challenge.domain.Challenge; -import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -41,7 +40,7 @@ public Challenge toChallengeEntity() { .period(challengeRequest.period()) .userId(userId) .goalTime(challengeRequest.goalTime()) - .startDate(ZonedDateTime.now(zoneId).toLocalDate()) + .startDate(LocalDate.now(zoneId)) .build(); } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java b/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java index c5194b3c..cebed4f1 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/dto/response/ChallengeResponse.java @@ -1,7 +1,7 @@ package sopt.org.hmh.domain.challenge.dto.response; import java.time.LocalDate; -import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.temporal.ChronoUnit; import lombok.Builder; import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse; @@ -16,27 +16,28 @@ public record ChallengeResponse( Integer period, List statuses, Integer todayIndex, - String startDate, + LocalDate startDate, Long goalTime, List apps ) { - public static ChallengeResponse of(Challenge challenge) { + public static ChallengeResponse of(Challenge challenge, String timeZone) { return ChallengeResponse.builder() .period(challenge.getPeriod()) .statuses(challenge.getHistoryDailyChallenges() .stream() .map(DailyChallenge::getStatus) .toList()) - .todayIndex(calculateTodayIndex(challenge.getCreatedAt(), challenge.getPeriod())) - .startDate(challenge.getCreatedAt().toLocalDate().toString()) + .todayIndex(calculateTodayIndex(challenge, LocalDate.now(ZoneId.of(timeZone)))) + .startDate(challenge.getStartDate()) .goalTime(challenge.getGoalTime()) .apps(challenge.getApps().stream() .map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList()) .build(); } - private static Integer calculateTodayIndex(LocalDateTime challengeCreateAt, int period) { - int daysBetween = (int) ChronoUnit.DAYS.between(challengeCreateAt.toLocalDate(), LocalDate.now()); - return (daysBetween >= period) ? -1 : daysBetween; + private static Integer calculateTodayIndex(Challenge challenge, LocalDate now) { + final int COMPLETED_CHALLENGE_INDEX = -1; + int daysBetween = (int) ChronoUnit.DAYS.between(challenge.getStartDate(), now); + return (daysBetween >= challenge.getPeriod()) ? COMPLETED_CHALLENGE_INDEX : daysBetween; } } \ No newline at end of file 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 bf4e8e88..fe3b415e 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 @@ -46,8 +46,9 @@ private void addAppsByNewChallengeOrder(NewChallengeOrder newChallengeOrder, Cha } @Transactional(readOnly = true) - public ChallengeResponse getCurrentChallengeInfo(Long userId) { - return ChallengeResponse.of(this.findCurrentChallengeByUserId(userId)); + public ChallengeResponse getCurrentChallengeInfo(Long userId, String timeZone) { + Challenge currentChallenge = this.findCurrentChallengeByUserId(userId); + return ChallengeResponse.of(currentChallenge, timeZone); } @Transactional(readOnly = true) From c9ff73dffcce3ccfa215ba1bb35cd87ab6904c26 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:07:58 +0900 Subject: [PATCH 20/41] =?UTF-8?q?refactor=20-=20#175=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=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 --- .../org/hmh/domain/auth/dto/request/SocialSignUpRequest.java | 1 - src/main/java/sopt/org/hmh/domain/user/service/UserService.java | 2 -- 2 files changed, 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 ef3d4511..f8ebcc51 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,7 +3,6 @@ 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; 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 263d8bab..456ef92c 100644 --- a/src/main/java/sopt/org/hmh/domain/user/service/UserService.java +++ b/src/main/java/sopt/org/hmh/domain/user/service/UserService.java @@ -12,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.challenge.domain.exception.ChallengeError; -import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; import sopt.org.hmh.domain.user.domain.User; import sopt.org.hmh.domain.user.domain.UserConstants; import sopt.org.hmh.domain.user.domain.exception.UserError; From 72953d25214afdbc5fe404bd996dcacf3a481db2 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:13:53 +0900 Subject: [PATCH 21/41] =?UTF-8?q?refactor=20-=20#175=20challengeAppControl?= =?UTF-8?q?ler=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/ChallengeAppApi.java | 59 +++++++++++++++++++ .../controller/ChallengeAppController.java | 53 +++++++++++++++++ .../challenge/controller/ChallengeApi.java | 40 ------------- .../controller/ChallengeApiDeprecated.java | 40 ------------- .../controller/ChallengeController.java | 27 --------- .../ChallengeControllerDeprecated.java | 29 --------- 6 files changed, 112 insertions(+), 136 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppApi.java create mode 100644 src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java diff --git a/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppApi.java b/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppApi.java new file mode 100644 index 00000000..8c0dd3c5 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppApi.java @@ -0,0 +1,59 @@ +package sopt.org.hmh.domain.app.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; +import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; +import sopt.org.hmh.global.auth.jwt.JwtConstants; +import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; + +@Tag(name = "챌린지 관련 API") +@SecurityRequirement(name = JwtConstants.AUTHORIZATION) +public interface ChallengeAppApi { + + @Operation( + summary = "스크린타임 설정할 앱을 추가하는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지 정보 조회에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderAddApps( + @Parameter(hidden = true) Long userId, + @RequestHeader("OS") String os, + @RequestBody ChallengeAppArrayRequest requests); + + @Operation( + summary = "스크린타임 설정한 앱을 삭제하는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "챌린지 정보 조회에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderRemoveApp( + @Parameter(hidden = true) Long userId, + @RequestHeader("OS") String os, + @RequestBody AppRemoveRequest request); +} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java b/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java new file mode 100644 index 00000000..73f88567 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java @@ -0,0 +1,53 @@ +package sopt.org.hmh.domain.app.controller; + +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.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import sopt.org.hmh.domain.app.domain.exception.AppSuccess; +import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; +import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/challenge/app") +public class ChallengeAppController implements ChallengeAppApi { + + private final ChallengeFacade challengeFacade; + + @Override + @PostMapping + 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 + .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse())); + + } + + @Override + @DeleteMapping + 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 + .status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse())); + } +} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java index 806249de..eeebfa19 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApi.java @@ -8,8 +8,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; -import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; 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; @@ -76,43 +74,5 @@ ResponseEntity> orderGetChallenge( ResponseEntity> orderGetDailyChallenge( @Parameter(hidden = true) final Long userId, @RequestHeader final String timeZone); - - @Operation( - summary = "스크린타임 설정할 앱을 추가하는 API", - responses = { - @ApiResponse( - responseCode = "200", - description = "챌린지 정보 조회에 성공했습니다."), - @ApiResponse( - responseCode = "400", - description = "잘못된 요청입니다.", - content = @Content), - @ApiResponse( - responseCode = "500", - description = "서버 내부 오류입니다.", - content = @Content)}) - ResponseEntity> orderAddApps( - @Parameter(hidden = true) Long userId, - @RequestHeader("OS") String os, - @RequestBody ChallengeAppArrayRequest requests); - - @Operation( - summary = "스크린타임 설정한 앱을 삭제하는 API", - responses = { - @ApiResponse( - responseCode = "200", - description = "챌린지 정보 조회에 성공했습니다."), - @ApiResponse( - responseCode = "400", - description = "잘못된 요청입니다.", - content = @Content), - @ApiResponse( - responseCode = "500", - description = "서버 내부 오류입니다.", - content = @Content)}) - ResponseEntity> orderRemoveApp( - @Parameter(hidden = true)Long userId, - @RequestHeader("OS") String os, - @RequestBody AppRemoveRequest request); } diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java index a6105d9b..c11b6904 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java @@ -8,8 +8,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; -import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest; 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; @@ -73,43 +71,5 @@ ResponseEntity> orderGetChallenge( content = @Content)}) ResponseEntity> orderGetDailyChallenge( @Parameter(hidden = true) final Long userId); - - @Operation( - summary = "스크린타임 설정할 앱을 추가하는 API", - responses = { - @ApiResponse( - responseCode = "200", - description = "챌린지 정보 조회에 성공했습니다."), - @ApiResponse( - responseCode = "400", - description = "잘못된 요청입니다.", - content = @Content), - @ApiResponse( - responseCode = "500", - description = "서버 내부 오류입니다.", - content = @Content)}) - ResponseEntity> orderAddApps( - @Parameter(hidden = true) Long userId, - @RequestHeader("OS") String os, - @RequestBody ChallengeAppArrayRequest requests); - - @Operation( - summary = "스크린타임 설정한 앱을 삭제하는 API", - responses = { - @ApiResponse( - responseCode = "200", - description = "챌린지 정보 조회에 성공했습니다."), - @ApiResponse( - responseCode = "400", - description = "잘못된 요청입니다.", - content = @Content), - @ApiResponse( - responseCode = "500", - description = "서버 내부 오류입니다.", - content = @Content)}) - ResponseEntity> orderRemoveApp( - @Parameter(hidden = true) Long userId, - @RequestHeader("OS") String os, - @RequestBody AppRemoveRequest 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 3a00b09e..70de9de4 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 @@ -59,31 +59,4 @@ public ResponseEntity> orderGetDailyChallen .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, challengeFacade.getDailyChallengeInfo(userId, timeZone))); } - - @Override - @PostMapping("/app") - 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 - .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse())); - - } - - @Override - @DeleteMapping("/app") - 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 - .status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse())); - } } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 0db9a28d..495e2f83 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -60,33 +60,4 @@ public ResponseEntity> orderGetDailyChallen .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, challengeFacade.getDailyChallengeInfo(userId, "Asia/Seoul"))); } - - @PostMapping("/app") - @Override - @Deprecated - 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 - .status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse())); - - } - - @DeleteMapping("/app") - @Override - @Deprecated - 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 - .status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus()) - .body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse())); - } } \ No newline at end of file From 8e6365ab012c70043e785e315c5277326ad400e9 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:14:31 +0900 Subject: [PATCH 22/41] =?UTF-8?q?refactor=20-=20#175=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/challenge/controller/ChallengeController.java | 3 --- .../challenge/controller/ChallengeControllerDeprecated.java | 3 --- 2 files changed, 6 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 70de9de4..07d33b5b 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 @@ -6,9 +6,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -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.exception.ChallengeSuccess; import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 495e2f83..4cb20ea9 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -6,9 +6,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -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.exception.ChallengeSuccess; import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest; import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse; From 97ddeb40b29e3ebbe169783c49784187313ce559 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:19:45 +0900 Subject: [PATCH 23/41] =?UTF-8?q?refactor=20-=20#175=20DailyChallengeContr?= =?UTF-8?q?oller=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DailyChallengeApi.java | 14 +++++ .../DailyChallengeApiDeprecated.java | 45 ++++++++++++++++ .../controller/DailyChallengeController.java | 2 +- .../DailyChallengeControllerDeprecated.java | 53 +++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java index 62c85780..912a6c54 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java @@ -37,6 +37,20 @@ ResponseEntity> orderAddHistoryDailyChallenge( final FinishedDailyChallengeListRequest request ); + @Operation( + summary = "완료된 챌린지 정보 리스트 전송 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "완료된 챌린지 정보 리스트 전송에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) ResponseEntity> orderChangeStatusDailyChallenge( @Parameter(hidden = true) final Long userId, final String os, diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java new file mode 100644 index 00000000..949dbedd --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java @@ -0,0 +1,45 @@ +package sopt.org.hmh.domain.dailychallenge.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +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.dailychallenge.dto.request.FinishedDailyChallengeListRequest; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; +import sopt.org.hmh.global.auth.jwt.JwtConstants; +import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; + +@Tag(name = "일별챌린지 관련 API") +@SecurityRequirement(name = JwtConstants.AUTHORIZATION) +public interface DailyChallengeApiDeprecated { + + @Operation( + summary = "사용시간과 함께 일별챌린지 정보 업데이트 요청하는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "일별 챌린지 정보 업데이트에 성공했습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderAddHistoryDailyChallenge( + @Parameter(hidden = true) final Long userId, + final String os, + final FinishedDailyChallengeListRequest request + ); + + ResponseEntity> orderChangeStatusDailyChallenge( + @Parameter(hidden = true) final Long userId, + final String os, + final FinishedDailyChallengeStatusListRequest request + ); + } 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 63c045c5..7f7208bb 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 @@ -14,7 +14,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/challenge/daily") +@RequestMapping("/api/v2/challenge/daily") public class DailyChallengeController implements DailyChallengeApi { private final DailyChallengeFacade dailyChallengeFacade; diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java new file mode 100644 index 00000000..6db3cf26 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java @@ -0,0 +1,53 @@ +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeSuccess; +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.global.auth.UserId; +import sopt.org.hmh.global.common.response.BaseResponse; +import sopt.org.hmh.global.common.response.EmptyJsonResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/challenge/daily") +public class DailyChallengeControllerDeprecated implements DailyChallengeApiDeprecated { + + private final DailyChallengeFacade dailyChallengeFacade; + + @Override + @PostMapping("/finish") + public ResponseEntity> orderAddHistoryDailyChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestBody @Valid final FinishedDailyChallengeListRequest request + ) { + dailyChallengeFacade.addFinishedDailyChallengeHistory(userId, request, os); + return ResponseEntity + .status(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS, + new EmptyJsonResponse())); + } + + @Override + @PostMapping("/success") + public ResponseEntity> orderChangeStatusDailyChallenge( + @UserId final Long userId, + @RequestHeader("OS") final String os, + @RequestBody final FinishedDailyChallengeStatusListRequest 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())); + } +} \ No newline at end of file From 1f98f5b8353429fcad454f17b99646aa4857ef75 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:25:52 +0900 Subject: [PATCH 24/41] =?UTF-8?q?refactor=20-=20#175=20CustomHeaderType?= =?UTF-8?q?=EC=9D=84=20=EC=83=81=EC=88=98=EB=A1=9C=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/app/controller/ChallengeAppController.java | 5 +++-- .../org/hmh/domain/auth/controller/AuthController.java | 7 ++++--- .../challenge/controller/ChallengeController.java | 5 +++-- .../controller/DailyChallengeController.java | 5 +++-- .../hmh/global/common/constant/CustomHeaderType.java | 10 ++++++++++ 5 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/global/common/constant/CustomHeaderType.java diff --git a/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java b/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java index 73f88567..274b2fa9 100644 --- a/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java +++ b/src/main/java/sopt/org/hmh/domain/app/controller/ChallengeAppController.java @@ -14,6 +14,7 @@ import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest; import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -28,7 +29,7 @@ public class ChallengeAppController implements ChallengeAppApi { @PostMapping public ResponseEntity> orderAddApps( @UserId final Long userId, - @RequestHeader("OS") final String os, + @RequestHeader(CustomHeaderType.OS) final String os, @RequestBody @Valid final ChallengeAppArrayRequest requests) { challengeFacade.addAppsToCurrentChallenge(userId, requests.apps(), os); @@ -42,7 +43,7 @@ public ResponseEntity> orderAddApps( @DeleteMapping public ResponseEntity> orderRemoveApp( @UserId final Long userId, - @RequestHeader("OS") final String os, + @RequestHeader(CustomHeaderType.OS) final String os, @RequestBody @Valid final AppRemoveRequest request) { challengeFacade.removeAppFromCurrentChallenge(userId, request.appCode(), os); 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 6187908b..01671257 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 @@ -18,6 +18,7 @@ import sopt.org.hmh.domain.auth.service.AuthFacade; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.auth.social.SocialAccessTokenResponse; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; @RestController @@ -46,7 +47,7 @@ public ResponseEntity> orderLogin( @PostMapping("/v1/user/signup") public ResponseEntity> orderSignupDeprecated( @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, - @RequestHeader("OS") final String os, + @RequestHeader(CustomHeaderType.OS) final String os, @RequestBody @Valid final SocialSignUpRequest request ) { return ResponseEntity @@ -61,8 +62,8 @@ public ResponseEntity> orderSignupDeprecated( @PostMapping("/v2/user/signup") public ResponseEntity> orderSignup( @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken, - @RequestHeader("OS") final String os, - @RequestHeader("Time-Zone") final String timeZone, + @RequestHeader(CustomHeaderType.OS) final String os, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone, @RequestBody @Valid final SocialSignUpRequest request ) { return ResponseEntity 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 07d33b5b..b7023c60 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,6 +12,7 @@ import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse; import sopt.org.hmh.domain.challenge.service.ChallengeFacade; import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -26,8 +27,8 @@ public class ChallengeController implements ChallengeApi { @PostMapping public ResponseEntity> orderAddChallenge( @UserId final Long userId, - @RequestHeader("OS") final String os, - @RequestHeader("Time-Zone") final String timeZone, + @RequestHeader(CustomHeaderType.OS) final String os, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone, @RequestBody @Valid final ChallengeRequest request) { challengeFacade.startNewChallenge(createNextChallengeOrder(request, userId, os, timeZone)); return ResponseEntity 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 7f7208bb..3b06d7b6 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 @@ -9,6 +9,7 @@ import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeFacade; import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -23,7 +24,7 @@ public class DailyChallengeController implements DailyChallengeApi { @PostMapping("/finish") public ResponseEntity> orderAddHistoryDailyChallenge( @UserId final Long userId, - @RequestHeader("OS") final String os, + @RequestHeader(CustomHeaderType.OS) final String os, @RequestBody @Valid final FinishedDailyChallengeListRequest request ) { dailyChallengeFacade.addFinishedDailyChallengeHistory(userId, request, os); @@ -36,7 +37,7 @@ public ResponseEntity> orderAddHistoryDailyChall @PostMapping("/success") public ResponseEntity> orderChangeStatusDailyChallenge( @UserId final Long userId, - @RequestHeader("OS") final String os, + @RequestHeader(CustomHeaderType.OS) final String os, @RequestBody final FinishedDailyChallengeStatusListRequest request ) { dailyChallengeFacade.changeDailyChallengeStatusByIsSuccess(userId, request); diff --git a/src/main/java/sopt/org/hmh/global/common/constant/CustomHeaderType.java b/src/main/java/sopt/org/hmh/global/common/constant/CustomHeaderType.java new file mode 100644 index 00000000..62dcf727 --- /dev/null +++ b/src/main/java/sopt/org/hmh/global/common/constant/CustomHeaderType.java @@ -0,0 +1,10 @@ +package sopt.org.hmh.global.common.constant; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public abstract class CustomHeaderType { + public static final String OS = "OS"; + public static final String TIME_ZONE = "Time-Zone"; +} From e03935487ff60b4d18954603c0e7e05ce8ff1f23 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:34:18 +0900 Subject: [PATCH 25/41] =?UTF-8?q?refactor=20-=20#175=20jwt=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/admin/service/AdminFacade.java | 2 +- .../sopt/org/hmh/domain/auth/dto/response/LoginResponse.java | 2 +- .../org/hmh/domain/auth/dto/response/ReissueResponse.java | 2 +- .../java/sopt/org/hmh/domain/auth/service/AuthFacade.java | 2 +- .../org/hmh/global/auth/jwt/{ => dto}/TokenResponse.java | 2 +- .../global/auth/jwt/{ => exception}/JwtValidationType.java | 2 +- .../org/hmh/global/auth/jwt/{ => service}/JwtGenerator.java | 2 +- .../global/auth/jwt/{ => service}/JwtPrefixExtractor.java | 3 ++- .../org/hmh/global/auth/jwt/{ => service}/JwtProvider.java | 5 +++-- .../org/hmh/global/auth/jwt/{ => service}/JwtValidator.java | 4 ++-- .../org/hmh/global/auth/jwt/{ => service}/TokenService.java | 5 +++-- .../hmh/global/auth/security/JwtAuthenticationFilter.java | 4 ++-- .../hmh/global/auth/security/ValidateAdminInterceptor.java | 2 +- src/main/java/sopt/org/hmh/global/config/SecurityConfig.java | 4 ++-- 14 files changed, 22 insertions(+), 19 deletions(-) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => dto}/TokenResponse.java (68%) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => exception}/JwtValidationType.java (91%) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => service}/JwtGenerator.java (98%) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => service}/JwtPrefixExtractor.java (86%) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => service}/JwtProvider.java (81%) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => service}/JwtValidator.java (92%) rename src/main/java/sopt/org/hmh/global/auth/jwt/{ => service}/TokenService.java (84%) 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 6fbdc22d..ac11f6f9 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 @@ -19,7 +19,7 @@ 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; +import sopt.org.hmh.global.auth.jwt.service.TokenService; @Service @RequiredArgsConstructor 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 e5c16e3c..3c434bfd 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,7 @@ package sopt.org.hmh.domain.auth.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; -import sopt.org.hmh.global.auth.jwt.TokenResponse; +import sopt.org.hmh.global.auth.jwt.dto.TokenResponse; public record LoginResponse( Long userId, diff --git a/src/main/java/sopt/org/hmh/domain/auth/dto/response/ReissueResponse.java b/src/main/java/sopt/org/hmh/domain/auth/dto/response/ReissueResponse.java index 119600c9..b0a79787 100644 --- a/src/main/java/sopt/org/hmh/domain/auth/dto/response/ReissueResponse.java +++ b/src/main/java/sopt/org/hmh/domain/auth/dto/response/ReissueResponse.java @@ -1,7 +1,7 @@ package sopt.org.hmh.domain.auth.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; -import sopt.org.hmh.global.auth.jwt.TokenResponse; +import sopt.org.hmh.global.auth.jwt.dto.TokenResponse; public record ReissueResponse( @JsonProperty(value = "token") 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 f3658be7..a63ef773 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 @@ -10,7 +10,7 @@ import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest; import sopt.org.hmh.domain.auth.dto.response.LoginResponse; import sopt.org.hmh.domain.user.service.UserService; -import sopt.org.hmh.global.auth.jwt.TokenService; +import sopt.org.hmh.global.auth.jwt.service.TokenService; import sopt.org.hmh.global.auth.jwt.exception.JwtError; import sopt.org.hmh.global.auth.jwt.exception.JwtException; import sopt.org.hmh.global.auth.social.SocialPlatform; diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java b/src/main/java/sopt/org/hmh/global/auth/jwt/dto/TokenResponse.java similarity index 68% rename from src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/dto/TokenResponse.java index a0751843..9de94aed 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenResponse.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/dto/TokenResponse.java @@ -1,4 +1,4 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.dto; public record TokenResponse( String accessToken, diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidationType.java b/src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtValidationType.java similarity index 91% rename from src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidationType.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtValidationType.java index 49051e80..f35cf633 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidationType.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/exception/JwtValidationType.java @@ -1,4 +1,4 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.exception; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtGenerator.java similarity index 98% rename from src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtGenerator.java index f30eba8e..6df887aa 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtGenerator.java @@ -1,4 +1,4 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.service; import static sopt.org.hmh.global.auth.jwt.JwtConstants.ADMIN_ROLE; diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtPrefixExtractor.java similarity index 86% rename from src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtPrefixExtractor.java index bf825e6b..5d5b70ec 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtPrefixExtractor.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtPrefixExtractor.java @@ -1,8 +1,9 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.service; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.springframework.util.StringUtils; +import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.auth.jwt.exception.JwtError; import sopt.org.hmh.global.auth.jwt.exception.JwtException; diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtProvider.java similarity index 81% rename from src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtProvider.java index ade8b1df..b05b299b 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtProvider.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtProvider.java @@ -1,10 +1,11 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.service; -import static sopt.org.hmh.global.auth.jwt.JwtPrefixExtractor.extractPrefix; +import static sopt.org.hmh.global.auth.jwt.service.JwtPrefixExtractor.extractPrefix; import io.jsonwebtoken.JwtParser; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import sopt.org.hmh.global.auth.jwt.dto.TokenResponse; @Component @RequiredArgsConstructor diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtValidator.java similarity index 92% rename from src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtValidator.java index c964c791..8cdf2431 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/JwtValidator.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/service/JwtValidator.java @@ -1,7 +1,7 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.service; import static sopt.org.hmh.global.auth.jwt.JwtConstants.ADMIN_ROLE; -import static sopt.org.hmh.global.auth.jwt.JwtPrefixExtractor.extractPrefix; +import static sopt.org.hmh.global.auth.jwt.service.JwtPrefixExtractor.extractPrefix; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; diff --git a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java b/src/main/java/sopt/org/hmh/global/auth/jwt/service/TokenService.java similarity index 84% rename from src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java rename to src/main/java/sopt/org/hmh/global/auth/jwt/service/TokenService.java index b589abac..d305ce51 100644 --- a/src/main/java/sopt/org/hmh/global/auth/jwt/TokenService.java +++ b/src/main/java/sopt/org/hmh/global/auth/jwt/service/TokenService.java @@ -1,11 +1,12 @@ -package sopt.org.hmh.global.auth.jwt; +package sopt.org.hmh.global.auth.jwt.service; -import static sopt.org.hmh.global.auth.jwt.JwtPrefixExtractor.extractPrefix; +import static sopt.org.hmh.global.auth.jwt.service.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.dto.TokenResponse; @Service @RequiredArgsConstructor 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 db01f72f..6e19c6d7 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 @@ -14,8 +14,8 @@ 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.service.JwtProvider; +import sopt.org.hmh.global.auth.jwt.service.JwtValidator; @RequiredArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { 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 index 4a08fac4..8802a076 100644 --- a/src/main/java/sopt/org/hmh/global/auth/security/ValidateAdminInterceptor.java +++ b/src/main/java/sopt/org/hmh/global/auth/security/ValidateAdminInterceptor.java @@ -6,7 +6,7 @@ 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; +import sopt.org.hmh.global.auth.jwt.service.TokenService; @Component @RequiredArgsConstructor 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 7a8a4908..3a499501 100644 --- a/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java +++ b/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java @@ -10,8 +10,8 @@ import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import sopt.org.hmh.global.auth.jwt.JwtProvider; -import sopt.org.hmh.global.auth.jwt.JwtValidator; +import sopt.org.hmh.global.auth.jwt.service.JwtProvider; +import sopt.org.hmh.global.auth.jwt.service.JwtValidator; import sopt.org.hmh.global.auth.security.JwtAuthenticationEntryPoint; import sopt.org.hmh.global.auth.security.JwtAuthenticationFilter; import sopt.org.hmh.global.auth.security.exception.ExceptionHandlerFilter; From 256468feb4d9c6c487e393bddf92f06a21237781 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 17:34:56 +0900 Subject: [PATCH 26/41] =?UTF-8?q?docs=20-=20#175=20DailyChallengeControlle?= =?UTF-8?q?r=20swagger=20=EB=AC=B8=EC=84=9C=20=EC=84=A4=EB=AA=85=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 --- .../controller/DailyChallengeApi.java | 20 +++++++++++-------- .../controller/DailyChallengeController.java | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java index 912a6c54..486d1562 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApi.java @@ -7,9 +7,12 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; import sopt.org.hmh.global.auth.jwt.JwtConstants; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -18,11 +21,11 @@ public interface DailyChallengeApi { @Operation( - summary = "사용시간과 함께 일별챌린지 정보 업데이트 요청하는 API", + summary = "완료된 챌린지 정보 리스트 전송 API (Android)", responses = { @ApiResponse( responseCode = "200", - description = "일별 챌린지 정보 업데이트에 성공했습니다."), + description = "완료된 챌린지 정보 리스트 전송에 성공했습니다."), @ApiResponse( responseCode = "400", description = "잘못된 요청입니다.", @@ -33,16 +36,17 @@ public interface DailyChallengeApi { content = @Content)}) ResponseEntity> orderAddHistoryDailyChallenge( @Parameter(hidden = true) final Long userId, - final String os, - final FinishedDailyChallengeListRequest request + @RequestHeader(CustomHeaderType.TIME_ZONE) final String os, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone, + @RequestBody final FinishedDailyChallengeListRequest request ); @Operation( - summary = "완료된 챌린지 정보 리스트 전송 API", + summary = "챌린지 성공 여부 리스트 전송 API (iOS)", responses = { @ApiResponse( responseCode = "200", - description = "완료된 챌린지 정보 리스트 전송에 성공했습니다."), + description = "챌린지 성공 여부 리스트 전송에 성공했습니다."), @ApiResponse( responseCode = "400", description = "잘못된 요청입니다.", @@ -53,8 +57,8 @@ ResponseEntity> orderAddHistoryDailyChallenge( content = @Content)}) ResponseEntity> orderChangeStatusDailyChallenge( @Parameter(hidden = true) final Long userId, - final String os, - final FinishedDailyChallengeStatusListRequest request + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone, + @RequestBody final FinishedDailyChallengeStatusListRequest request ); } 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 3b06d7b6..06e6a6fc 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 @@ -25,6 +25,7 @@ public class DailyChallengeController implements DailyChallengeApi { public ResponseEntity> orderAddHistoryDailyChallenge( @UserId final Long userId, @RequestHeader(CustomHeaderType.OS) final String os, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone, @RequestBody @Valid final FinishedDailyChallengeListRequest request ) { dailyChallengeFacade.addFinishedDailyChallengeHistory(userId, request, os); @@ -37,7 +38,7 @@ public ResponseEntity> orderAddHistoryDailyChall @PostMapping("/success") public ResponseEntity> orderChangeStatusDailyChallenge( @UserId final Long userId, - @RequestHeader(CustomHeaderType.OS) final String os, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone, @RequestBody final FinishedDailyChallengeStatusListRequest request ) { dailyChallengeFacade.changeDailyChallengeStatusByIsSuccess(userId, request); From 0f5f284c337167b5673f240226b434e23c1ea548 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 23:10:57 +0900 Subject: [PATCH 27/41] =?UTF-8?q?modify=20-=20#175=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Deprecated=20controller=EC=97=90=20Deprecated=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge/controller/ChallengeApiDeprecated.java | 1 + .../controller/ChallengeControllerDeprecated.java | 1 + .../controller/DailyChallengeApiDeprecated.java | 9 +++++---- .../controller/DailyChallengeControllerDeprecated.java | 9 +++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java index c11b6904..72acaed3 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeApiDeprecated.java @@ -15,6 +15,7 @@ import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; +@Deprecated @Tag(name = "챌린지 관련 API") @SecurityRequirement(name = JwtConstants.AUTHORIZATION) public interface ChallengeApiDeprecated { diff --git a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java index 4cb20ea9..8545fecf 100644 --- a/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/challenge/controller/ChallengeControllerDeprecated.java @@ -15,6 +15,7 @@ import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; +@Deprecated @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/challenge") diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java index 949dbedd..a5cc76a4 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeApiDeprecated.java @@ -7,13 +7,14 @@ 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.dailychallenge.dto.request.FinishedDailyChallengeListRequest; -import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequestDeprecated; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequestDeprecated; import sopt.org.hmh.global.auth.jwt.JwtConstants; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @Tag(name = "일별챌린지 관련 API") +@Deprecated @SecurityRequirement(name = JwtConstants.AUTHORIZATION) public interface DailyChallengeApiDeprecated { @@ -34,12 +35,12 @@ public interface DailyChallengeApiDeprecated { ResponseEntity> orderAddHistoryDailyChallenge( @Parameter(hidden = true) final Long userId, final String os, - final FinishedDailyChallengeListRequest request + final FinishedDailyChallengeListRequestDeprecated request ); ResponseEntity> orderChangeStatusDailyChallenge( @Parameter(hidden = true) final Long userId, final String os, - final FinishedDailyChallengeStatusListRequest request + final FinishedDailyChallengeStatusListRequestDeprecated request ); } diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java index 6db3cf26..3a6b06c8 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java @@ -9,13 +9,14 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeSuccess; -import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; -import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequestDeprecated; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequestDeprecated; import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeFacade; import sopt.org.hmh.global.auth.UserId; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; +@Deprecated @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/challenge/daily") @@ -28,7 +29,7 @@ public class DailyChallengeControllerDeprecated implements DailyChallengeApiDepr public ResponseEntity> orderAddHistoryDailyChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, - @RequestBody @Valid final FinishedDailyChallengeListRequest request + @RequestBody @Valid final FinishedDailyChallengeListRequestDeprecated request ) { dailyChallengeFacade.addFinishedDailyChallengeHistory(userId, request, os); return ResponseEntity @@ -42,7 +43,7 @@ public ResponseEntity> orderAddHistoryDailyChall public ResponseEntity> orderChangeStatusDailyChallenge( @UserId final Long userId, @RequestHeader("OS") final String os, - @RequestBody final FinishedDailyChallengeStatusListRequest request + @RequestBody final FinishedDailyChallengeStatusListRequestDeprecated request ) { dailyChallengeFacade.changeDailyChallengeStatusByIsSuccess(userId, request); return ResponseEntity From 4f7a4f4b4cd7f6530448e3bd4e0a10325c36b27e Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 23:13:00 +0900 Subject: [PATCH 28/41] =?UTF-8?q?modify=20-=20#175=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?DailyChallengeController=20=EA=B4=80=EB=A0=A8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=97=90=20Deprecated=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyChallengeControllerDeprecated.java | 8 +-- .../FinishedDailyChallengeListRequest.java | 10 ---- ...edDailyChallengeListRequestDeprecated.java | 11 ++++ ...ishedDailyChallengeRequestDeprecated.java} | 3 +- ...nishedDailyChallengeStatusListRequest.java | 9 --- ...yChallengeStatusListRequestDeprecated.java | 10 ++++ ...ailyChallengeStatusRequestDeprecated.java} | 3 +- .../DailyChallengeFacadeDeprecated.java | 57 +++++++++++++++++++ 8 files changed, 86 insertions(+), 25 deletions(-) delete mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequestDeprecated.java rename src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/{FinishedDailyChallengeRequest.java => FinishedDailyChallengeRequestDeprecated.java} (85%) delete mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequestDeprecated.java rename src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/{FinishedDailyChallengeStatusRequest.java => FinishedDailyChallengeStatusRequestDeprecated.java} (67%) create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacadeDeprecated.java diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java index 3a6b06c8..a789e286 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/controller/DailyChallengeControllerDeprecated.java @@ -11,7 +11,7 @@ import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeSuccess; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequestDeprecated; import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequestDeprecated; -import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeFacade; +import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeFacadeDeprecated; import sopt.org.hmh.global.auth.UserId; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -22,7 +22,7 @@ @RequestMapping("/api/v1/challenge/daily") public class DailyChallengeControllerDeprecated implements DailyChallengeApiDeprecated { - private final DailyChallengeFacade dailyChallengeFacade; + private final DailyChallengeFacadeDeprecated dailyChallengeFacadeDeprecated; @Override @PostMapping("/finish") @@ -31,7 +31,7 @@ public ResponseEntity> orderAddHistoryDailyChall @RequestHeader("OS") final String os, @RequestBody @Valid final FinishedDailyChallengeListRequestDeprecated request ) { - dailyChallengeFacade.addFinishedDailyChallengeHistory(userId, request, os); + dailyChallengeFacadeDeprecated.addFinishedDailyChallengeHistory(userId, request, os); return ResponseEntity .status(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS, @@ -45,7 +45,7 @@ public ResponseEntity> orderChangeStatusDailyCha @RequestHeader("OS") final String os, @RequestBody final FinishedDailyChallengeStatusListRequestDeprecated request ) { - dailyChallengeFacade.changeDailyChallengeStatusByIsSuccess(userId, request); + dailyChallengeFacadeDeprecated.changeDailyChallengeStatusByIsSuccess(userId, request); return ResponseEntity .status(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS, 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 deleted file mode 100644 index cae0e1da..00000000 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java +++ /dev/null @@ -1,10 +0,0 @@ -package sopt.org.hmh.domain.dailychallenge.dto.request; - -import jakarta.validation.Valid; -import java.util.List; - -public record FinishedDailyChallengeListRequest( - List<@Valid FinishedDailyChallengeRequest> finishedDailyChallenges -) { - -} diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequestDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequestDeprecated.java new file mode 100644 index 00000000..fca2cd29 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequestDeprecated.java @@ -0,0 +1,11 @@ +package sopt.org.hmh.domain.dailychallenge.dto.request; + +import jakarta.validation.Valid; +import java.util.List; + +@Deprecated +public record FinishedDailyChallengeListRequestDeprecated( + List<@Valid FinishedDailyChallengeRequestDeprecated> 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/FinishedDailyChallengeRequestDeprecated.java similarity index 85% rename from src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java rename to src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequestDeprecated.java index 540bc927..490a9052 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/FinishedDailyChallengeRequestDeprecated.java @@ -6,7 +6,8 @@ import java.util.List; import sopt.org.hmh.domain.app.dto.request.HistoryAppRequest; -public record FinishedDailyChallengeRequest( +@Deprecated +public record FinishedDailyChallengeRequestDeprecated( @NotNull(message = "챌린지 날짜는 null일 수 없습니다.") LocalDate challengeDate, List<@Valid HistoryAppRequest> apps diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java deleted file mode 100644 index d5692b78..00000000 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package sopt.org.hmh.domain.dailychallenge.dto.request; - -import java.util.List; - -public record FinishedDailyChallengeStatusListRequest( - List finishedDailyChallenges -) { - -} diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequestDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequestDeprecated.java new file mode 100644 index 00000000..e0c130bc --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequestDeprecated.java @@ -0,0 +1,10 @@ +package sopt.org.hmh.domain.dailychallenge.dto.request; + +import java.util.List; + +@Deprecated +public record FinishedDailyChallengeStatusListRequestDeprecated( + List finishedDailyChallenges +) { + +} diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequestDeprecated.java similarity index 67% rename from src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java rename to src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequestDeprecated.java index a2baadc0..65e65d38 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequestDeprecated.java @@ -2,7 +2,8 @@ import java.time.LocalDate; -public record FinishedDailyChallengeStatusRequest( +@Deprecated +public record FinishedDailyChallengeStatusRequestDeprecated( LocalDate challengeDate, boolean isSuccess ) { diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacadeDeprecated.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacadeDeprecated.java new file mode 100644 index 00000000..b9be5f99 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacadeDeprecated.java @@ -0,0 +1,57 @@ +package sopt.org.hmh.domain.dailychallenge.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.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.FinishedDailyChallengeListRequestDeprecated; +import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequestDeprecated; +import sopt.org.hmh.domain.user.service.UserService; + +@Service +@Deprecated +@RequiredArgsConstructor +public class DailyChallengeFacadeDeprecated { + + private final DailyChallengeService dailyChallengeService; + private final HistoryAppService historyAppService; + private final ChallengeService challengeService; + private final UserService userService; + + @Transactional + @Deprecated + public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequestDeprecated requests, String os) { + Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); + List currentChallengeApps = + challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); + + requests.finishedDailyChallenges().forEach(request -> { + DailyChallenge dailyChallenge = + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(request.challengeDate(), userId); + dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); + historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); + }); + } + + @Transactional + @Deprecated + public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequestDeprecated requests) { + requests.finishedDailyChallenges().forEach(request -> { + DailyChallenge dailyChallenge = + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(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); + } + }); + } +} From f25a2e6273df879865ff3be2558938a805c42c96 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 23:31:38 +0900 Subject: [PATCH 29/41] =?UTF-8?q?feat=20-=20#175=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EC=9A=B4=20dailyChallenge=20request=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/FinishedDailyChallengeListRequest.java | 10 ++++++++++ .../dto/request/FinishedDailyChallengeRequest.java | 13 +++++++++++++ .../FinishedDailyChallengeStatusListRequest.java | 8 ++++++++ .../FinishedDailyChallengeStatusRequest.java | 7 +++++++ 4 files changed, 38 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java 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 new file mode 100644 index 00000000..cae0e1da --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.java @@ -0,0 +1,10 @@ +package sopt.org.hmh.domain.dailychallenge.dto.request; + +import jakarta.validation.Valid; +import java.util.List; + +public record FinishedDailyChallengeListRequest( + 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 new file mode 100644 index 00000000..b2aa0b81 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.java @@ -0,0 +1,13 @@ +package sopt.org.hmh.domain.dailychallenge.dto.request; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import java.util.List; +import sopt.org.hmh.domain.app.dto.request.HistoryAppRequest; + +public record FinishedDailyChallengeRequest( + @NotNull(message = "챌린지 날짜는 null일 수 없습니다.") + Integer challengePeriodIndex, + List<@Valid HistoryAppRequest> apps +) { +} diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java new file mode 100644 index 00000000..c0776977 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java @@ -0,0 +1,8 @@ +package sopt.org.hmh.domain.dailychallenge.dto.request; + +import java.util.List; + +public record FinishedDailyChallengeStatusListRequest( + List finishedDailyChallenges +) { +} diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java new file mode 100644 index 00000000..ee3dfa82 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java @@ -0,0 +1,7 @@ +package sopt.org.hmh.domain.dailychallenge.dto.request; + +public record FinishedDailyChallengeStatusRequest( + Integer challengePeriodIndex, + boolean isSuccess +) { +} From d25e154ba930d5f4e489dd8c785008e175fee541 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 23:31:55 +0900 Subject: [PATCH 30/41] =?UTF-8?q?chore=20-=20#175=20=EC=A4=84=EB=B0=94?= =?UTF-8?q?=EA=BF=88=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/hmh/domain/app/service/HistoryAppService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c4a79d9a..a0c218bd 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 @@ -24,7 +24,7 @@ public void addHistoryApp( } private List supplementAdditionalInfo(List currentChallengeApps, - List apps, DailyChallenge dailyChallenge, String os) { + List apps, DailyChallenge dailyChallenge, String os) { return apps.stream().map(app -> HistoryApp.builder() .goalTime(this.getGoalTime(currentChallengeApps, app.appCode())) .appCode(app.appCode()) From 282cfee1830ab5f88c06d96dd35b853889b78024 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Jul 2024 23:32:14 +0900 Subject: [PATCH 31/41] =?UTF-8?q?refactor=20-=20#175=20DailyChallengeRepos?= =?UTF-8?q?itory=20=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyChallengeJpaRepository.java | 14 +++++++++++ .../repository/DailyChallengeRepository.java | 3 +-- .../DailyChallengeRepositoryImpl.java | 25 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java new file mode 100644 index 00000000..fc59e683 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java @@ -0,0 +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 DailyChallengeJpaRepository extends JpaRepository { + + Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); + + List findAllByChallengeId(Long challengeId); +} 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 ca5bd335..0813b985 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 @@ -3,10 +3,9 @@ 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 { +public interface DailyChallengeRepository { Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java new file mode 100644 index 00000000..ca2b0b1f --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java @@ -0,0 +1,25 @@ +package sopt.org.hmh.domain.dailychallenge.repository; + +import java.time.LocalDate; +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; + +@Repository +@RequiredArgsConstructor +public class DailyChallengeRepositoryImpl implements DailyChallengeRepository { + + private final DailyChallengeJpaRepository dailyChallengeJpaRepository; + + @Override + public Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId) { + return dailyChallengeJpaRepository.findByChallengeDateAndUserId(challengeDate, userId); + } + + @Override + public List findAllByChallengeId(Long challengeId) { + return dailyChallengeJpaRepository.findAllByChallengeId(challengeId); + } +} From e64fc9e0b54b3796fae8fac651bf9f92b6707f59 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:13:15 +0900 Subject: [PATCH 32/41] =?UTF-8?q?feat=20-=20#175=20dailyChalleng=EB=A5=BC?= =?UTF-8?q?=20=EB=AA=A8=EB=91=90=20=EC=B0=BE=EB=8A=94=20=EB=A0=88=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20challengeDate=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=ED=95=A0=20=EC=88=98=20=EC=9E=88=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 --- .../repository/DailyChallengeJpaRepository.java | 2 +- .../repository/DailyChallengeRepository.java | 5 ++++- .../repository/DailyChallengeRepositoryImpl.java | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java index fc59e683..56f1ce01 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java @@ -10,5 +10,5 @@ public interface DailyChallengeJpaRepository extends JpaRepository findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); - List findAllByChallengeId(Long challengeId); + List findAllByChallengeIdOrderByChallengeDate(Long challengeId); } 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 0813b985..b7614769 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 @@ -7,7 +7,10 @@ public interface DailyChallengeRepository { + void saveAll(List dailyChallengeByChallengePeriod); + Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); - List findAllByChallengeId(Long challengeId); + List findAllByChallengeIdOrderByChallengeDate(Long challengeId); + } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java index ca2b0b1f..6f6ba996 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java @@ -13,13 +13,18 @@ public class DailyChallengeRepositoryImpl implements DailyChallengeRepository { private final DailyChallengeJpaRepository dailyChallengeJpaRepository; + @Override + public void saveAll(List dailyChallengeByChallengePeriod) { + dailyChallengeJpaRepository.saveAll(dailyChallengeByChallengePeriod); + } + @Override public Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId) { return dailyChallengeJpaRepository.findByChallengeDateAndUserId(challengeDate, userId); } @Override - public List findAllByChallengeId(Long challengeId) { - return dailyChallengeJpaRepository.findAllByChallengeId(challengeId); + public List findAllByChallengeIdOrderByChallengeDate(Long challengeId) { + return dailyChallengeJpaRepository.findAllByChallengeIdOrderByChallengeDate(challengeId); } } From 12dedba90238ebc4ddb393922f3f896b7a62dbe9 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:13:34 +0900 Subject: [PATCH 33/41] =?UTF-8?q?feat=20-=20#175=20QuerydslConfiguration?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/QuerydslConfiguration.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/global/config/QuerydslConfiguration.java diff --git a/src/main/java/sopt/org/hmh/global/config/QuerydslConfiguration.java b/src/main/java/sopt/org/hmh/global/config/QuerydslConfiguration.java new file mode 100644 index 00000000..52b71f91 --- /dev/null +++ b/src/main/java/sopt/org/hmh/global/config/QuerydslConfiguration.java @@ -0,0 +1,19 @@ +package sopt.org.hmh.global.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class QuerydslConfiguration { + + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} \ No newline at end of file From 0808e8c7897914dcba1f80dc7a7c5ec6601c50b1 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:17:04 +0900 Subject: [PATCH 34/41] =?UTF-8?q?modify=20-=20#175=20dailyChallenge=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20dto=20valid=20=EB=AC=B8=EC=9E=A5=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 --- .../dto/request/FinishedDailyChallengeRequest.java | 2 +- .../dto/request/FinishedDailyChallengeStatusListRequest.java | 3 ++- .../dto/request/FinishedDailyChallengeStatusRequest.java | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) 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 b2aa0b81..774ae010 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 @@ -6,7 +6,7 @@ import sopt.org.hmh.domain.app.dto.request.HistoryAppRequest; public record FinishedDailyChallengeRequest( - @NotNull(message = "챌린지 날짜는 null일 수 없습니다.") + @NotNull(message = "챌린지 기간 인덱스는 null일 수 없습니다.") Integer challengePeriodIndex, List<@Valid HistoryAppRequest> apps ) { diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java index c0776977..c49ae992 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusListRequest.java @@ -1,8 +1,9 @@ package sopt.org.hmh.domain.dailychallenge.dto.request; +import jakarta.validation.Valid; import java.util.List; public record FinishedDailyChallengeStatusListRequest( - List finishedDailyChallenges + List<@Valid FinishedDailyChallengeStatusRequest> finishedDailyChallenges ) { } diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java index ee3dfa82..9c9a6f60 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeStatusRequest.java @@ -1,6 +1,9 @@ package sopt.org.hmh.domain.dailychallenge.dto.request; +import jakarta.validation.constraints.NotNull; + public record FinishedDailyChallengeStatusRequest( + @NotNull(message = "챌린지 기간 인덱스는 null일 수 없습니다.") Integer challengePeriodIndex, boolean isSuccess ) { From 2e7c450f3f8129faf45b67c947e334ba8e0d7230 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:17:53 +0900 Subject: [PATCH 35/41] =?UTF-8?q?modify=20-=20#175=20DailyChallengeService?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=EC=99=80=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=20=EC=9D=B8=EB=8D=B1=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=BC=EB=B3=84=EC=B1=8C=EB=A6=B0=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EC=B0=BE=EB=8A=94=20=EB=A1=9C=EC=A7=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/exception/DailyChallengeError.java | 1 + .../service/DailyChallengeFacade.java | 7 +++++-- .../service/DailyChallengeService.java | 13 ++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) 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 60c5b7aa..4333ca2c 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,6 +8,7 @@ public enum DailyChallengeError implements ErrorBase { DAILY_CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "일별 챌린지를 찾을 수 없습니다."), + DAILY_CHALLENGE_PERIOD_INDEX_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 인덱스의 일별 챌린지를 찾을 수 없습니다."), DAILY_CHALLENGE_ALREADY_PROCESSED(HttpStatus.BAD_REQUEST, "이미 처리된 일별 챌린지입니다.") ; 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 eb227178..f6f3bbbf 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 @@ -30,7 +30,8 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge requests.finishedDailyChallenges().forEach(request -> { DailyChallenge dailyChallenge = - dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(request.challengeDate(), userId); + dailyChallengeService.findDailyChallengeByChallengeIdAndChallengePeriodIndex( + currentChallengeId, request.challengePeriodIndex()); dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); }); @@ -38,9 +39,11 @@ public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallenge @Transactional public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { + Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); requests.finishedDailyChallenges().forEach(request -> { DailyChallenge dailyChallenge = - dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(request.challengeDate(), userId); + dailyChallengeService.findDailyChallengeByChallengeIdAndChallengePeriodIndex( + currentChallengeId, request.challengePeriodIndex()); if (request.isSuccess()) { dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); dailyChallenge.changeStatus(Status.UNEARNED); 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 f5aa4d85..739f15a1 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,6 +2,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; import java.util.stream.IntStream; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,6 +24,12 @@ public DailyChallenge findDailyChallengeByChallengeDateAndUserIdOrElseThrow(Loca .orElseThrow(() -> new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_NOT_FOUND)); } + public DailyChallenge findDailyChallengeByChallengeIdAndChallengePeriodIndex(Long challengeId, Integer challengePeriodIndex) { + return Optional.ofNullable( + dailyChallengeRepository.findAllByChallengeIdOrderByChallengeDate(challengeId).get(challengePeriodIndex) + ).orElseThrow(() -> new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_PERIOD_INDEX_NOT_FOUND)); + } + public DailyChallenge findDailyChallengeByChallengeAndChallengeDate(Challenge challenge, LocalDate challengeDate) { return challenge.getHistoryDailyChallenges().stream() .filter(dailyChallenge -> dailyChallenge.getChallengeDate().equals(challengeDate)) @@ -67,12 +74,12 @@ private List createDailyChallengeByChallengePeriod(Challenge cha .toList(); } - public List getDailyChallengesByChallengeId(Long challengeId) { - return dailyChallengeRepository.findAllByChallengeId(challengeId); + public List getDailyChallengesByChallengeIdOrderByChallengeDate(Long challengeId) { + return dailyChallengeRepository.findAllByChallengeIdOrderByChallengeDate(challengeId); } public void changeInfoOfDailyChallenges(Long challengeId, List statuses, LocalDate challengeDate) { - List dailyChallenges = getDailyChallengesByChallengeId(challengeId); + List dailyChallenges = this.getDailyChallengesByChallengeIdOrderByChallengeDate(challengeId); changeStatusOfDailyChallenges(dailyChallenges, statuses); changeChallengeDateOfDailyChallenges(dailyChallenges, challengeDate); } From 331825ae41c56791d7d0dc41c7e623207b6cd32f Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:27:36 +0900 Subject: [PATCH 36/41] =?UTF-8?q?feat=20-=20#175=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=20api=20v2=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20v1=20Deprecated=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/point/controller/PointApi.java | 26 ++++++++++++++-- .../point/controller/PointController.java | 30 ++++++++++++++----- .../hmh/domain/point/service/PointFacade.java | 18 ++++++++++- 3 files changed, 63 insertions(+), 11 deletions(-) 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 45bbb357..a7db78a0 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,6 +7,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestHeader; 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; @@ -14,6 +15,7 @@ import sopt.org.hmh.domain.point.dto.response.UsagePointResponse; import sopt.org.hmh.domain.point.dto.response.UsePointResponse; import sopt.org.hmh.global.auth.jwt.JwtConstants; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; @Tag(name = "포인트 관련 API") @@ -37,6 +39,24 @@ public interface PointApi { ResponseEntity> orderGetChallengePointStatusList( @Parameter(hidden = true) Long userId); + @Operation( + summary = "포인트 사용 API Deprecated", + responses = { + @ApiResponse( + responseCode = "200", + description = "포인트 사용에 성공하였습니다."), + @ApiResponse( + responseCode = "400", + description = "잘못된 요청입니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderUsagePointAndChallengeFailedDeprecated( + @Parameter(hidden = true) Long userId, + ChallengeDateRequest challengeDateRequest); + @Operation( summary = "포인트 사용 API", responses = { @@ -52,7 +72,8 @@ ResponseEntity> orderGetChallenge description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderUsagePointAndChallengeFailed( - @Parameter(hidden = true) Long userId, ChallengeDateRequest challengeDateRequest); + @Parameter(hidden = true) Long userId, + @RequestHeader(CustomHeaderType.TIME_ZONE) String timeZone); @Operation( summary = "포인트 받기 API", @@ -69,7 +90,8 @@ ResponseEntity> orderUsagePointAndChallengeFailed description = "서버 내부 오류입니다.", content = @Content)}) ResponseEntity> orderEarnPointAndChallengeEarned( - @Parameter(hidden = true) Long userId, ChallengeDateRequest challengeDateRequest); + @Parameter(hidden = true) Long userId, + ChallengeDateRequest challengeDateRequest); @Operation( summary = "사용할 포인트 받기 API", 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 7e7b9558..99a27dc4 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 @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sopt.org.hmh.domain.challenge.dto.request.ChallengeDateRequest; @@ -14,17 +15,18 @@ import sopt.org.hmh.domain.point.exception.PointSuccess; import sopt.org.hmh.domain.point.service.PointFacade; import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/point") +@RequestMapping("/api") public class PointController implements PointApi { private final PointFacade pointFacade; @Override - @GetMapping("/list") + @GetMapping("/v1/point/list") public ResponseEntity> orderGetChallengePointStatusList( @UserId final Long userId ) { @@ -32,23 +34,35 @@ public ResponseEntity> orderGetCh .status(PointSuccess.GET_CHALLENGE_POINT_STATUS_LIST_SUCCESS.getHttpStatus()) .body(BaseResponse.success(PointSuccess.GET_CHALLENGE_POINT_STATUS_LIST_SUCCESS, pointFacade.getChallengePointStatusList(userId))); + } + @Override + @Deprecated + @PatchMapping("/v1/point/use") + public ResponseEntity> orderUsagePointAndChallengeFailedDeprecated( + @UserId final Long userId, + @RequestBody @Valid final ChallengeDateRequest challengeDateRequest + ) { + return ResponseEntity + .status(PointSuccess.POINT_USAGE_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(PointSuccess.POINT_USAGE_SUCCESS, + pointFacade.usePointAndChallengeFailedDeprecated(userId, challengeDateRequest.challengeDate()))); } @Override - @PatchMapping("/use") + @PatchMapping("/v2/point/use") public ResponseEntity> orderUsagePointAndChallengeFailed( @UserId final Long userId, - @RequestBody @Valid final ChallengeDateRequest challengeDateRequest + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone ) { return ResponseEntity .status(PointSuccess.POINT_USAGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(PointSuccess.POINT_USAGE_SUCCESS, - pointFacade.usePointAndChallengeFailed(userId, challengeDateRequest.challengeDate()))); + pointFacade.usePointAndChallengeFailed(userId, timeZone))); } @Override - @PatchMapping("/earn") + @PatchMapping("/v1/point/earn") public ResponseEntity> orderEarnPointAndChallengeEarned( @UserId final Long userId, @RequestBody final ChallengeDateRequest challengeDateRequest @@ -60,7 +74,7 @@ public ResponseEntity> orderEarnPointAndChalleng } @Override - @GetMapping("/earn") + @GetMapping("/v1/point/earn") public ResponseEntity> orderGetEarnedPoint() { return ResponseEntity .status(PointSuccess.GET_EARNED_POINT_SUCCESS.getHttpStatus()) @@ -69,7 +83,7 @@ public ResponseEntity> orderGetEarnedPoint() { } @Override - @GetMapping("/use") + @GetMapping("/v1/point/use") public ResponseEntity> orderGetUsagePoint() { return ResponseEntity .status(PointSuccess.GET_USAGE_POINT_SUCCESS.getHttpStatus()) 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 c9c54f3b..70404155 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 @@ -25,7 +25,23 @@ public class PointFacade { private final ChallengeService challengeService; @Transactional - public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challengeDate) { + @Deprecated + public UsePointResponse usePointAndChallengeFailedDeprecated(Long userId, LocalDate challengeDate) { + DailyChallenge dailyChallenge = + dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(challengeDate, userId); + User user = userService.findByIdOrThrowException(userId); + + dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); + dailyChallenge.changeStatus(Status.FAILURE); + + return new UsePointResponse( + ChallengeConstants.USAGE_POINT, + user.decreasePoint(ChallengeConstants.USAGE_POINT) + ); + } + + @Transactional + public UsePointResponse usePointAndChallengeFailed(Long userId, String timeZone) { DailyChallenge dailyChallenge = dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(challengeDate, userId); User user = userService.findByIdOrThrowException(userId); From bf677a5edd21035fd8f943a9f774c20bc2e30fcf Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:29:41 +0900 Subject: [PATCH 37/41] =?UTF-8?q?feat=20-=20#175=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=20api=EB=A5=BC=20timeZone?= =?UTF-8?q?=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EB=8B=B9?= =?UTF-8?q?=EC=9D=BC=EC=9D=98=20=EB=82=A0=EC=A7=9C=EB=A1=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=ED=95=98=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 --- .../sopt/org/hmh/domain/point/controller/PointController.java | 2 +- .../java/sopt/org/hmh/domain/point/service/PointFacade.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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 99a27dc4..844f65c0 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 @@ -58,7 +58,7 @@ public ResponseEntity> orderUsagePointAndChalleng return ResponseEntity .status(PointSuccess.POINT_USAGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(PointSuccess.POINT_USAGE_SUCCESS, - pointFacade.usePointAndChallengeFailed(userId, timeZone))); + pointFacade.usePointAndTodayDailyChallengeFailed(userId, timeZone))); } @Override 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 70404155..06308bd4 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 @@ -1,6 +1,7 @@ package sopt.org.hmh.domain.point.service; import java.time.LocalDate; +import java.time.ZoneId; import java.util.List; import lombok.RequiredArgsConstructor; @@ -41,7 +42,8 @@ public UsePointResponse usePointAndChallengeFailedDeprecated(Long userId, LocalD } @Transactional - public UsePointResponse usePointAndChallengeFailed(Long userId, String timeZone) { + public UsePointResponse usePointAndTodayDailyChallengeFailed(Long userId, String timeZone) { + LocalDate challengeDate = LocalDate.now(ZoneId.of(timeZone)); DailyChallenge dailyChallenge = dailyChallengeService.findDailyChallengeByChallengeDateAndUserIdOrElseThrow(challengeDate, userId); User user = userService.findByIdOrThrowException(userId); From 12b79020370b3774e2d5301dc67c1372210e41fa Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 00:40:56 +0900 Subject: [PATCH 38/41] =?UTF-8?q?feat=20-=20#175=20=EB=8B=B9=EC=9D=BC=20?= =?UTF-8?q?=EC=9E=A0=EA=B8=88=20=EC=97=AC=EB=B6=80=20=EC=A0=84=EC=86=A1=20?= =?UTF-8?q?=EB=B0=8F=20=ED=99=95=EC=9D=B8=20v2=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/user/controller/UserApi.java | 17 ++++++- .../user/controller/UserController.java | 46 +++++++++++++++---- .../hmh/domain/user/service/UserService.java | 18 +++++++- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/user/controller/UserApi.java b/src/main/java/sopt/org/hmh/domain/user/controller/UserApi.java index e390f419..3d0c2bc0 100644 --- a/src/main/java/sopt/org/hmh/domain/user/controller/UserApi.java +++ b/src/main/java/sopt/org/hmh/domain/user/controller/UserApi.java @@ -4,9 +4,11 @@ import io.swagger.v3.oas.annotations.Parameter; import java.time.LocalDate; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestHeader; import sopt.org.hmh.domain.user.dto.request.UserRequest.LockDateRequest; import sopt.org.hmh.domain.user.dto.response.UserResponse.IsLockTodayResponse; import sopt.org.hmh.domain.user.dto.response.UserResponse.UserInfoResponse; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @@ -26,10 +28,21 @@ public interface UserApi { @Operation(summary = "당일 잠금 여부 전송") ResponseEntity> orderChangeRecentLockDate( - @Parameter(hidden = true) final Long userId, final LockDateRequest request); + @Parameter(hidden = true) final Long userId, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone); + + @Operation(summary = "당일 잠금 여부 전송") + ResponseEntity> orderChangeRecentLockDateDeprecated( + @Parameter(hidden = true) final Long userId, + final LockDateRequest request); @Operation(summary = "당일 잠금 여부 확인") ResponseEntity> orderGetRecentLockDate( - @Parameter(hidden = true) final Long userId, final LocalDate lockCheckDate); + @Parameter(hidden = true) final Long userId, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone); + @Operation(summary = "당일 잠금 여부 확인") + ResponseEntity> orderGetRecentLockDateDeprecated( + @Parameter(hidden = true) final Long userId, + final LocalDate lockCheckDate); } diff --git a/src/main/java/sopt/org/hmh/domain/user/controller/UserController.java b/src/main/java/sopt/org/hmh/domain/user/controller/UserController.java index 9e5d80f9..cba390a6 100644 --- a/src/main/java/sopt/org/hmh/domain/user/controller/UserController.java +++ b/src/main/java/sopt/org/hmh/domain/user/controller/UserController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -18,17 +19,18 @@ import sopt.org.hmh.domain.user.dto.response.UserResponse.UserInfoResponse; import sopt.org.hmh.domain.user.service.UserService; import sopt.org.hmh.global.auth.UserId; +import sopt.org.hmh.global.common.constant.CustomHeaderType; import sopt.org.hmh.global.common.response.BaseResponse; import sopt.org.hmh.global.common.response.EmptyJsonResponse; @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/user") +@RequestMapping("/api") public class UserController implements UserApi { private final UserService userService; - @PostMapping("/logout") + @PostMapping("/v1/user/logout") @Override public ResponseEntity> orderLogout() { return ResponseEntity @@ -44,7 +46,7 @@ public ResponseEntity> orderGetUserInfo(@UserId f .body(BaseResponse.success(UserSuccess.GET_USER_INFO_SUCCESS, userService.getUserInfo(userId))); } - @GetMapping("/point") + @GetMapping("/v1/user/point") @Override public ResponseEntity> orderGetUserPoint(@UserId final Long userId) { return ResponseEntity @@ -53,7 +55,7 @@ public ResponseEntity> orderGetUserPoint(@UserId final Lon userService.getUserInfo(userId).point())); } - @DeleteMapping + @DeleteMapping("/v1/user") public ResponseEntity> orderWithdraw(@UserId final Long userId) { userService.withdraw(userId); return ResponseEntity @@ -61,25 +63,49 @@ public ResponseEntity> orderWithdraw(@UserId fin .body(BaseResponse.success(UserSuccess.WITHDRAW_SUCCESS, new EmptyJsonResponse())); } - @PostMapping("/daily/lock") @Override + @Deprecated + @PostMapping("/v1/user/daily/lock") + public ResponseEntity> orderChangeRecentLockDateDeprecated( + @UserId final Long userId, + @Valid @RequestBody final LockDateRequest request) { + userService.changeRecentLockDateDeprecated(userId, request.lockDate()); + return ResponseEntity + .status(UserSuccess.CHANGE_RECENT_LOCK_DATE_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(UserSuccess.CHANGE_RECENT_LOCK_DATE_SUCCESS, new EmptyJsonResponse())); + } + + @Override + @PostMapping("/v2/user/daily/lock") public ResponseEntity> orderChangeRecentLockDate( - @UserId final Long userId, @Valid @RequestBody final LockDateRequest request) { - userService.changeRecentLockDate(userId, request.lockDate()); + @UserId final Long userId, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone) { + userService.changeRecentLockDateToToday(userId, timeZone); return ResponseEntity .status(UserSuccess.CHANGE_RECENT_LOCK_DATE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(UserSuccess.CHANGE_RECENT_LOCK_DATE_SUCCESS, new EmptyJsonResponse())); } - @GetMapping("/daily/lock") @Override - public ResponseEntity> orderGetRecentLockDate( + @Deprecated + @GetMapping("/v1/user/daily/lock") + public ResponseEntity> orderGetRecentLockDateDeprecated( @UserId final Long userId, @RequestParam(name = "lockCheckDate") @DateTimeFormat(pattern = "yyyy-MM-dd") final LocalDate lockCheckDate) { return ResponseEntity .status(UserSuccess.GET_RECENT_LOCK_DATE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(UserSuccess.GET_RECENT_LOCK_DATE_SUCCESS, - userService.checkIsTodayLock(userId, lockCheckDate))); + userService.checkIsTodayLockDeprecated(userId, lockCheckDate))); } + @Override + @GetMapping("/v2/user/daily/lock") + public ResponseEntity> orderGetRecentLockDate( + @UserId final Long userId, + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone) { + return ResponseEntity + .status(UserSuccess.GET_RECENT_LOCK_DATE_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(UserSuccess.GET_RECENT_LOCK_DATE_SUCCESS, + userService.checkIsTodayLock(userId, timeZone))); + } } 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 456ef92c..55c63d1b 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,6 +1,7 @@ package sopt.org.hmh.domain.user.service; import java.time.LocalDate; +import java.time.ZoneId; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -108,17 +109,30 @@ public void changeCurrentChallengeIdByUserId(Long userId, Long challengeId) { this.findByIdOrThrowException(userId).changeCurrentChallengeId(challengeId); } + @Deprecated @Transactional - public void changeRecentLockDate(Long userId, LocalDate lockDate) { + public void changeRecentLockDateDeprecated(Long userId, LocalDate lockDate) { this.findByIdOrThrowException(userId).changeRecentLockDate(lockDate); } + @Transactional + public void changeRecentLockDateToToday(Long userId, String timeZone) { + this.findByIdOrThrowException(userId).changeRecentLockDate(LocalDate.now(ZoneId.of(timeZone))); + } + @Transactional(readOnly = true) - public IsLockTodayResponse checkIsTodayLock(Long userId, LocalDate lockCheckDate) { + @Deprecated + public IsLockTodayResponse checkIsTodayLockDeprecated(Long userId, LocalDate lockCheckDate) { LocalDate userRecentLockDate = this.findByIdOrThrowException(userId).getRecentLockDate(); return new IsLockTodayResponse(lockCheckDate.equals(userRecentLockDate)); } + @Transactional(readOnly = true) + public IsLockTodayResponse checkIsTodayLock(Long userId, String timeZone) { + LocalDate userRecentLockDate = this.findByIdOrThrowException(userId).getRecentLockDate(); + return new IsLockTodayResponse(userRecentLockDate.equals(LocalDate.now(ZoneId.of(timeZone)))); + } + public void withdrawImmediately(Long userId) { userRepository.deleteById(userId); } From 5dc8f9ba2e72dbe39df391e4dc38454fca9834ec Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 01:36:38 +0900 Subject: [PATCH 39/41] =?UTF-8?q?fix=20-=20#175=20=EB=B9=A0=EB=9C=A8?= =?UTF-8?q?=EB=A6=B0=20RequestHeader=20key=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmh/domain/challenge/controller/ChallengeController.java | 4 ++-- 1 file 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 b7023c60..a42d1af1 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 @@ -40,7 +40,7 @@ public ResponseEntity> orderAddChallenge( @GetMapping public ResponseEntity> orderGetChallenge( @UserId final Long userId, - @RequestHeader final String timeZone) { + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone) { return ResponseEntity .status(ChallengeSuccess.GET_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_CHALLENGE_SUCCESS, @@ -51,7 +51,7 @@ public ResponseEntity> orderGetChallenge( @GetMapping("/home") public ResponseEntity> orderGetDailyChallenge( @UserId final Long userId, - @RequestHeader final String timeZone) { + @RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone) { return ResponseEntity .status(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS.getHttpStatus()) .body(BaseResponse.success(ChallengeSuccess.GET_DAILY_CHALLENGE_SUCCESS, From 11153db523d13833ffe63cfec5c3b213c693d0dd Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 01:37:19 +0900 Subject: [PATCH 40/41] =?UTF-8?q?fix=20-=20#175=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20v2=EB=A5=BC=20=EC=9D=B8=EC=A6=9D=EC=9D=84?= =?UTF-8?q?=20=EA=B1=B0=EC=B9=98=EC=A7=80=20=EC=95=8A=EC=95=84=EB=8F=84=20?= =?UTF-8?q?=EB=90=98=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/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 3a499501..e1c75631 100644 --- a/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java +++ b/src/main/java/sopt/org/hmh/global/config/SecurityConfig.java @@ -41,6 +41,7 @@ public class SecurityConfig { "/api/v1/admin/login", "/api/v1/user/reissue", "/api/v1/user/signup", + "/api/v2/user/signup", "/api/v1/user/social/token/kakao", }; From a67b09772b0edd16e0dd07231b17bea89b9c5a74 Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Jul 2024 01:37:56 +0900 Subject: [PATCH 41/41] =?UTF-8?q?fix=20-=20#175=20userRecentLockDate?= =?UTF-8?q?=EA=B0=80=20null=EC=9D=BC=20=EB=95=8C=20NPE=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=A9=EC=A7=80=ED=95=98=EB=8F=84=EB=A1=9D=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/user/service/UserService.java | 3 ++- 1 file changed, 2 insertions(+), 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 55c63d1b..6682d188 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 @@ -129,8 +129,9 @@ public IsLockTodayResponse checkIsTodayLockDeprecated(Long userId, LocalDate loc @Transactional(readOnly = true) public IsLockTodayResponse checkIsTodayLock(Long userId, String timeZone) { + LocalDate now = LocalDate.now(ZoneId.of(timeZone)); LocalDate userRecentLockDate = this.findByIdOrThrowException(userId).getRecentLockDate(); - return new IsLockTodayResponse(userRecentLockDate.equals(LocalDate.now(ZoneId.of(timeZone)))); + return new IsLockTodayResponse(now.equals(userRecentLockDate)); } public void withdrawImmediately(Long userId) {