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 deleted file mode 100644 index dc9fda4d..00000000 --- a/src/main/java/com/coniverse/dangjang/domain/analysis/exception/UnitLessThanZeroException.java +++ /dev/null @@ -1,16 +0,0 @@ -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 9080ff36..a0eaea45 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,22 +33,6 @@ 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)); - } - /** * 카카오 로그인 * @@ -66,22 +50,6 @@ 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)); - } - /** * 네이버 로그인 * @@ -99,23 +67,6 @@ 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 재발급 * @@ -132,22 +83,6 @@ 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 8c9b42bb..e52a8924 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,23 +31,6 @@ 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 00b02fa0..4a0d8b52 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,7 +8,6 @@ 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; @@ -54,10 +53,12 @@ private BloodSugarGuide(String oauthId, String createdAt) { * @since 1.0.0 */ public void addSubGuide(SubGuide subGuide) { - verifySubGuideNonExistent(subGuide.getType()); + if (isDuplicatedSubGuide(subGuide)) { + return; + } this.subGuides.add(subGuide); - sortSubGuides(); plusAlertCount(subGuide.getAlert()); + sortSubGuides(); } /** @@ -80,7 +81,9 @@ public void updateSubGuide(SubGuide updatedSubGuide) { * @since 1.0.0 */ public void updateSubGuide(SubGuide updatedSubGuide, CommonCode prevType) { - verifySubGuideNonExistent(updatedSubGuide.getType()); + if (isDuplicatedSubGuide(updatedSubGuide)) { + return; + } SubGuide subGuide = getSubGuide(prevType); updateAlertCount(subGuide.getAlert(), updatedSubGuide.getAlert()); subGuide.update(updatedSubGuide); @@ -88,17 +91,14 @@ public void updateSubGuide(SubGuide updatedSubGuide, CommonCode prevType) { } /** - * 서브 가이드가 존재하는지 검증한다. + * 서브 가이드가 중복인지 확인한다. * - * @param type 서브 가이드 타입 - * @throws GuideAlreadyExistsException 이미 해당 가이드가 존재할 경우 발생한다. - * @since 1.0.0 + * @param subGuide 서브 가이드 + * @since 1.6.1 */ - private void verifySubGuideNonExistent(CommonCode type) { - boolean exists = this.subGuides.stream().anyMatch(guide -> guide.isSameType(type)); - if (exists) { - throw new GuideAlreadyExistsException(); - } + private boolean isDuplicatedSubGuide(SubGuide subGuide) { + return this.subGuides.stream() + .anyMatch(s -> s.equals(subGuide)); } /** @@ -111,7 +111,7 @@ private void verifySubGuideNonExistent(CommonCode type) { */ private SubGuide getSubGuide(CommonCode type) { return this.subGuides.stream() - .filter(guide -> guide.isSameType(type)) + .filter(s -> s.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(guide -> guide.isSameAlert(alert)) + .filter(s -> s.isSameAlert(alert)) .findFirst() .ifPresent(TodayGuide::plusCount); } @@ -162,7 +162,7 @@ private void plusAlertCount(String alert) { */ private void minusAlertCount(String alert) { this.todayGuides.stream() - .filter(guide -> guide.isSameAlert(alert)) + .filter(s -> s.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 e7f709ed..01216971 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,4 +52,21 @@ 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 850992ec..85df8dac 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,22 +31,6 @@ 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 8bab930f..1a21110d 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,24 +32,6 @@ 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/weight/controller/WeightGuideController.java b/src/main/java/com/coniverse/dangjang/domain/guide/weight/controller/WeightGuideController.java index 817d64b9..6b04d2e5 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,23 +32,6 @@ 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/healthmetric/controller/HealthConnectController.java b/src/main/java/com/coniverse/dangjang/domain/healthmetric/controller/HealthConnectController.java index 567c2df5..598f6389 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,23 +31,6 @@ 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로 받은 건강 지표 데이터를 등록한다. * @@ -65,23 +48,6 @@ 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 1a409e49..7fb098f1 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,20 +48,6 @@ 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 작성 * @@ -76,23 +62,6 @@ 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 작성 * @@ -110,25 +79,6 @@ 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)); - } - /** * 건강지표 차트 데이터를 조회한다. * @@ -148,22 +98,6 @@ 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)); - } - /** * 마지막 건강지표 생성일을 조회한다 * @@ -180,24 +114,6 @@ 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 new file mode 100644 index 00000000..179495cd --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/domain/infrastructure/sidecar/SideCarSender.java @@ -0,0 +1,36 @@ +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 b44be230..92d456f1 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,19 +27,6 @@ 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 d4dccebe..56453a5c 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,30 +2,27 @@ 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 RestTemplate restTemplate; + private final SideCarSender sideCarSender; private final LogMapper logMapper; @Value("${fluentbit.app-log-url}") - private String url; + private final String uri; /** * send app log to ETL @@ -34,10 +31,6 @@ public class LogService { */ public void sendLog(LogRequest request) { AppLog appLog = logMapper.toAppLog(request); - try { - restTemplate.postForEntity(url, appLog, String.class); - } catch (ResourceAccessException e) { - log.error("fluentbit is dead"); - } + sideCarSender.send(uri, appLog); } } 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 94627388..f2b57486 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,21 +31,6 @@ 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)); - } - /** * 미확인 알림 목록 조회 * @@ -61,23 +46,6 @@ 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 4a2842ac..4290e7f0 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,33 +2,26 @@ 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 RestTemplate restTemplate; + private final SideCarSender sideCarSender; @Value("${fluentbit.notification-url}") - private String url; + private final String uri; public void sendMessage(FcmMessage message) { - try { - restTemplate.postForEntity(url, message, String.class); - } catch (ResourceAccessException e) { - log.error("fluentbit is dead"); - } + sideCarSender.send(uri, message); } } 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 d9498824..24bc07e7 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,22 +34,6 @@ 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)); - } - /** * 포인트 상품 구매 * @@ -67,20 +51,6 @@ 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 4310fc2f..2ca744fc 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 */ -@RequiredArgsConstructor @Service +@RequiredArgsConstructor @EnableSchedulerLock(defaultLockAtMostFor = "PT10S") public class SchedulerService { private final NotificationService notificationService; @@ -41,7 +41,6 @@ public class SchedulerService { @SchedulerLock(name = "SchedulerService_makeNotification", lockAtLeastFor = "PT60S", lockAtMostFor = "PT70S") public void makeNotification() { List fcmMessage = notificationService.makeAccessFcmMessage(); - fcmMessage.forEach(message -> notificationSendService.sendMessage(message)); - + fcmMessage.forEach(notificationSendService::sendMessage); } } 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 9e613d12..68d3f7a3 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,22 +29,6 @@ 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 d7916463..a5a982a7 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,20 +43,6 @@ 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)); - } - /** * 닉네임 중복 여부 확인 * @@ -73,20 +59,6 @@ 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에 필요한 사용자 정보 조회 * @@ -102,21 +74,6 @@ 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(); - } - /** * 회원 탈퇴 * @@ -131,22 +88,6 @@ 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 4aa7b597..4614e74a 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,19 +29,6 @@ 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)); - } - /** * 버전 정보를 조회한다. * @@ -55,19 +42,6 @@ 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 afa1b60e..c8727d7b 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,6 +4,7 @@ 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; @@ -23,10 +24,11 @@ @Aspect @RequiredArgsConstructor @Slf4j +@Profile("!test & !performance") public class LogAspect { private final RestTemplate restTemplate; @Value("${fluentbit.server-log-url}") - private String url; + private String uri; /** * presentation layer logging @@ -81,7 +83,7 @@ private Object sendLog(String group, ProceedingJoinPoint joinPoint) throws Throw ServerLog serverLog = new ServerLog(group, joinPoint.getSignature(), end - start); try { - restTemplate.postForEntity(url, serverLog, String.class); + restTemplate.postForEntity(uri, 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 179a76f1..aae0dccd 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") +@Profile("!test & !performance") @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 deleted file mode 100644 index 0d73ea9d..00000000 --- a/src/main/java/com/coniverse/dangjang/global/exception/IncorrectCreatedAtException.java +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 2cb692d6..00000000 --- a/src/main/java/com/coniverse/dangjang/global/util/CreatedAtUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -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 1f099250..a1f6cb3a 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit 1f0992500bd9501f10d7d62bfc74bbfcaede0111 +Subproject commit a1f6cb3a181cd3408dcf27f172a45414223328de 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 1bfc8f49..37a99773 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,7 +24,9 @@ * @since 1.0.0 */ class LoginControllerTest extends ControllerTest { - private static final String URI = "/api/auth"; + 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 final LoginResponse response = 로그인_응답(); @Autowired private OauthLoginService oauthLoginService; @@ -41,7 +43,7 @@ class LoginControllerTest extends ControllerTest { given(oauthLoginService.getAuthToken(any())).willReturn(authToken.getAccessToken()); // when - ResultActions resultActions = post(mockMvc, URI + "/kakao", content); + ResultActions resultActions = post(mockMvc, KAKAO_URI, content); // then resultActions.andExpectAll( @@ -59,7 +61,7 @@ class LoginControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI + "/kakao", content); + ResultActions resultActions = post(mockMvc, KAKAO_URI, content); // then resultActions.andExpectAll( @@ -82,7 +84,7 @@ class LoginControllerTest extends ControllerTest { given(oauthLoginService.getAuthToken(any())).willReturn(authToken.getAccessToken()); // when - ResultActions resultActions = post(mockMvc, URI + "/naver", content); + ResultActions resultActions = post(mockMvc, NAVER_URI, content); // then resultActions.andExpectAll( @@ -99,7 +101,7 @@ class LoginControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URI + "/naver", content); + ResultActions resultActions = post(mockMvc, NAVER_URI, content); // then resultActions.andExpectAll( @@ -113,11 +115,10 @@ 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, URI + subURL, content); + ResultActions resultActions = post(mockMvc, LOGOUT_URI, 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 5603b09a..dffeb052 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 { - public static final String URL = "/api/guide/blood-sugar"; + private static final String URI = "/api/v1/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, URL, params); + ResultActions resultActions = get(mockMvc, URI, params); // then resultActions.andExpectAll( @@ -69,7 +69,7 @@ class BloodSugarGuideControllerTest extends ControllerTest { params.add("date", createdAt); // when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, 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 3478f6e1..67dcfc63 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.MethodOrderer; -import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.AfterEach; 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,7 +24,6 @@ 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; @@ -33,8 +32,6 @@ * @since 1.0.0 */ @SpringBootTest -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) class BloodSugarGuideGenerateServiceTest { private static final User user = 유저_테오(); @Autowired @@ -46,13 +43,17 @@ class BloodSugarGuideGenerateServiceTest { @Autowired private BloodSugarGuideRepository bloodSugarGuideRepository; - @Order(100) + @AfterEach + void tearDown() { + bloodSugarGuideRepository.deleteAll(); + } + @Test void 혈당_가이드가_존재하지_않을_때_새로운_서브_가이드를_성공적으로_저장한다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.BEFORE_BREAKFAST, "140") - ); + final CommonCode type = CommonCode.BEFORE_BREAKFAST; + final String unit = "140"; + final BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, unit)); // when SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); @@ -65,20 +66,23 @@ class BloodSugarGuideGenerateServiceTest { () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), () -> { SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); + assertThat(서브_가이드.getType()).isEqualTo(type); + assertThat(서브_가이드.getUnit()).isEqualTo(unit); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } - @Order(150) @Test void 혈당_가이드가_존재할_때_새로운_서브_가이드를_성공적으로_저장한다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.AFTER_BREAKFAST, "140") - ); + 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)); // when SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); @@ -91,33 +95,46 @@ class BloodSugarGuideGenerateServiceTest { () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), () -> { SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(1); - assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); + assertThat(서브_가이드.getType()).isEqualTo(curType); + assertThat(서브_가이드.getUnit()).isEqualTo(unit); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } - @Order(175) @Test - void 이미_존재하는_서브_가이드를_새로_저장할_때_예외를_발생한다() { + void 이미_존재하는_서브_가이드를_새로_저장할_때_건너뛴다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.AFTER_BREAKFAST, "140") - ); + final CommonCode type = CommonCode.BEFORE_BREAKFAST; + final String unit = "140"; + bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisStrategy.analyze(혈당_분석_데이터(user, type, unit))); - // when & then - assertThatThrownBy(() -> bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData)) - .isInstanceOf(GuideAlreadyExistsException.class); + 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); + } + ); } - @Order(200) @Test void 경보와_가이드_내용이_수정된_서브_가이드를_성공적으로_저장한다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.BEFORE_BREAKFAST, "200") - ); + 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)); // when SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.updateGuide(bloodSugarAnalysisData); @@ -127,103 +144,119 @@ class BloodSugarGuideGenerateServiceTest { assertAll( () -> assertThat(bloodSugarAnalysisData.getAlert().getTitle()).isEqualTo(서브_가이드_응답.alert()), () -> assertThat(서브_가이드_응답.unit()).isNull(), - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), + () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), () -> { SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); + assertThat(서브_가이드.getType()).isEqualTo(type); + assertThat(서브_가이드.getUnit()).isEqualTo(unit); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } - @Order(225) @Test void 수정할_서브_가이드가_존재하지_않을_때_예외를_발생한다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.BEFORE_DINNER, "200") - ); + 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")); // when & then assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuide(bloodSugarAnalysisData)) .isInstanceOf(GuideNotFoundException.class); } - @Order(250) @Test void 타입이_수정된_서브_가이드를_성공적으로_저장한다() { // given - CommonCode 수정할_타입 = CommonCode.AFTER_BREAKFAST; - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.ETC, "200") - ); + 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)); // when - SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, 수정할_타입); + SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, prevType); BloodSugarGuide 혈당_가이드 = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(user.getOauthId(), bloodSugarAnalysisData.getCreatedAt()); // then assertAll( () -> assertThat(bloodSugarAnalysisData.getAlert().getTitle()).isEqualTo(서브_가이드_응답.alert()), () -> assertThat(서브_가이드_응답.unit()).isNull(), - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(2), + () -> assertThat(혈당_가이드.getSubGuides()).hasSize(1), () -> { - SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(1); - assertThat(서브_가이드.getType()).isEqualTo(bloodSugarAnalysisData.getType()); + SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); + assertThat(서브_가이드.getType()).isEqualTo(curType); + assertThat(서브_가이드.getUnit()).isEqualTo(unit); assertThat(서브_가이드.getContent()).isEqualTo(서브_가이드_응답.content()); assertThat(서브_가이드.getAlert()).isEqualTo(서브_가이드_응답.alert()); } ); } - @Order(275) @Test void 타입을_수정했을_때_수정_전_서브_가이드를_다시_수정하면_가이드가_존재하지_않다는_예외를_발생한다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.BEFORE_LUNCH, "200") - ); + 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")); // when & then - assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, CommonCode.AFTER_BREAKFAST)) + assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, beforeType)) .isInstanceOf(GuideNotFoundException.class); } - @Order(300) @Test - void 타입이_수정된_서브_가이드가_이미_존재할_경우_예외를_발생한다() { + void 타입이_수정된_서브_가이드가_이미_존재할_경우_건너뛴다() { // given - CommonCode 수정할_타입 = CommonCode.ETC; - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.BEFORE_BREAKFAST, "200") - ); + 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"))); - // when & then - assertThatThrownBy(() -> bloodSugarGuideGenerateService.updateGuideWithType(bloodSugarAnalysisData, 수정할_타입)) - .isInstanceOf(GuideAlreadyExistsException.class); + 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); + } + ); } - @Order(400) @Test void 서브_가이드를_저장하면_타입의_ordinal_순으로_정렬한다() { // given - BloodSugarAnalysisData bloodSugarAnalysisData = (BloodSugarAnalysisData)bloodSugarAnalysisStrategy.analyze( - 혈당_분석_데이터(user, CommonCode.EMPTY_STOMACH, "140") - ); + 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")))); // when - SubGuideResponse 서브_가이드_응답 = (SubGuideResponse)bloodSugarGuideGenerateService.createGuide(bloodSugarAnalysisData); BloodSugarGuide 혈당_가이드 = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(user.getOauthId(), bloodSugarAnalysisData.getCreatedAt()); // then - assertAll( - () -> assertThat(혈당_가이드.getSubGuides()).hasSize(3), - () -> { - SubGuide 서브_가이드 = 혈당_가이드.getSubGuides().get(0); - assertThat(서브_가이드.getType()).isEqualTo(CommonCode.EMPTY_STOMACH); - } - ); + 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 276b7101..c1aa954c 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,7 +8,6 @@ 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; @@ -33,7 +32,6 @@ * @since 1.0.0 */ @SpringBootTest -@TestInstance(TestInstance.Lifecycle.PER_CLASS) class GenerateSubGuideTest { private static final User 전단계_환자 = 전단계_환자(); private static final User 당뇨_환자_강하제X_주사X = 당뇨_환자(false, false); @@ -47,7 +45,7 @@ class GenerateSubGuideTest { @MockBean private BloodSugarGuideRepository bloodSugarGuideRepository; - private Stream provideHypoglycemia() { + static 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), @@ -75,7 +73,7 @@ private Stream provideHypoglycemia() { ); } - private Stream provideHypoglycemiaSuspect() { + static Stream provideHypoglycemiaSuspect() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "50", 20), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "80", 10), @@ -102,7 +100,7 @@ private Stream provideHypoglycemiaSuspect() { ); } - private Stream provideNormal() { + static Stream provideNormal() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "79"), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "130"), @@ -132,7 +130,7 @@ private Stream provideNormal() { ); } - private Stream provideCaution() { + static Stream provideCaution() { return Stream.of( Arguments.of(전단계_환자, CommonCode.EMPTY_STOMACH, "100", false, false, -1), Arguments.of(전단계_환자, CommonCode.AFTER_BREAKFAST, "199", false, true, -60), @@ -163,7 +161,7 @@ private Stream provideCaution() { ); } - private Stream provideWarning() { + static 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 dbdf65ec..ace628d2 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 URL = "/api/guide"; + private static final String URI = "/api/v1/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, URL, params); + ResultActions resultActions = get(mockMvc, URI, 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, URL, params); + ResultActions resultActions = get(mockMvc, URI, 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 e7ffbc39..9fc3d8d9 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 URL = "/api/guide/exercise"; + private static final String URI = "/api/v1/guide/exercise"; @Autowired private ExerciseGuideSearchService exerciseGuideSearchService; @@ -39,7 +39,7 @@ class ExerciseGuideControllerTest extends ControllerTest { params.add("date", 조회_날짜); //when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, params); //then resultActions.andExpectAll( status().isOk(), @@ -62,7 +62,7 @@ class ExerciseGuideControllerTest extends ControllerTest { params.add("date", 유효하지_않는_날짜); //when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, 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 37e627fa..d5ce06ce 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; - public static final String URL = "/api/guide/weight"; - private static final String createdAt = "2023-12-31"; + private static final String URI = "/api/v1/guide/weight"; + private static final String CREATED_AT = "2023-12-31"; private static final String 등록되지_않은_날짜 = "3000-12-33"; @Test void 체중_조회를_성공한다() throws Exception { // given - WeightGuideResponse response = 체중_가이드_응답(createdAt); + WeightGuideResponse response = 체중_가이드_응답(CREATED_AT); doReturn(response).when(weightGuideSearchService).findGuide(any(), any()); // when MultiValueMap params = new LinkedMultiValueMap<>(); params.add("date", "2023-12-31"); // when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, params); // then resultActions.andExpectAll( status().isOk(), jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), - jsonPath("$.data.createdAt").value(createdAt), + jsonPath("$.data.createdAt").value(CREATED_AT), 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 = 체중_가이드_응답(createdAt); + WeightGuideResponse response = 체중_가이드_응답(CREATED_AT); doReturn(null).when(weightGuideSearchService).findGuide(any(), any()); // when MultiValueMap params = new LinkedMultiValueMap<>(); params.add("date", 등록되지_않은_날짜); // when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, 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 428e901a..616e8129 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,7 +20,8 @@ */ @WithDangjangUser class HealthConnectControllerTest extends ControllerTest { - public static final String URL = "/api/health-connect"; + private static final String DATA_POST_URI = "/api/v1/health-connect"; + private static final String INTERLOCK_POST_URI = "/api/v1/health-connect/interlock"; @Test void 헬스_커넥트_데이터를_등록하면_성공_메시지를_반환한다() throws Exception { @@ -30,7 +31,7 @@ class HealthConnectControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, DATA_POST_URI, content); // then resultActions.andExpectAll( @@ -45,9 +46,8 @@ class HealthConnectControllerTest extends ControllerTest { // given HealthConnectRegisterRequest request = 헬스_커넥트_연동_요청(true); String content = objectMapper.writeValueAsString(request); - String subURL = "/interlock"; // when - ResultActions resultActions = patch(mockMvc, URL + subURL, content); + ResultActions resultActions = patch(mockMvc, INTERLOCK_POST_URI, 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 a1222c7e..1e9d0c33 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 { - 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 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); 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, URL, postContent); + ResultActions resultActions = post(mockMvc, URI, postContent); // then resultActions.andExpectAll( @@ -99,7 +99,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -118,7 +118,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -138,7 +138,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -158,7 +158,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -176,7 +176,7 @@ void setUp() throws JsonProcessingException { given(healthMetricRegisterService.update(any(), anyString())).willReturn(response); // when - ResultActions resultActions = patch(mockMvc, URL, patchContent); + ResultActions resultActions = patch(mockMvc, URI, patchContent); // then resultActions.andExpectAll( @@ -200,7 +200,7 @@ void setUp() throws JsonProcessingException { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = patch(mockMvc, URL, content); + ResultActions resultActions = patch(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -220,7 +220,7 @@ void setUp() throws JsonProcessingException { params.add("endDate", 마지막_날짜.toString()); //when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, params); //then resultActions.andExpectAll( @@ -243,7 +243,7 @@ void setUp() throws JsonProcessingException { params.add("endDate", 마지막_날짜.toString()); //when - ResultActions resultActions = get(mockMvc, URL, params); + ResultActions resultActions = get(mockMvc, URI, params); //then resultActions.andExpectAll( @@ -256,7 +256,7 @@ void setUp() throws JsonProcessingException { @Test void 건강지표_마지막_생성일을_전달한다() throws Exception { //given - String subUrl = URL + "/last-date"; + String subUrl = URI + "/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, URL, params); + ResultActions resultActions = delete(mockMvc, URI, params); // then resultActions.andExpectAll( @@ -297,7 +297,7 @@ void setUp() throws JsonProcessingException { params.add("type", "아침식전"); // when - ResultActions resultActions = delete(mockMvc, URL, params); + ResultActions resultActions = delete(mockMvc, URI, params); // then resultActions.andExpectAll( @@ -316,7 +316,7 @@ void setUp() throws JsonProcessingException { params.add("type", type); // when - ResultActions resultActions = delete(mockMvc, URL, params); + ResultActions resultActions = delete(mockMvc, URI, 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 af692805..52d483ec 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 URL = "/api/log"; + private static final String URI = "/api/v1/log"; @Test void 로그를_등록하면_성공_메시지를_반환한다() throws Exception { @@ -27,7 +27,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -45,7 +45,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -64,7 +64,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -83,7 +83,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -102,7 +102,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( @@ -121,7 +121,7 @@ class AppLogControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, 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 2be21c4c..40bfbb74 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 URL = "/api/notification"; + private static final String URI = "/api/v1/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, URL); + ResultActions resultActions = get(mockMvc, URI); //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, URL, content); + ResultActions resultActions = patch(mockMvc, URI, 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, URL, content); + ResultActions resultActions = patch(mockMvc, URI, 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 7f617aa7..849111ce 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 String URL = "/api/point"; + private static final String URI = "/api/v1/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, URL); + ResultActions resultActions = get(mockMvc, URI); // then resultActions.andExpectAll( status().isOk(), @@ -60,7 +60,7 @@ class PointHistoryControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(request); // when - ResultActions resultActions = post(mockMvc, URL, content); + ResultActions resultActions = post(mockMvc, URI, content); // then resultActions.andExpectAll( status().isOk(), @@ -74,11 +74,10 @@ 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, URL, content); + ResultActions resultActions = post(mockMvc, URI, 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 7a7b25b2..dbaf5c20 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 final String URI = "/api/signup"; + private static final String URI = "/api/v1/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 59bc97d8..09ea8c46 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,15 +19,18 @@ * @since 1.0.0 */ class UserControllerTest extends ControllerTest { - private static final String URI = "/api/user"; + 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"; @Test void 닉네임을_받아와_확인을_성공한다() throws Exception { //given MultiValueMap params = new LinkedMultiValueMap<>(); params.add("nickname", "hello"); + // when - ResultActions resultActions = get(mockMvc, URI + "/duplicateNickname", params); + ResultActions resultActions = get(mockMvc, NICKNAME_URI, params); // then resultActions.andExpectAll( @@ -43,8 +46,9 @@ class UserControllerTest extends ControllerTest { //given MultiValueMap params = new LinkedMultiValueMap<>(); params.add("nickname", nickname); + // when - ResultActions resultActions = get(mockMvc, URI + "/duplicateNickname", params); + ResultActions resultActions = get(mockMvc, NICKNAME_URI, params); // then resultActions.andExpectAll( @@ -58,10 +62,9 @@ class UserControllerTest extends ControllerTest { void 마이페이지에_필요한_정보를_전달한다() throws Exception { //given MultiValueMap params = new LinkedMultiValueMap<>(); - String subURL = "/mypage"; // when - ResultActions resultActions = get(mockMvc, URI + subURL, params); + ResultActions resultActions = get(mockMvc, MY_PAGE_URI, params); // then resultActions.andExpectAll( @@ -73,11 +76,8 @@ class UserControllerTest extends ControllerTest { @WithDangjangUser @Test void 회원탈퇴를_성공한다() throws Exception { - // given - String subUrl = "/withdrawal"; - // when - ResultActions resultActions = delete(mockMvc, URI + subUrl); + ResultActions resultActions = delete(mockMvc, WITHDRAWAL_URI); // 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 deleted file mode 100644 index d0a6fd53..00000000 --- a/src/test/java/com/coniverse/dangjang/domain/util/CreatedAtUtilTest.java +++ /dev/null @@ -1,31 +0,0 @@ -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 3aee4994..274424ac 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,7 +22,8 @@ * @since 1.3.0 */ class VersionControllerTest extends ControllerTest { - private static final String URI = "/api/version"; + private static final String VERSION_URI = "/api/v1/version"; + private static final String INTRO_URI = "/api/v1/version/intro"; @Autowired private VersionService versionService; @@ -34,7 +35,7 @@ class VersionControllerTest extends ControllerTest { doReturn(versionResponse).when(versionService).getVersionResponse(); // when - ResultActions resultActions = get(mockMvc, URI + "/intro"); + ResultActions resultActions = get(mockMvc, INTRO_URI); // then resultActions.andExpectAll( @@ -54,7 +55,7 @@ class VersionControllerTest extends ControllerTest { doReturn(versionResponse).when(versionService).saveVersion(any()); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, VERSION_URI, content); // then resultActions.andExpectAll( @@ -73,7 +74,7 @@ class VersionControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(versionRequest); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, VERSION_URI, content); // then resultActions.andExpectAll( @@ -92,7 +93,7 @@ class VersionControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(versionRequest); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, VERSION_URI, content); // then resultActions.andExpectAll( @@ -111,7 +112,7 @@ class VersionControllerTest extends ControllerTest { String content = objectMapper.writeValueAsString(versionRequest); // when - ResultActions resultActions = post(mockMvc, URI, content); + ResultActions resultActions = post(mockMvc, VERSION_URI, content); // then resultActions.andExpectAll( diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml index fba0327d..4f5425de 100644 --- a/src/test/resources/config/application.yml +++ b/src/test/resources/config/application.yml @@ -68,7 +68,6 @@ version: api: version: uri-prefix: /api - sharing-uri-prefix: true logging: level: @@ -90,6 +89,8 @@ logging: web: trace given: apiversion: trace + de: + flapdoodle: off --- spring: