From 44dd13e94b1c984198ced81abf5ca8a47508bf65 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Sun, 3 Dec 2023 12:38:33 +0900 Subject: [PATCH] Revert "[Release] v1.6.1 " --- .../exception/UnitLessThanZeroException.java | 16 ++ .../auth/controller/LoginController.java | 65 +++++++ .../controller/BloodSugarGuideController.java | 17 ++ .../bloodsugar/document/BloodSugarGuide.java | 32 ++-- .../guide/bloodsugar/document/SubGuide.java | 17 -- .../common/controller/GuideController.java | 16 ++ .../controller/ExerciseGuideController.java | 18 ++ .../exercise/document/ExerciseGuide.java | 29 --- .../service/ExerciseGuideGenerateService.java | 24 +-- .../controller/WeightGuideController.java | 17 ++ .../service/WeightGuideGenerateService.java | 11 +- .../controller/HealthConnectController.java | 34 ++++ .../controller/HealthMetricController.java | 84 +++++++++ .../infrastructure/sidecar/SideCarSender.java | 36 ---- .../log/controller/AppLogController.java | 13 ++ .../domain/log/service/LogService.java | 17 +- .../controller/NotificationController.java | 32 ++++ .../service/NotificationSendService.java | 17 +- .../point/controller/PointController.java | 30 +++ .../scheduler/service/SchedulerService.java | 7 +- .../user/controller/SignupController.java | 16 ++ .../user/controller/UserController.java | 59 ++++++ .../version/controller/VersionController.java | 26 +++ .../global/aop/aspect/log/LogAspect.java | 6 +- .../dangjang/global/config/RedisConfig.java | 2 +- .../IncorrectCreatedAtException.java | 17 ++ .../dangjang/global/util/CreatedAtUtil.java | 34 ++++ src/main/resources/config | 2 +- .../auth/controller/LoginControllerTest.java | 15 +- .../BloodSugarGuideControllerTest.java | 6 +- .../BloodSugarGuideGenerateServiceTest.java | 173 +++++++----------- .../service/GenerateSubGuideTest.java | 12 +- .../controller/DayGuideControllerTest.java | 6 +- .../ExerciseGuideControllerTest.java | 6 +- .../controller/WeightGuideControllerTest.java | 14 +- .../HealthConnectControllerTest.java | 8 +- .../HealthMetricControllerTest.java | 42 ++--- .../log/controller/AppLogControllerTest.java | 14 +- .../NotificationControllerTest.java | 8 +- .../PointHistoryControllerTest.java | 9 +- .../user/controller/SignupControllerTest.java | 2 +- .../user/controller/UserControllerTest.java | 18 +- .../domain/util/CreatedAtUtilTest.java | 31 ++++ .../controller/VersionControllerTest.java | 13 +- src/test/resources/config/application.yml | 3 +- 45 files changed, 742 insertions(+), 332 deletions(-) create mode 100644 src/main/java/com/coniverse/dangjang/domain/analysis/exception/UnitLessThanZeroException.java delete mode 100644 src/main/java/com/coniverse/dangjang/domain/infrastructure/sidecar/SideCarSender.java create mode 100644 src/main/java/com/coniverse/dangjang/global/exception/IncorrectCreatedAtException.java create mode 100644 src/main/java/com/coniverse/dangjang/global/util/CreatedAtUtil.java create mode 100644 src/test/java/com/coniverse/dangjang/domain/util/CreatedAtUtilTest.java diff --git a/src/main/java/com/coniverse/dangjang/domain/analysis/exception/UnitLessThanZeroException.java b/src/main/java/com/coniverse/dangjang/domain/analysis/exception/UnitLessThanZeroException.java new file mode 100644 index 00000000..dc9fda4d --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/domain/analysis/exception/UnitLessThanZeroException.java @@ -0,0 +1,16 @@ +package com.coniverse.dangjang.domain.analysis.exception; + +import com.coniverse.dangjang.global.exception.BusinessException; + +/** + * 단위가 0보다 작을 때 발생하는 예외 + * + * @author TEO + * @since 1.0.0 + */ +@Deprecated(since = "1.0.0") +public class UnitLessThanZeroException extends BusinessException { + public UnitLessThanZeroException() { + super(400, "단위는 0보다 작을 수 없습니다"); + } +} diff --git a/src/main/java/com/coniverse/dangjang/domain/auth/controller/LoginController.java b/src/main/java/com/coniverse/dangjang/domain/auth/controller/LoginController.java index a0eaea45..9080ff36 100644 --- a/src/main/java/com/coniverse/dangjang/domain/auth/controller/LoginController.java +++ b/src/main/java/com/coniverse/dangjang/domain/auth/controller/LoginController.java @@ -33,6 +33,22 @@ public class LoginController { private static final String AUTHORIZATION = "Authorization"; private final OauthLoginService oauthLoginService; + /** + * @param params 카카오 accessToken + * @return ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, auth id)를 전달한다. + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping("/kakao") + public ResponseEntity> loginKakao(@Valid @RequestBody KakaoLoginRequest params) { + LoginResponse loginResponse = oauthLoginService.login(params); + String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname()); + return ResponseEntity.ok() + .header(ACCESS_TOKEN.toString(), accessToken) + .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse)); + } + /** * 카카오 로그인 * @@ -50,6 +66,22 @@ public ResponseEntity> loginKakaoV1(@Valid .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse)); } + /** + * @param params 네이버 accessToken + * @return ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, auth id)를 전달한다. + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping("/naver") + public ResponseEntity> loginNaver(@Valid @RequestBody NaverLoginRequest params) { + LoginResponse loginResponse = oauthLoginService.login(params); + String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname()); + return ResponseEntity.ok() + .header(ACCESS_TOKEN, accessToken) + .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse)); + } + /** * 네이버 로그인 * @@ -67,6 +99,23 @@ public ResponseEntity> loginNaverV1(@Valid .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse)); } + /** + * refreshToken으로 AuthToken 재발급 + * + * @param request 재발급 요청 , header에 accessToken이 필요 + * @return AuthToken + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping("/reissue") + public ResponseEntity> reissue(HttpServletRequest request) { + String newAccessToken = oauthLoginService.reissueToken(request.getHeader(AUTHORIZATION)); + return ResponseEntity.ok() + .header(ACCESS_TOKEN, newAccessToken) + .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * refresh token으로 access token 재발급 * @@ -83,6 +132,22 @@ public ResponseEntity> reissueV1(HttpServletRequest req .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); } + /** + * 로그아웃 + * + * @param request HttpServletRequest oauthId + * @param logoutFcmTokenRequest fcmToken + * @since 1.1.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping("/logout") + public ResponseEntity logout(HttpServletRequest request, @RequestBody LogoutFcmTokenRequest logoutFcmTokenRequest) { + oauthLoginService.logout(request.getHeader(AUTHORIZATION), logoutFcmTokenRequest.fcmToken()); + return ResponseEntity.ok() + .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * 로그아웃 * diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideController.java b/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideController.java index e52a8924..8c9b42bb 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideController.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideController.java @@ -31,6 +31,23 @@ public class BloodSugarGuideController { private final BloodSugarGuideSearchService bloodSugarGuideSearchService; + /** + * 혈당 가이드를 조회한다. + * + * @param date 조회할 일자 + * @param principal 사용자 정보 + * @return 혈당 가이드 응답 dto + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> get(@ValidLocalDate @RequestParam String date, + @AuthenticationPrincipal User principal) { + BloodSugarGuideResponse response = bloodSugarGuideSearchService.findGuide(principal.getUsername(), date); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 혈당 가이드를 조회한다. * diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/BloodSugarGuide.java b/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/BloodSugarGuide.java index 4a0d8b52..00b02fa0 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/BloodSugarGuide.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/BloodSugarGuide.java @@ -8,6 +8,7 @@ import com.coniverse.dangjang.domain.analysis.enums.Alert; import com.coniverse.dangjang.domain.code.enums.CommonCode; +import com.coniverse.dangjang.domain.guide.common.exception.GuideAlreadyExistsException; import com.coniverse.dangjang.domain.guide.common.exception.GuideNotFoundException; import jakarta.persistence.Id; @@ -53,12 +54,10 @@ private BloodSugarGuide(String oauthId, String createdAt) { * @since 1.0.0 */ public void addSubGuide(SubGuide subGuide) { - if (isDuplicatedSubGuide(subGuide)) { - return; - } + verifySubGuideNonExistent(subGuide.getType()); this.subGuides.add(subGuide); - plusAlertCount(subGuide.getAlert()); sortSubGuides(); + plusAlertCount(subGuide.getAlert()); } /** @@ -81,9 +80,7 @@ public void updateSubGuide(SubGuide updatedSubGuide) { * @since 1.0.0 */ public void updateSubGuide(SubGuide updatedSubGuide, CommonCode prevType) { - if (isDuplicatedSubGuide(updatedSubGuide)) { - return; - } + verifySubGuideNonExistent(updatedSubGuide.getType()); SubGuide subGuide = getSubGuide(prevType); updateAlertCount(subGuide.getAlert(), updatedSubGuide.getAlert()); subGuide.update(updatedSubGuide); @@ -91,14 +88,17 @@ public void updateSubGuide(SubGuide updatedSubGuide, CommonCode prevType) { } /** - * 서브 가이드가 중복인지 확인한다. + * 서브 가이드가 존재하는지 검증한다. * - * @param subGuide 서브 가이드 - * @since 1.6.1 + * @param type 서브 가이드 타입 + * @throws GuideAlreadyExistsException 이미 해당 가이드가 존재할 경우 발생한다. + * @since 1.0.0 */ - private boolean isDuplicatedSubGuide(SubGuide subGuide) { - return this.subGuides.stream() - .anyMatch(s -> s.equals(subGuide)); + private void verifySubGuideNonExistent(CommonCode type) { + boolean exists = this.subGuides.stream().anyMatch(guide -> guide.isSameType(type)); + if (exists) { + throw new GuideAlreadyExistsException(); + } } /** @@ -111,7 +111,7 @@ private boolean isDuplicatedSubGuide(SubGuide subGuide) { */ private SubGuide getSubGuide(CommonCode type) { return this.subGuides.stream() - .filter(s -> s.isSameType(type)) + .filter(guide -> guide.isSameType(type)) .findFirst() .orElseThrow(GuideNotFoundException::new); } @@ -149,7 +149,7 @@ private void updateAlertCount(String prevAlert, String curAlert) { */ private void plusAlertCount(String alert) { this.todayGuides.stream() - .filter(s -> s.isSameAlert(alert)) + .filter(guide -> guide.isSameAlert(alert)) .findFirst() .ifPresent(TodayGuide::plusCount); } @@ -162,7 +162,7 @@ private void plusAlertCount(String alert) { */ private void minusAlertCount(String alert) { this.todayGuides.stream() - .filter(s -> s.isSameAlert(alert)) + .filter(guide -> guide.isSameAlert(alert)) .findFirst() .ifPresent(TodayGuide::minusCount); } diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/SubGuide.java b/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/SubGuide.java index 01216971..e7f709ed 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/SubGuide.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/bloodsugar/document/SubGuide.java @@ -52,21 +52,4 @@ protected void update(SubGuide subGuide) { protected boolean isSameType(CommonCode type) { return this.type.equals(type); } - - /** - * equals 메서드 overriding - *

- * 타입이 같으면 같은 서브 가이드로 취급한다. - * - * @param obj 비교할 객체 - * @return 같으면 true, 다르면 false - * @since 1.6.1 - */ - @Override - public boolean equals(Object obj) { - if (obj instanceof SubGuide subGuide) { - return this.type.equals(subGuide.getType()); - } - return false; - } } diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/common/controller/GuideController.java b/src/main/java/com/coniverse/dangjang/domain/guide/common/controller/GuideController.java index 85df8dac..850992ec 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/common/controller/GuideController.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/common/controller/GuideController.java @@ -31,6 +31,22 @@ public class GuideController { private final DayGuideService dayGuideService; + /** + * 하루 요약 가이드를 조회하여 전달한다 + * + * @param date 조회날짜 + * @author EVE + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> getDayGuide(@ValidLocalDate @RequestParam String date, + @AuthenticationPrincipal User principal) { + DayGuideResponse dayGuideResponse = dayGuideService.getDayGuide(principal.getUsername(), date); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), dayGuideResponse)); + } + /** * 하루 요약 가이드를 조회하여 전달한다 * diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideController.java b/src/main/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideController.java index 1a21110d..8bab930f 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideController.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideController.java @@ -32,6 +32,24 @@ public class ExerciseGuideController { private final ExerciseGuideSearchService exerciseGuideSearchService; + /** + * 운동 조회 + * + * @param date 조회하는 날짜 + * @param principal 유저 정보 + * @return 운동 가이드 응답 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> get(@ValidLocalDate @RequestParam String date, + @AuthenticationPrincipal User principal) { + ExerciseGuideResponse response = exerciseGuideSearchService.findGuide(principal.getUsername(), date); + return ResponseEntity.ok() + .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 운동 조회 * diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/exercise/document/ExerciseGuide.java b/src/main/java/com/coniverse/dangjang/domain/guide/exercise/document/ExerciseGuide.java index 40ba52b4..5492d969 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/exercise/document/ExerciseGuide.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/exercise/document/ExerciseGuide.java @@ -64,35 +64,6 @@ public void changeAboutWalk(int needStepByTTS, int needStepByLastWeek, String co this.stepCount = stepCount; } - /** - * 걸음수와 관련된 속성들 중복 여부 판별 - * - * @param needStepByTTS 만보 대비 필요한 걸음수 - * @param needStepByLastWeek 지난주 평균 걸음수 대비 필요한 걸음수 - * @param comparedToLastWeek 지난주 걸음수와 비교한 가이드 - * @param content 만보 대비 걸음수에 대한 가이드 - * @return 중복 여부 - * @since 1.6.1 - */ - public boolean isDuplicateAboutStepCount(int needStepByTTS, int needStepByLastWeek, String comparedToLastWeek, String content, int stepCount) { - if (this.needStepByTTS == needStepByTTS && this.needStepByLastWeek == needStepByLastWeek && this.comparedToLastWeek == comparedToLastWeek - && this.content == content && this.stepCount == stepCount) { - return true; - } - return false; - } - - /** - * 걸음수와 관련된 속성들 중복 여부 판별 - * - * @param exerciseCalorie 운동 칼로리 - * @return 중복 여부 - * @since 1.6.1 - */ - public boolean isDuplicateAboutExerciseCalories(ExerciseCalorie exerciseCalorie) { - return this.exerciseCalories.stream().filter(exercise -> exercise.type().equals(exerciseCalorie.type())).findFirst().isPresent(); - } - /** * 수정된 운동 칼로리를 업데이트한다. *

diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/exercise/service/ExerciseGuideGenerateService.java b/src/main/java/com/coniverse/dangjang/domain/guide/exercise/service/ExerciseGuideGenerateService.java index e8ad4e9e..792728c6 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/exercise/service/ExerciseGuideGenerateService.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/exercise/service/ExerciseGuideGenerateService.java @@ -65,22 +65,16 @@ public GuideResponse createGuide(AnalysisData analysisData) { } // 걸음 수 추가 if (exerciseAnalysisData.getType().equals(CommonCode.STEP_COUNT)) { - if (!existExerciseGuide.isDuplicateAboutStepCount(exerciseAnalysisData.needStepByTTS, exerciseAnalysisData.needStepByLastWeek, - walkGuideContent.getGuideLastWeek(), walkGuideContent.getGuideTTS(), exerciseAnalysisData.getUnit())) { - existExerciseGuide.changeAboutWalk(exerciseAnalysisData.needStepByTTS, exerciseAnalysisData.needStepByLastWeek, - walkGuideContent.getGuideLastWeek(), walkGuideContent.getGuideTTS(), exerciseAnalysisData.getUnit()); - return exerciseGuideMapper.toResponse(exerciseGuideRepository.save(existExerciseGuide)); - } - } else { - ExerciseCalorie exerciseCalorie = new ExerciseCalorie(exerciseAnalysisData.getType(), exerciseAnalysisData.getCalorie(), - exerciseAnalysisData.getUnit()); - //운동 추가 - if (!existExerciseGuide.isDuplicateAboutExerciseCalories(exerciseCalorie)) { - existExerciseGuide.changeExerciseCalories(exerciseCalorie); - return exerciseGuideMapper.toResponse(exerciseGuideRepository.save(existExerciseGuide)); - } + existExerciseGuide.changeAboutWalk(exerciseAnalysisData.needStepByTTS, exerciseAnalysisData.needStepByLastWeek, + walkGuideContent.getGuideLastWeek(), walkGuideContent.getGuideTTS(), exerciseAnalysisData.getUnit()); + return exerciseGuideMapper.toResponse(exerciseGuideRepository.save(existExerciseGuide)); } - return exerciseGuideMapper.toResponse(existExerciseGuide); + //운동 추가 + ExerciseCalorie exerciseCalorie = new ExerciseCalorie(exerciseAnalysisData.getType(), exerciseAnalysisData.getCalorie(), + exerciseAnalysisData.getUnit()); + existExerciseGuide.changeExerciseCalories(exerciseCalorie); + return exerciseGuideMapper.toResponse(exerciseGuideRepository.save(existExerciseGuide)); + } /** diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideController.java b/src/main/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideController.java index 6b04d2e5..817d64b9 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideController.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideController.java @@ -32,6 +32,23 @@ public class WeightGuideController { private final WeightGuideSearchService weightGuideSearchService; + /** + * 날짜별 체중 가이드 조회 + * + * @param date 조회하는 날짜 + * @param principal 유저 정보 + * @author EVE + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> get(@ValidLocalDate @RequestParam String date, + @AuthenticationPrincipal User principal) { + WeightGuideResponse response = weightGuideSearchService.findGuide(principal.getUsername(), date); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 날짜별 체중 가이드 조회 * diff --git a/src/main/java/com/coniverse/dangjang/domain/guide/weight/service/WeightGuideGenerateService.java b/src/main/java/com/coniverse/dangjang/domain/guide/weight/service/WeightGuideGenerateService.java index 31b30ac5..52f9f2bf 100644 --- a/src/main/java/com/coniverse/dangjang/domain/guide/weight/service/WeightGuideGenerateService.java +++ b/src/main/java/com/coniverse/dangjang/domain/guide/weight/service/WeightGuideGenerateService.java @@ -10,7 +10,6 @@ import com.coniverse.dangjang.domain.code.enums.CommonCode; import com.coniverse.dangjang.domain.code.enums.GroupCode; import com.coniverse.dangjang.domain.guide.common.dto.response.GuideResponse; -import com.coniverse.dangjang.domain.guide.common.exception.GuideNotFoundException; import com.coniverse.dangjang.domain.guide.common.service.GuideGenerateService; import com.coniverse.dangjang.domain.guide.weight.document.WeightGuide; import com.coniverse.dangjang.domain.guide.weight.mapper.WeightMapper; @@ -43,14 +42,8 @@ public class WeightGuideGenerateService implements GuideGenerateService { public GuideResponse createGuide(AnalysisData analysisData) { WeightAnalysisData data = (WeightAnalysisData)analysisData; String content = createContent(data); - WeightGuide existWeightGuide; - try { - existWeightGuide = weightGuideSearchService.findByUserIdAndCreatedAt(data.getOauthId(), data.getCreatedAt().toString()); - } catch (GuideNotFoundException e) { - WeightGuide weightGuide = weightMapper.toDocument(data, content); - return weightMapper.toResponse(mongoTemplate.save(weightGuide)); - } - return weightMapper.toResponse(existWeightGuide); + WeightGuide weightGuide = weightMapper.toDocument(data, content); + return weightMapper.toResponse(mongoTemplate.save(weightGuide)); } /** diff --git a/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectController.java b/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectController.java index 598f6389..567c2df5 100644 --- a/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectController.java +++ b/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectController.java @@ -31,6 +31,23 @@ public class HealthConnectController { private final HealthConnectService healthConnectService; + /** + * health connect로 받은 건강 지표 데이터를 등록한다. + * + * @param requests 건강 지표 request post dto n개 + * @param principal 유저 정보 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping + public ResponseEntity> postHealthConnect(@Valid @RequestBody HealthConnectPostRequest requests, + @AuthenticationPrincipal User principal) { + String oauthId = principal.getUsername(); + healthConnectService.registerHealthConnectData(requests, oauthId); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * health connect로 받은 건강 지표 데이터를 등록한다. * @@ -48,6 +65,23 @@ public ResponseEntity> postHealthConnectV1(@Valid @Requ .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); } + /** + * health connect 연동 여부를 확인한다. + * + * @param requests health connect 연동 여부 데이터 + * @param principal 유저 정보 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PatchMapping("/interlock") + public ResponseEntity> interlockHealthConnect(@Valid @RequestBody HealthConnectRegisterRequest requests, + @AuthenticationPrincipal User principal) { + String oauthId = principal.getUsername(); + healthConnectService.interlockHealthConnect(requests, oauthId); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * health connect 연동 여부를 확인한다. * diff --git a/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricController.java b/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricController.java index 7fb098f1..1a409e49 100644 --- a/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricController.java +++ b/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricController.java @@ -48,6 +48,20 @@ public class HealthMetricController { private final HealthMetricChartSearchService healthMetricChartSearchService; private final HealthMetricSearchService healthMetricSearchService; + /** + * HTTP POST METHOD + * + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping + public ResponseEntity> post(@Valid @RequestBody HealthMetricPostRequest postRequest, + @AuthenticationPrincipal User principal) { + HealthMetricResponse response = healthMetricRegisterService.register(postRequest, principal.getUsername()); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * HTTP POST METHOD // TODO 작성 * @@ -62,6 +76,23 @@ public ResponseEntity> postHealthMet .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /* + * HTTP PATCH METHOD + * + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PatchMapping + public ResponseEntity> patch(@Valid @RequestBody HealthMetricPatchRequest patchRequest, + @AuthenticationPrincipal User principal) { + if (patchRequest.isSameType()) { + throw new SameTypeException(); + } + HealthMetricResponse response = healthMetricRegisterService.update(patchRequest, principal.getUsername()); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /* * HTTP PATCH METHOD // TODO 작성 * @@ -79,6 +110,25 @@ public ResponseEntity> patchHealthMe .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /** + * 건강지표 차트 데이터를 조회한다. + * + * @param startDate 조회 시작 날짜 + * @param endDate 조회 종료 날짜 + * @param principal 유저 정보 + * @return 건강지표 차트 데이터 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> getHealthMetrics(@ValidLocalDate @RequestParam String startDate, + @ValidLocalDate @RequestParam String endDate, @AuthenticationPrincipal User principal) { + HealthMetricChartResponse response = healthMetricChartSearchService.findHealthMetricChart(principal.getUsername(), LocalDate.parse(startDate), + LocalDate.parse(endDate)); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 건강지표 차트 데이터를 조회한다. * @@ -98,6 +148,22 @@ public ResponseEntity> getHealt .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /** + * 마지막 건강지표 생성일을 조회한다 + * + * @param principal 유저 정보 + * @return 유저의 마지막 건강지표 생성일 + * @since 1.1.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping("/last-date") + public ResponseEntity> getHealthMetricLastDate(@AuthenticationPrincipal User principal) { + String oauthId = principal.getUsername(); + HealthMetricLastDateResponse response = healthMetricSearchService.findHealthMetricLastDate(oauthId); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 마지막 건강지표 생성일을 조회한다 * @@ -114,6 +180,24 @@ public ResponseEntity> getLa .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /** + * 건강지표를 DELETE 요청한다. + * + * @param date 건강지표 생성일 + * @param type 건강지표 타입 + * @param principal 유저 정보 + * @return 성공 메시지 + * @since 1.3.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @DeleteMapping + public ResponseEntity> deleteHealthMetric(@ValidLocalDate @RequestParam String date, @NotBlank @RequestParam String type, + @AuthenticationPrincipal User principal) { + healthMetricRegisterService.remove(date, type, principal.getUsername()); + return ResponseEntity.noContent().build(); + } + /** * 건강지표를 DELETE 요청한다. * diff --git a/src/main/java/com/coniverse/dangjang/domain/infrastructure/sidecar/SideCarSender.java b/src/main/java/com/coniverse/dangjang/domain/infrastructure/sidecar/SideCarSender.java deleted file mode 100644 index 179495cd..00000000 --- a/src/main/java/com/coniverse/dangjang/domain/infrastructure/sidecar/SideCarSender.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.coniverse.dangjang.domain.infrastructure.sidecar; - -import org.springframework.stereotype.Service; -import org.springframework.web.client.ResourceAccessException; -import org.springframework.web.client.RestTemplate; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -/** - * sidecar로 메시지를 전송하는 서비스 - * - * @author TEO - * @since 1.6.1 - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class SideCarSender { - private final RestTemplate restTemplate; - - /** - * sidecar로 메시지를 전송한다. - * - * @param uri sidecar uri - * @param data 전송할 데이터 - * @since 1.6.1 - */ - public void send(String uri, T data) { - try { - restTemplate.postForEntity(uri, data, String.class); - } catch (ResourceAccessException e) { - log.error("fluentbit is dead"); - } - } -} diff --git a/src/main/java/com/coniverse/dangjang/domain/log/controller/AppLogController.java b/src/main/java/com/coniverse/dangjang/domain/log/controller/AppLogController.java index 92d456f1..b44be230 100644 --- a/src/main/java/com/coniverse/dangjang/domain/log/controller/AppLogController.java +++ b/src/main/java/com/coniverse/dangjang/domain/log/controller/AppLogController.java @@ -27,6 +27,19 @@ public class AppLogController { private final LogService logService; + /** + * 앱 로그를 post 요청한다. + * + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping + public ResponseEntity> post(@Valid @RequestBody LogRequest request) { + logService.sendLog(request); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * 앱 로그를 post 요청한다. * diff --git a/src/main/java/com/coniverse/dangjang/domain/log/service/LogService.java b/src/main/java/com/coniverse/dangjang/domain/log/service/LogService.java index 56453a5c..d4dccebe 100644 --- a/src/main/java/com/coniverse/dangjang/domain/log/service/LogService.java +++ b/src/main/java/com/coniverse/dangjang/domain/log/service/LogService.java @@ -2,27 +2,30 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.RestTemplate; -import com.coniverse.dangjang.domain.infrastructure.sidecar.SideCarSender; import com.coniverse.dangjang.domain.log.dto.app.AppLog; import com.coniverse.dangjang.domain.log.dto.request.LogRequest; import com.coniverse.dangjang.domain.log.mapper.LogMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** - * 사용자 행동 로그 서비스 + * log service * * @author TEO * @since 1.0.0 */ @Service @RequiredArgsConstructor +@Slf4j public class LogService { - private final SideCarSender sideCarSender; + private final RestTemplate restTemplate; private final LogMapper logMapper; @Value("${fluentbit.app-log-url}") - private final String uri; + private String url; /** * send app log to ETL @@ -31,6 +34,10 @@ public class LogService { */ public void sendLog(LogRequest request) { AppLog appLog = logMapper.toAppLog(request); - sideCarSender.send(uri, appLog); + try { + restTemplate.postForEntity(url, appLog, String.class); + } catch (ResourceAccessException e) { + log.error("fluentbit is dead"); + } } } diff --git a/src/main/java/com/coniverse/dangjang/domain/notification/controller/NotificationController.java b/src/main/java/com/coniverse/dangjang/domain/notification/controller/NotificationController.java index f2b57486..94627388 100644 --- a/src/main/java/com/coniverse/dangjang/domain/notification/controller/NotificationController.java +++ b/src/main/java/com/coniverse/dangjang/domain/notification/controller/NotificationController.java @@ -31,6 +31,21 @@ public class NotificationController { private final NotificationService notificationService; + /** + * 알림 목록 조회 + * + * @param user 사용자 + * @return notificationList 확인 안된 알림 목록 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> get(@AuthenticationPrincipal User user) { + NotificationListResponse response = new NotificationListResponse(notificationService.getNotificationList(user.getUsername())); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 미확인 알림 목록 조회 * @@ -46,6 +61,23 @@ public ResponseEntity> getUnread .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /** + * 확인된 알림 변경 요청 + *

+ * 클라이언트에서 사용자가 확인한 알림Id 목록을 서버로 전달, + * 서버에서 알림 확인 여부를 변경한다. + * + * @param notificationIdList 알림Id 목록 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PatchMapping + public ResponseEntity> patch(@Valid @RequestBody CheckNotificationIdRequest notificationIdList) { + notificationService.updateNotificationIsRead(notificationIdList); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * 확인된 푸쉬 알림 변경 *

diff --git a/src/main/java/com/coniverse/dangjang/domain/notification/service/NotificationSendService.java b/src/main/java/com/coniverse/dangjang/domain/notification/service/NotificationSendService.java index 4290e7f0..4a2842ac 100644 --- a/src/main/java/com/coniverse/dangjang/domain/notification/service/NotificationSendService.java +++ b/src/main/java/com/coniverse/dangjang/domain/notification/service/NotificationSendService.java @@ -2,26 +2,33 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.RestTemplate; -import com.coniverse.dangjang.domain.infrastructure.sidecar.SideCarSender; import com.coniverse.dangjang.domain.notification.dto.message.FcmMessage; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** - * 푸쉬 알림 전송 서비스 + * FluentBit를 통해 Notification을 전송하는 서비스 * * @author EVE * @since 1.1.0 */ +@Slf4j @Service @RequiredArgsConstructor public class NotificationSendService { - private final SideCarSender sideCarSender; + private final RestTemplate restTemplate; @Value("${fluentbit.notification-url}") - private final String uri; + private String url; public void sendMessage(FcmMessage message) { - sideCarSender.send(uri, message); + try { + restTemplate.postForEntity(url, message, String.class); + } catch (ResourceAccessException e) { + log.error("fluentbit is dead"); + } } } diff --git a/src/main/java/com/coniverse/dangjang/domain/point/controller/PointController.java b/src/main/java/com/coniverse/dangjang/domain/point/controller/PointController.java index 24bc07e7..d9498824 100644 --- a/src/main/java/com/coniverse/dangjang/domain/point/controller/PointController.java +++ b/src/main/java/com/coniverse/dangjang/domain/point/controller/PointController.java @@ -34,6 +34,22 @@ public class PointController { private final PointService pointService; + /** + * 포인트 상품 구매 + * + * @param request 포인트 구매하고자 하는 내역 정보 + * @return response 사용자 구매 완료 내역 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping + public ResponseEntity> purchaseProduct(@Valid @RequestBody UsePointRequest request, + @AuthenticationPrincipal User user) { + UsePointResponse response = pointService.purchaseProduct(user.getUsername(), request); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 포인트 상품 구매 * @@ -51,6 +67,20 @@ public ResponseEntity> purchaseProductV1 .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /** + * 구매 가능 포인트 상품 목록 조회 + * + * @return response 사용자 포인트 잔액, 구매 가능한 상품 내역 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping + public ResponseEntity> getProductList(@AuthenticationPrincipal User user) { + ProductListResponse response = pointService.getProducts(user.getUsername()); + return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * 구매 가능 포인트 상품 목록 조회 * diff --git a/src/main/java/com/coniverse/dangjang/domain/scheduler/service/SchedulerService.java b/src/main/java/com/coniverse/dangjang/domain/scheduler/service/SchedulerService.java index 2ca744fc..4310fc2f 100644 --- a/src/main/java/com/coniverse/dangjang/domain/scheduler/service/SchedulerService.java +++ b/src/main/java/com/coniverse/dangjang/domain/scheduler/service/SchedulerService.java @@ -17,13 +17,13 @@ import lombok.RequiredArgsConstructor; /** - * 스케쥴러 + * SchedulerService * * @author EVE * @since 1.1.0 */ -@Service @RequiredArgsConstructor +@Service @EnableSchedulerLock(defaultLockAtMostFor = "PT10S") public class SchedulerService { private final NotificationService notificationService; @@ -41,6 +41,7 @@ public class SchedulerService { @SchedulerLock(name = "SchedulerService_makeNotification", lockAtLeastFor = "PT60S", lockAtMostFor = "PT70S") public void makeNotification() { List fcmMessage = notificationService.makeAccessFcmMessage(); - fcmMessage.forEach(notificationSendService::sendMessage); + fcmMessage.forEach(message -> notificationSendService.sendMessage(message)); + } } diff --git a/src/main/java/com/coniverse/dangjang/domain/user/controller/SignupController.java b/src/main/java/com/coniverse/dangjang/domain/user/controller/SignupController.java index 68d3f7a3..9e613d12 100644 --- a/src/main/java/com/coniverse/dangjang/domain/user/controller/SignupController.java +++ b/src/main/java/com/coniverse/dangjang/domain/user/controller/SignupController.java @@ -29,6 +29,22 @@ public class SignupController { private final UserSignupService userSignupService; private final OauthLoginService oauthLoginService; + /** + * @param params 회원가입에 필요한 정보를 담아온다. + * @return 회원가입 후 로그인을 시도 , ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, authID)를 전달한다. + * @since 1.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping + public ResponseEntity> signUp(@Valid @RequestBody SignUpRequest params) { + LoginResponse loginResponse = userSignupService.signUp(params); + String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname()); + return ResponseEntity.ok() + .header(ACCESS_TOKEN, accessToken) + .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse)); + } + /** * 회원가입을 진행한다. * diff --git a/src/main/java/com/coniverse/dangjang/domain/user/controller/UserController.java b/src/main/java/com/coniverse/dangjang/domain/user/controller/UserController.java index a5a982a7..d7916463 100644 --- a/src/main/java/com/coniverse/dangjang/domain/user/controller/UserController.java +++ b/src/main/java/com/coniverse/dangjang/domain/user/controller/UserController.java @@ -43,6 +43,20 @@ public class UserController { private final UserWithdrawalService userWithdrawalService; private final NotificationService notificationService; + /** + * @param nickname 확인이 필요한 닉네임을 담아온다. + * @return 닉네임이 중복되지 않았으면 true, 중복된 닉네임이면 false를 담은 DuplicateNicknameResponse 객체를 반환한다. + * @since 1.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping("/duplicateNickname") + public ResponseEntity> checkDuplicateNickname( + @RequestParam @Pattern(regexp = "^[가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z0-9]{1,8}$", message = "닉네임은 영어,한글,숫자 1~8글자 이내로 이루어져있어야 합니다.") @NotBlank(message = "닉네임은 1~8글자 이내여야 합니다.") String nickname) { + DuplicateNicknameResponse duplicateNicknameResponse = userSignupService.checkDuplicatedNickname(nickname); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), duplicateNicknameResponse)); + } + /** * 닉네임 중복 여부 확인 * @@ -59,6 +73,20 @@ public ResponseEntity> verifyDu .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), duplicateNicknameResponse)); } + /** + * Mypage에 필요한 정보를 조회한다. + * + * @return MypageResponse 사용자 닉네임과 포인트 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping("/mypage") + public ResponseEntity> getMyPage(@AuthenticationPrincipal User user) { + MypageResponse response = mypageService.getMypage(user.getUsername()); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); + } + /** * Mypage에 필요한 사용자 정보 조회 * @@ -74,6 +102,21 @@ public ResponseEntity> getMyPageV1(@Authen .body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response)); } + /** + * 회원 탈퇴 + * + * @param user 사용자 정보 + * @return ResponseEntity + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @DeleteMapping("/withdrawal") + public ResponseEntity withdraw(@AuthenticationPrincipal User user) { + userWithdrawalService.withdraw(user.getUsername()); + return ResponseEntity.noContent().build(); + } + /** * 회원 탈퇴 * @@ -88,6 +131,22 @@ public ResponseEntity withdrawV1(@AuthenticationPrincipal User user) { return ResponseEntity.noContent().build(); } + /** + * fcmToken 저장 및 업데이트 + * + * @param user 사용자 정보 + * @param request fcmToken + * @return MyPageResponse 사용자 닉네임과 포인트 + * @since 1.0.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping("/fcmToken") + public ResponseEntity> postFcmToken(@AuthenticationPrincipal User user, @Valid @RequestBody PostFcmTokenRequest request) { + notificationService.saveOrUpdateFcmToken(request, user.getUsername()); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null)); + } + /** * fcm token 등록 * diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index 4614e74a..4aa7b597 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -29,6 +29,19 @@ public class VersionController { private final VersionService versionService; + /** + * 버전 정보를 GET 요청한다. + * + * @since 1.3.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @GetMapping("/intro") + public ResponseEntity>> getIntro() { + VersionResponse versionResponse = versionService.getVersionResponse(); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); + } + /** * 버전 정보를 조회한다. * @@ -42,6 +55,19 @@ public ResponseEntity>> getIntroV1() { return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); } + /** + * 버전 정보를 POST 요청한다. + * + * @since 1.3.0 + * @deprecated 1.6.0 + */ + @Deprecated(since = "1.6.0") + @PostMapping + public ResponseEntity>> postVersion(@Valid @RequestBody VersionRequest request) { + VersionResponse versionResponse = versionService.saveVersion(request); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); + } + /** * 버전 정보를 등록한다. * diff --git a/src/main/java/com/coniverse/dangjang/global/aop/aspect/log/LogAspect.java b/src/main/java/com/coniverse/dangjang/global/aop/aspect/log/LogAspect.java index c8727d7b..afa1b60e 100644 --- a/src/main/java/com/coniverse/dangjang/global/aop/aspect/log/LogAspect.java +++ b/src/main/java/com/coniverse/dangjang/global/aop/aspect/log/LogAspect.java @@ -4,7 +4,6 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; @@ -24,11 +23,10 @@ @Aspect @RequiredArgsConstructor @Slf4j -@Profile("!test & !performance") public class LogAspect { private final RestTemplate restTemplate; @Value("${fluentbit.server-log-url}") - private String uri; + private String url; /** * presentation layer logging @@ -83,7 +81,7 @@ private Object sendLog(String group, ProceedingJoinPoint joinPoint) throws Throw ServerLog serverLog = new ServerLog(group, joinPoint.getSignature(), end - start); try { - restTemplate.postForEntity(uri, serverLog, String.class); + restTemplate.postForEntity(url, serverLog, String.class); } catch (ResourceAccessException e) { log.error("fluentbit is dead"); } diff --git a/src/main/java/com/coniverse/dangjang/global/config/RedisConfig.java b/src/main/java/com/coniverse/dangjang/global/config/RedisConfig.java index aae0dccd..179a76f1 100644 --- a/src/main/java/com/coniverse/dangjang/global/config/RedisConfig.java +++ b/src/main/java/com/coniverse/dangjang/global/config/RedisConfig.java @@ -15,7 +15,7 @@ * @author EVE * @since 1.0.0 */ -@Profile("!test & !performance") +@Profile("!test") @Configuration @EnableRedisRepositories public class RedisConfig { diff --git a/src/main/java/com/coniverse/dangjang/global/exception/IncorrectCreatedAtException.java b/src/main/java/com/coniverse/dangjang/global/exception/IncorrectCreatedAtException.java new file mode 100644 index 00000000..0d73ea9d --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/global/exception/IncorrectCreatedAtException.java @@ -0,0 +1,17 @@ +package com.coniverse.dangjang.global.exception; + +import com.coniverse.dangjang.global.validator.ValidLocalDate; + +/** + * 생성일자가 올바르지 않을 때 발생하는 예외 + * + * @author TEO + * @since 1.0.0 + * @deprecated use {@link ValidLocalDate} + */ +@Deprecated(since = "1.0.0") +public class IncorrectCreatedAtException extends BusinessException { + public IncorrectCreatedAtException() { + super(400, "생성일자가 올바르지 않습니다."); + } +} diff --git a/src/main/java/com/coniverse/dangjang/global/util/CreatedAtUtil.java b/src/main/java/com/coniverse/dangjang/global/util/CreatedAtUtil.java new file mode 100644 index 00000000..2cb692d6 --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/global/util/CreatedAtUtil.java @@ -0,0 +1,34 @@ +package com.coniverse.dangjang.global.util; + +import java.time.DateTimeException; +import java.time.LocalDate; + +import com.coniverse.dangjang.global.exception.IncorrectCreatedAtException; +import com.coniverse.dangjang.global.validator.ValidLocalDate; + +/** + * 생성일자와 관련한 util + * + * @author TEO + * @since 1.0.0 + * @deprecated use {@link ValidLocalDate} + */ +@Deprecated(since = "1.0.0") +public class CreatedAtUtil { + /** + * 생성일자를 생성한다. + * + * @param month 생성일자의 월 + * @param day 생성일자의 일 + * @return LocalDate 생성일자 + * @throws IncorrectCreatedAtException 생성일자가 올바르지 않을 때 발생하는 예외 + * @since 1.0.0 + */ + public static LocalDate generateCreatedAt(int month, int day) { + try { + return LocalDate.of(LocalDate.now().getYear(), month, day); + } catch (DateTimeException e) { + throw new IncorrectCreatedAtException(); + } + } +} diff --git a/src/main/resources/config b/src/main/resources/config index a1f6cb3a..1f099250 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit a1f6cb3a181cd3408dcf27f172a45414223328de +Subproject commit 1f0992500bd9501f10d7d62bfc74bbfcaede0111 diff --git a/src/test/java/com/coniverse/dangjang/domain/auth/controller/LoginControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/auth/controller/LoginControllerTest.java index 37a99773..1bfc8f49 100644 --- a/src/test/java/com/coniverse/dangjang/domain/auth/controller/LoginControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/auth/controller/LoginControllerTest.java @@ -24,9 +24,7 @@ * @since 1.0.0 */ class LoginControllerTest extends ControllerTest { - private static final String KAKAO_URI = "/api/v1/auth/kakao"; - private static final String NAVER_URI = "/api/v1/auth/naver"; - private static final String LOGOUT_URI = "/api/v1/auth/logout"; + private static final String URI = "/api/auth"; private final LoginResponse response = 로그인_응답(); @Autowired private OauthLoginService oauthLoginService; @@ -43,7 +41,7 @@ class LoginControllerTest extends ControllerTest { given(oauthLoginService.getAuthToken(any())).willReturn(authToken.getAccessToken()); // when - ResultActions resultActions = post(mockMvc, KAKAO_URI, content); + ResultActions resultActions = post(mockMvc, URI + "/kakao", content); // then resultActions.andExpectAll( @@ -61,7 +59,7 @@ class LoginControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, KAKAO_URI, content); + ResultActions resultActions = post(mockMvc, URI + "/kakao", content); // then resultActions.andExpectAll( @@ -84,7 +82,7 @@ class LoginControllerTest extends ControllerTest { given(oauthLoginService.getAuthToken(any())).willReturn(authToken.getAccessToken()); // when - ResultActions resultActions = post(mockMvc, NAVER_URI, content); + ResultActions resultActions = post(mockMvc, URI + "/naver", content); // then resultActions.andExpectAll( @@ -101,7 +99,7 @@ class LoginControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, NAVER_URI, content); + ResultActions resultActions = post(mockMvc, URI + "/naver", content); // then resultActions.andExpectAll( @@ -115,10 +113,11 @@ class LoginControllerTest extends ControllerTest { @WithDangjangUser @Test void 로그아웃을_성공한다() throws Exception { + String subURL = "/logout"; LogoutFcmTokenRequest request = new LogoutFcmTokenRequest("fcmToken"); String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, LOGOUT_URI, content); + ResultActions resultActions = post(mockMvc, URI + subURL, content); // then resultActions.andExpectAll( diff --git a/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideControllerTest.java index dffeb052..5603b09a 100644 --- a/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/controller/BloodSugarGuideControllerTest.java @@ -25,7 +25,7 @@ */ @WithDangjangUser class BloodSugarGuideControllerTest extends ControllerTest { - private static final String URI = "/api/v1/guide/blood-sugar"; + public static final String URL = "/api/guide/blood-sugar"; private static final String createdAt = "2023-12-31"; @Autowired private BloodSugarGuideSearchService bloodSugarGuideSearchService; @@ -40,7 +40,7 @@ class BloodSugarGuideControllerTest extends ControllerTest { params.add("date", createdAt); // when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); // then resultActions.andExpectAll( @@ -69,7 +69,7 @@ class BloodSugarGuideControllerTest extends ControllerTest { params.add("date", createdAt); // when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); // then resultActions.andExpectAll( diff --git a/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/BloodSugarGuideGenerateServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/BloodSugarGuideGenerateServiceTest.java index 67dcfc63..3478f6e1 100644 --- a/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/BloodSugarGuideGenerateServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/BloodSugarGuideGenerateServiceTest.java @@ -8,12 +8,12 @@ import static org.junit.jupiter.api.Assertions.*; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -24,6 +24,7 @@ import com.coniverse.dangjang.domain.guide.bloodsugar.document.SubGuide; import com.coniverse.dangjang.domain.guide.bloodsugar.dto.SubGuideResponse; import com.coniverse.dangjang.domain.guide.bloodsugar.repository.BloodSugarGuideRepository; +import com.coniverse.dangjang.domain.guide.common.exception.GuideAlreadyExistsException; import com.coniverse.dangjang.domain.guide.common.exception.GuideNotFoundException; import com.coniverse.dangjang.domain.user.entity.User; @@ -32,6 +33,8 @@ * @since 1.0.0 */ @SpringBootTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) class BloodSugarGuideGenerateServiceTest { private static final User user = 유저_테오(); @Autowired @@ -43,17 +46,13 @@ class BloodSugarGuideGenerateServiceTest { @Autowired private BloodSugarGuideRepository bloodSugarGuideRepository; - @AfterEach - void tearDown() { - bloodSugarGuideRepository.deleteAll(); - } - + @Order(100) @Test void 혈당_가이드가_존재하지_않을_때_새로운_서브_가이드를_성공적으로_저장한다() { // given - final CommonCode type = CommonCode.BEFORE_BREAKFAST; - final String unit = "140"; - final BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, unit)); + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.BEFORE_BREAKFAST, "140") + ); // when SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); @@ -66,23 +65,20 @@ void tearDown() { () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), () -> { SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(type); - assertThat(서브_가이드.getUnit()).isEqualTo(unit); + assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } + @Order(150) @Test void 혈당_가이드가_존재할_때_새로운_서브_가이드를_성공적으로_저장한다() { // given - final CommonCode prevType = CommonCode.BEFORE_BREAKFAST; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, prevType, "160"))); - - final CommonCode curType = CommonCode.AFTER_BREAKFAST; - final String unit = "140"; - final BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, curType, unit)); + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.AFTER_BREAKFAST, "140") + ); // when SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); @@ -95,46 +91,33 @@ void tearDown() { () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), () -> { SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(1); - assertThat(서브_가이드.getType()).isEqualTo(curType); - assertThat(서브_가이드.getUnit()).isEqualTo(unit); + assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } + @Order(175) @Test - void 이미_존재하는_서브_가이드를_새로_저장할_때_건너뛴다() { + void 이미_존재하는_서브_가이드를_새로_저장할_때_예외를_발생한다() { // given - final CommonCode type = CommonCode.BEFORE_BREAKFAST; - final String unit = "140"; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, unit))); - - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, "200")); - - // when - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); - BloodSugarGuide 혈당_가이드 = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(user.getOauthId(), bloodSugarAnalysisData.getCreatedAt()); - - // then - assertAll( - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), - () -> { - SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(type); - assertThat(서브_가이드.getUnit()).isEqualTo(unit); - } + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.AFTER_BREAKFAST, "140") ); + + // when & then + assertThatThrownBy(() -> bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData)) + .isInstanceOf(GuideAlreadyExistsException.class); } + @Order(200) @Test void 경보와_가이드_내용이_수정된_서브_가이드를_성공적으로_저장한다() { // given - final CommonCode type = CommonCode.BEFORE_BREAKFAST; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, "140"))); - - final String unit = "200"; - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, unit)); + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.BEFORE_BREAKFAST, "200") + ); // when SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.updateGuide(bloodSugarAnalysisData); @@ -144,119 +127,103 @@ void tearDown() { assertAll( () -> assertThat(bloodSugarAnalysisData.getAlert().getTitle()).isEqualTo(서브_가이드_응답.alert()), () -> assertThat(서브_가이드_응답.unit()).isNull(), - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), + () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), () -> { SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(type); - assertThat(서브_가이드.getUnit()).isEqualTo(unit); + assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } + @Order(225) @Test void 수정할_서브_가이드가_존재하지_않을_때_예외를_발생한다() { // given - final CommonCode validType = CommonCode.BEFORE_BREAKFAST; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, validType, "140"))); - - final CommonCode invalidType = CommonCode.BEFORE_LUNCH; - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, invalidType, "200")); + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.BEFORE_DINNER, "200") + ); // when & then assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuide(bloodSugarAnalysisData)) .isInstanceOf(GuideNotFoundException.class); } + @Order(250) @Test void 타입이_수정된_서브_가이드를_성공적으로_저장한다() { // given - final CommonCode prevType = CommonCode.AFTER_BREAKFAST; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, prevType, "140"))); - - final CommonCode curType = CommonCode.ETC; - final String unit = "200"; - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, curType, unit)); + CommonCode 수정할_타입 = CommonCode.AFTER_BREAKFAST; + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.ETC, "200") + ); // when - SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, prevType); + SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, 수정할_타입); BloodSugarGuide 혈당_가이드 = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(user.getOauthId(), bloodSugarAnalysisData.getCreatedAt()); // then assertAll( () -> assertThat(bloodSugarAnalysisData.getAlert().getTitle()).isEqualTo(서브_가이드_응답.alert()), () -> assertThat(서브_가이드_응답.unit()).isNull(), - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), + () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), () -> { - SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(curType); - assertThat(서브_가이드.getUnit()).isEqualTo(unit); + SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(1); + assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } + @Order(275) @Test void 타입을_수정했을_때_수정_전_서브_가이드를_다시_수정하면_가이드가_존재하지_않다는_예외를_발생한다() { // given - final CommonCode beforeType = CommonCode.BEFORE_BREAKFAST; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, beforeType, "100"))); - final CommonCode curType = CommonCode.AFTER_BREAKFAST; - bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, curType, "200")), beforeType); - - final CommonCode type = CommonCode.BEFORE_LUNCH; - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, "150")); + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.BEFORE_LUNCH, "200") + ); // when & then - assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, beforeType)) + assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, CommonCode.AFTER_BREAKFAST)) .isInstanceOf(GuideNotFoundException.class); } + @Order(300) @Test - void 타입이_수정된_서브_가이드가_이미_존재할_경우_건너뛴다() { + void 타입이_수정된_서브_가이드가_이미_존재할_경우_예외를_발생한다() { // given - final CommonCode existsType = CommonCode.BEFORE_BREAKFAST; - final String unit = "140"; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, existsType, unit))); - final CommonCode targetType = CommonCode.AFTER_BREAKFAST; - bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, targetType, "200"))); - - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, existsType, "200")); - - // when - bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, targetType); - BloodSugarGuide 혈당_가이드 = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(user.getOauthId(), bloodSugarAnalysisData.getCreatedAt()); - - // then - assertAll( - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), - () -> { - SubGuide existsSubguide = 혈당_가이드.getSubGuides().get(0); - assertThat(existsSubguide.getUnit()).isEqualTo(unit); - SubGuide targetSubguide = 혈당_가이드.getSubGuides().get(1); - assertThat(targetSubguide.getType()).isEqualTo(targetType); - } + CommonCode 수정할_타입 = CommonCode.ETC; + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.BEFORE_BREAKFAST, "200") ); + + // when & then + assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, 수정할_타입)) + .isInstanceOf(GuideAlreadyExistsException.class); } + @Order(400) @Test void 서브_가이드를_저장하면_타입의_ordinal_순으로_정렬한다() { // given - List bloodSugarTypes = new ArrayList<>(혈당_타입()); - Collections.shuffle(bloodSugarTypes); - - // when - BloodSugarAnalysisData bloodSugarAnalysisData = 혈당_분석_데이터(user, bloodSugarTypes.get(0), "140"); - bloodSugarTypes.forEach(type -> bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, "140")))); + BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( + 혈당_분석_데이터(user, CommonCode.EMPTY_STOMACH, "140") + ); // when + SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); BloodSugarGuide 혈당_가이드 = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(user.getOauthId(), bloodSugarAnalysisData.getCreatedAt()); // then - SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(CommonCode.EMPTY_STOMACH); + assertAll( + () -> assertThat(혈당_가이드.getSubGuides()).hasSize(3), + () -> { + SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); + assertThat(서브_가이드.getType()).isEqualTo(CommonCode.EMPTY_STOMACH); + } + ); } @Test diff --git a/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/GenerateSubGuideTest.java b/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/GenerateSubGuideTest.java index c1aa954c..276b7101 100644 --- a/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/GenerateSubGuideTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/guide/bloodsugar/service/GenerateSubGuideTest.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.stream.Stream; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -32,6 +33,7 @@ * @since 1.0.0 */ @SpringBootTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class GenerateSubGuideTest { private static final User 전단계_환자 = 전단계_환자(); private static final User 당뇨_환자_강하제X_주사X = 당뇨_환자(false, false); @@ -45,7 +47,7 @@ class GenerateSubGuideTest { @MockBean private BloodSugarGuideRepository bloodSugarGuideRepository; - static Stream provideHypoglycemia() { + private Stream provideHypoglycemia() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "49", HypoglycemiaGuideFormat.NO_MEDICINE_AND_INJECTION), Arguments.of(당뇨_환자_강하제X_주사X, CommonCode.AFTER_BREAKFAST, "1", HypoglycemiaGuideFormat.NO_MEDICINE_AND_INJECTION), @@ -73,7 +75,7 @@ static Stream provideHypoglycemia() { ); } - static Stream provideHypoglycemiaSuspect() { + private Stream provideHypoglycemiaSuspect() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "50", 20), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "80", 10), @@ -100,7 +102,7 @@ static Stream provideHypoglycemiaSuspect() { ); } - static Stream provideNormal() { + private Stream provideNormal() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "79"), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "130"), @@ -130,7 +132,7 @@ static Stream provideNormal() { ); } - static Stream provideCaution() { + private Stream provideCaution() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "100", false, false, -1), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "199", false, true, -60), @@ -161,7 +163,7 @@ static Stream provideCaution() { ); } - static Stream provideWarning() { + private Stream provideWarning() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "126", false, false, -27), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "200", false, true, -61), diff --git a/src/test/java/com/coniverse/dangjang/domain/guide/common/controller/DayGuideControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/guide/common/controller/DayGuideControllerTest.java index ace628d2..dbdf65ec 100644 --- a/src/test/java/com/coniverse/dangjang/domain/guide/common/controller/DayGuideControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/guide/common/controller/DayGuideControllerTest.java @@ -28,7 +28,7 @@ class DayGuideControllerTest extends ControllerTest { @Autowired private DayGuideService dayGuideService; - private static final String URI = "/api/v1/guide"; + private static final String URL = "/api/guide"; private User user = 유저_테오(); private String 테오_닉네임 = user.getNickname(); private String 조회_날짜 = "2023-12-31"; @@ -44,7 +44,7 @@ class DayGuideControllerTest extends ControllerTest { MultiValueMap params = new LinkedMultiValueMap<>(); params.add("date", 조회_날짜); //when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); //then resultActions.andExpectAll( status().isOk(), @@ -63,7 +63,7 @@ class DayGuideControllerTest extends ControllerTest { MultiValueMap params = new LinkedMultiValueMap<>(); params.add("date", 유효하지_않은_날짜); //when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); //then resultActions.andExpectAll( status().isBadRequest(), diff --git a/src/test/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideControllerTest.java index 9fc3d8d9..e7ffbc39 100644 --- a/src/test/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/guide/exercise/controller/ExerciseGuideControllerTest.java @@ -22,7 +22,7 @@ */ @WithDangjangUser class ExerciseGuideControllerTest extends ControllerTest { - private static final String URI = "/api/v1/guide/exercise"; + private static final String URL = "/api/guide/exercise"; @Autowired private ExerciseGuideSearchService exerciseGuideSearchService; @@ -39,7 +39,7 @@ class ExerciseGuideControllerTest extends ControllerTest { params.add("date", 조회_날짜); //when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); //then resultActions.andExpectAll( status().isOk(), @@ -62,7 +62,7 @@ class ExerciseGuideControllerTest extends ControllerTest { params.add("date", 유효하지_않는_날짜); //when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); //then resultActions.andExpectAll( status().isBadRequest(), diff --git a/src/test/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideControllerTest.java index d5ce06ce..37e627fa 100644 --- a/src/test/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideControllerTest.java @@ -25,26 +25,26 @@ class WeightGuideControllerTest extends ControllerTest { @Autowired private WeightGuideSearchService weightGuideSearchService; - private static final String URI = "/api/v1/guide/weight"; - private static final String CREATED_AT = "2023-12-31"; + public static final String URL = "/api/guide/weight"; + private static final String createdAt = "2023-12-31"; private static final String 등록되지_않은_날짜 = "3000-12-33"; @Test void 체중_조회를_성공한다() throws Exception { // given - WeightGuideResponse response = 체중_가이드_응답(CREATED_AT); + WeightGuideResponse response = 체중_가이드_응답(createdAt); doReturn(response).when(weightGuideSearchService).findGuide(any(), any()); // when MultiValueMap params = new LinkedMultiValueMap<>(); params.add("date", "2023-12-31"); // when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); // then resultActions.andExpectAll( status().isOk(), jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), - jsonPath("$.data.createdAt").value(CREATED_AT), + jsonPath("$.data.createdAt").value(createdAt), jsonPath("$.data.title").value(response.title()), jsonPath("$.data.content").value(response.content()), jsonPath("$.data.weightDiff").value(response.weightDiff()), @@ -56,14 +56,14 @@ class WeightGuideControllerTest extends ControllerTest { @Test void 유효하지_않는_날짜로_체중_조회를_실패한다() throws Exception { // given - WeightGuideResponse response = 체중_가이드_응답(CREATED_AT); + WeightGuideResponse response = 체중_가이드_응답(createdAt); doReturn(null).when(weightGuideSearchService).findGuide(any(), any()); // when MultiValueMap params = new LinkedMultiValueMap<>(); params.add("date", 등록되지_않은_날짜); // when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); // then resultActions.andExpectAll( status().isBadRequest(), diff --git a/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectControllerTest.java index 616e8129..428e901a 100644 --- a/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectControllerTest.java @@ -20,8 +20,7 @@ */ @WithDangjangUser class HealthConnectControllerTest extends ControllerTest { - private static final String DATA_POST_URI = "/api/v1/health-connect"; - private static final String INTERLOCK_POST_URI = "/api/v1/health-connect/interlock"; + public static final String URL = "/api/health-connect"; @Test void 헬스_커넥트_데이터를_등록하면_성공_메시지를_반환한다() throws Exception { @@ -31,7 +30,7 @@ class HealthConnectControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, DATA_POST_URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -46,8 +45,9 @@ class HealthConnectControllerTest extends ControllerTest { // given HealthConnectRegisterRequest request = 헬스_커넥트_연동_요청(true); String content = objectMapper.writeValueAsString(request); + String subURL = "/interlock"; // when - ResultActions resultActions = patch(mockMvc, INTERLOCK_POST_URI, content); + ResultActions resultActions = patch(mockMvc, URL + subURL, content); // then resultActions.andExpectAll( diff --git a/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricControllerTest.java index 1e9d0c33..a1222c7e 100644 --- a/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthMetricControllerTest.java @@ -44,14 +44,14 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class HealthMetricControllerTest extends ControllerTest { - private static final String URI = "/api/v1/health-metric"; - private static LocalDate 시작_날짜 = LocalDate.parse("2023-12-31"); - private static LocalDate 마지막_날짜 = LocalDate.parse("2024-01-06"); - private static LocalDate 생성_날짜 = LocalDate.of(2023, 12, 31); - private static List 혈당차트 = 혈당차트_생성(생성_날짜, 100, 200); - private static List 체중차트 = 체중차트_생성(생성_날짜, 100); - private static List 걸음수차트 = 걸음수차트_생성(생성_날짜, 10000); - private static List 칼로리차트 = 칼로리차트_생성(생성_날짜, 400); + public static final String URL = "/api/health-metric"; + public static LocalDate 시작_날짜 = LocalDate.parse("2023-12-31"); + public static LocalDate 마지막_날짜 = LocalDate.parse("2024-01-06"); + public static LocalDate 생성_날짜 = LocalDate.of(2023, 12, 31); + public static List 혈당차트 = 혈당차트_생성(생성_날짜, 100, 200); + public static List 체중차트 = 체중차트_생성(생성_날짜, 100); + public static List 걸음수차트 = 걸음수차트_생성(생성_날짜, 10000); + public static List 칼로리차트 = 칼로리차트_생성(생성_날짜, 400); private final HealthMetricResponse response = 건강지표_등록_응답(); private String postContent; private String patchContent; @@ -75,7 +75,7 @@ void setUp() throws JsonProcessingException { given(healthMetricRegisterService.register(any(), anyString())).willReturn(response); // when - ResultActions resultActions = post(mockMvc, URI, postContent); + ResultActions resultActions = post(mockMvc, URL, postContent); // then resultActions.andExpectAll( @@ -99,7 +99,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -118,7 +118,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -138,7 +138,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -158,7 +158,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -176,7 +176,7 @@ void setUp() throws JsonProcessingException { given(healthMetricRegisterService.update(any(), anyString())).willReturn(response); // when - ResultActions resultActions = patch(mockMvc, URI, patchContent); + ResultActions resultActions = patch(mockMvc, URL, patchContent); // then resultActions.andExpectAll( @@ -200,7 +200,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = patch(mockMvc, URI, content); + ResultActions resultActions = patch(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -220,7 +220,7 @@ void setUp() throws JsonProcessingException { params.add("endDate", 마지막_날짜.toString()); //when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); //then resultActions.andExpectAll( @@ -243,7 +243,7 @@ void setUp() throws JsonProcessingException { params.add("endDate", 마지막_날짜.toString()); //when - ResultActions resultActions = get(mockMvc, URI, params); + ResultActions resultActions = get(mockMvc, URL, params); //then resultActions.andExpectAll( @@ -256,7 +256,7 @@ void setUp() throws JsonProcessingException { @Test void 건강지표_마지막_생성일을_전달한다() throws Exception { //given - String subUrl = URI + "/last-date"; + String subUrl = URL + "/last-date"; LocalDate lastDate = LocalDate.now(); HealthMetricLastDateResponse response = new HealthMetricLastDateResponse(lastDate); given(healthMetricSearchService.findHealthMetricLastDate(any())).willReturn(response); @@ -280,7 +280,7 @@ void setUp() throws JsonProcessingException { params.add("type", "아침식전"); // when - ResultActions resultActions = delete(mockMvc, URI, params); + ResultActions resultActions = delete(mockMvc, URL, params); // then resultActions.andExpectAll( @@ -297,7 +297,7 @@ void setUp() throws JsonProcessingException { params.add("type", "아침식전"); // when - ResultActions resultActions = delete(mockMvc, URI, params); + ResultActions resultActions = delete(mockMvc, URL, params); // then resultActions.andExpectAll( @@ -316,7 +316,7 @@ void setUp() throws JsonProcessingException { params.add("type", type); // when - ResultActions resultActions = delete(mockMvc, URI, params); + ResultActions resultActions = delete(mockMvc, URL, params); // then resultActions.andExpectAll( diff --git a/src/test/java/com/coniverse/dangjang/domain/log/controller/AppLogControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/log/controller/AppLogControllerTest.java index 52d483ec..af692805 100644 --- a/src/test/java/com/coniverse/dangjang/domain/log/controller/AppLogControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/log/controller/AppLogControllerTest.java @@ -18,7 +18,7 @@ * @since 1.0.0 */ class AppLogControllerTest extends ControllerTest { - private static final String URI = "/api/v1/log"; + private static final String URL = "/api/log"; @Test void 로그를_등록하면_성공_메시지를_반환한다() throws Exception { @@ -27,7 +27,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -45,7 +45,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -64,7 +64,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -83,7 +83,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -102,7 +102,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( @@ -121,7 +121,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( diff --git a/src/test/java/com/coniverse/dangjang/domain/notification/controller/NotificationControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/notification/controller/NotificationControllerTest.java index 40bfbb74..2be21c4c 100644 --- a/src/test/java/com/coniverse/dangjang/domain/notification/controller/NotificationControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/notification/controller/NotificationControllerTest.java @@ -28,7 +28,7 @@ class NotificationControllerTest extends ControllerTest { @Autowired private NotificationService notificationService; - private static final String URI = "/api/v1/notification"; + private static final String URL = "/api/notification"; @Test void 사용자의_알림목록을_조회하면_성공메세지를_반환한다() throws Exception { @@ -36,7 +36,7 @@ class NotificationControllerTest extends ControllerTest { List response = 사용자_알림_목록(); given(notificationService.getNotificationList(any())).willReturn(response); //when - ResultActions resultActions = get(mockMvc, URI); + ResultActions resultActions = get(mockMvc, URL); //then resultActions.andExpectAll( status().isOk(), @@ -55,7 +55,7 @@ class NotificationControllerTest extends ControllerTest { CheckNotificationIdRequest request = 사용자_알림_확인요청_목록(); String content = objectMapper.writeValueAsString(request); //when - ResultActions resultActions = patch(mockMvc, URI, content); + ResultActions resultActions = patch(mockMvc, URL, content); //then resultActions.andExpectAll( status().isOk() @@ -68,7 +68,7 @@ class NotificationControllerTest extends ControllerTest { CheckNotificationIdRequest request = new CheckNotificationIdRequest(List.of()); String content = objectMapper.writeValueAsString(request); //when - ResultActions resultActions = patch(mockMvc, URI, content); + ResultActions resultActions = patch(mockMvc, URL, content); //then resultActions.andExpectAll( status().isBadRequest() diff --git a/src/test/java/com/coniverse/dangjang/domain/point/controller/PointHistoryControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/point/controller/PointHistoryControllerTest.java index 849111ce..7f617aa7 100644 --- a/src/test/java/com/coniverse/dangjang/domain/point/controller/PointHistoryControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/point/controller/PointHistoryControllerTest.java @@ -27,7 +27,7 @@ */ @WithDangjangUser class PointHistoryControllerTest extends ControllerTest { - private static final String URI = "/api/v1/point"; + private static String URL = "/api/point"; @Autowired private PointService pointService; private List products = 구매가능_포인트_상품_목록(); @@ -39,7 +39,7 @@ class PointHistoryControllerTest extends ControllerTest { ProductListResponse response = new ProductListResponse(1000, products, descriptionListToEarnPoint); when(pointService.getProducts(any())).thenReturn(response); // when - ResultActions resultActions = get(mockMvc, URI); + ResultActions resultActions = get(mockMvc, URL); // then resultActions.andExpectAll( status().isOk(), @@ -60,7 +60,7 @@ class PointHistoryControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( status().isOk(), @@ -74,10 +74,11 @@ class PointHistoryControllerTest extends ControllerTest { void 조건에_맞지않는_request로_포인트_상품_구매를_요청하면_예외를_던진다() throws Exception { // given UsePointRequest request = new UsePointRequest("010-22-0000", "CU오천원금액권", "이름", "코멘트"); + String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, URL, content); // then resultActions.andExpectAll( status().isBadRequest(), diff --git a/src/test/java/com/coniverse/dangjang/domain/user/controller/SignupControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/user/controller/SignupControllerTest.java index dbaf5c20..7a7b25b2 100644 --- a/src/test/java/com/coniverse/dangjang/domain/user/controller/SignupControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/user/controller/SignupControllerTest.java @@ -29,7 +29,7 @@ * @since 1.0.0 */ class SignupControllerTest extends ControllerTest { - private static final String URI = "/api/v1/signup"; + private final String URI = "/api/signup"; @Autowired private UserSignupService userSignupService; @Autowired diff --git a/src/test/java/com/coniverse/dangjang/domain/user/controller/UserControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/user/controller/UserControllerTest.java index 09ea8c46..59bc97d8 100644 --- a/src/test/java/com/coniverse/dangjang/domain/user/controller/UserControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/user/controller/UserControllerTest.java @@ -19,18 +19,15 @@ * @since 1.0.0 */ class UserControllerTest extends ControllerTest { - private static final String NICKNAME_URI = "/api/v1/user/duplicateNickname"; - private static final String MY_PAGE_URI = "/api/v1/user/mypage"; - private static final String WITHDRAWAL_URI = "/api/v1/user/withdrawal"; + private static final String URI = "/api/user"; @Test void 닉네임을_받아와_확인을_성공한다() throws Exception { //given MultiValueMap params = new LinkedMultiValueMap<>(); params.add("nickname", "hello"); - // when - ResultActions resultActions = get(mockMvc, NICKNAME_URI, params); + ResultActions resultActions = get(mockMvc, URI + "/duplicateNickname", params); // then resultActions.andExpectAll( @@ -46,9 +43,8 @@ class UserControllerTest extends ControllerTest { //given MultiValueMap params = new LinkedMultiValueMap<>(); params.add("nickname", nickname); - // when - ResultActions resultActions = get(mockMvc, NICKNAME_URI, params); + ResultActions resultActions = get(mockMvc, URI + "/duplicateNickname", params); // then resultActions.andExpectAll( @@ -62,9 +58,10 @@ class UserControllerTest extends ControllerTest { void 마이페이지에_필요한_정보를_전달한다() throws Exception { //given MultiValueMap params = new LinkedMultiValueMap<>(); + String subURL = "/mypage"; // when - ResultActions resultActions = get(mockMvc, MY_PAGE_URI, params); + ResultActions resultActions = get(mockMvc, URI + subURL, params); // then resultActions.andExpectAll( @@ -76,8 +73,11 @@ class UserControllerTest extends ControllerTest { @WithDangjangUser @Test void 회원탈퇴를_성공한다() throws Exception { + // given + String subUrl = "/withdrawal"; + // when - ResultActions resultActions = delete(mockMvc, WITHDRAWAL_URI); + ResultActions resultActions = delete(mockMvc, URI + subUrl); // then resultActions.andExpectAll( diff --git a/src/test/java/com/coniverse/dangjang/domain/util/CreatedAtUtilTest.java b/src/test/java/com/coniverse/dangjang/domain/util/CreatedAtUtilTest.java new file mode 100644 index 00000000..d0a6fd53 --- /dev/null +++ b/src/test/java/com/coniverse/dangjang/domain/util/CreatedAtUtilTest.java @@ -0,0 +1,31 @@ +package com.coniverse.dangjang.domain.util; + +import static org.assertj.core.api.Assertions.*; + +import java.time.LocalDate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.coniverse.dangjang.global.exception.IncorrectCreatedAtException; +import com.coniverse.dangjang.global.util.CreatedAtUtil; + +/** + * @author TEO + * @since 1.0.0 + */ +@Deprecated(since = "1.0.0") +class CreatedAtUtilTest { + @Test + void 생성일자를_생성한다() { + assertThat(CreatedAtUtil.generateCreatedAt(1, 1)).isEqualTo(LocalDate.now().getYear() + "-01-01"); + + } + + @ParameterizedTest + @ValueSource(ints = {2, 4, 6, 9, 11}) + void 생성일자가_올바르지_않을_때_예외가_발생한다(int month) { + assertThatThrownBy(() -> CreatedAtUtil.generateCreatedAt(month, 31)).isInstanceOf(IncorrectCreatedAtException.class); + } +} diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 274424ac..3aee4994 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -22,8 +22,7 @@ * @since 1.3.0 */ class VersionControllerTest extends ControllerTest { - private static final String VERSION_URI = "/api/v1/version"; - private static final String INTRO_URI = "/api/v1/version/intro"; + private static final String URI = "/api/version"; @Autowired private VersionService versionService; @@ -35,7 +34,7 @@ class VersionControllerTest extends ControllerTest { doReturn(versionResponse).when(versionService).getVersionResponse(); // when - ResultActions resultActions = get(mockMvc, INTRO_URI); + ResultActions resultActions = get(mockMvc, URI + "/intro"); // then resultActions.andExpectAll( @@ -55,7 +54,7 @@ class VersionControllerTest extends ControllerTest { doReturn(versionResponse).when(versionService).saveVersion(any()); // when - ResultActions resultActions = post(mockMvc, VERSION_URI, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -74,7 +73,7 @@ class VersionControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(versionRequest); // when - ResultActions resultActions = post(mockMvc, VERSION_URI, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -93,7 +92,7 @@ class VersionControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(versionRequest); // when - ResultActions resultActions = post(mockMvc, VERSION_URI, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -112,7 +111,7 @@ class VersionControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(versionRequest); // when - ResultActions resultActions = post(mockMvc, VERSION_URI, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml index 4f5425de..fba0327d 100644 --- a/src/test/resources/config/application.yml +++ b/src/test/resources/config/application.yml @@ -68,6 +68,7 @@ version: api: version: uri-prefix: /api + sharing-uri-prefix: true logging: level: @@ -89,8 +90,6 @@ logging: web: trace given: apiversion: trace - de: - flapdoodle: off --- spring: