From 0d40a839f8b2b9a5577f530a2ccdaf064363e2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=83=81=EB=AF=BC?= Date: Thu, 23 May 2024 11:55:57 +0900 Subject: [PATCH] =?UTF-8?q?Feat/81=20=EC=9D=98=EC=82=AC/=EC=84=BC=ED=84=B0?= =?UTF-8?q?=20=EC=95=B1=EC=97=90=EC=84=9C=20=ED=99=98=EC=9E=90=EC=9D=98=20?= =?UTF-8?q?=EB=AC=B4=EB=93=9C=20=EB=B0=8F=20=EC=B0=A8=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20(#82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(#81): 의사/센터 앱에서 환자 무드 및 차트 조회 기능 추가 * refactor(#81): 메소드 파라미터 리팩토링 --- .../mood/controller/MoodChartController.java | 57 ++++++++++++++++++- .../api/mood/controller/MoodController.java | 17 +++++- .../api/mood/service/MoodChartService.java | 12 ++-- .../remind/api/mood/service/MoodService.java | 4 +- .../core/security/config/SecuirityConfig.java | 2 + 5 files changed, 80 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/remind/api/mood/controller/MoodChartController.java b/src/main/java/com/remind/api/mood/controller/MoodChartController.java index 1af0470..78edb9e 100644 --- a/src/main/java/com/remind/api/mood/controller/MoodChartController.java +++ b/src/main/java/com/remind/api/mood/controller/MoodChartController.java @@ -19,6 +19,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -45,7 +46,26 @@ public ResponseEntity> getMoodCha @Parameter(description = "마지막으로 조회한 일") @RequestParam("day") Integer day, @Parameter(description = "한 페이지 속 데이터 갯수") @RequestParam("size") Integer size) { return ResponseEntity.ok( - new ApiSuccessResponse<>(moodChartService.getMoodChart(userDetails, year, month, day, size))); + new ApiSuccessResponse<>( + moodChartService.getMoodChart(userDetails.getMemberId(), year, month, day, size))); + } + + @Operation( + summary = "의사/센터의 특정 환자 무드 차트 조회" + ) + @ApiResponse( + responseCode = "200", description = "무드 차트 조회 성공 응답입니다.", useReturnTypeSchema = true + ) + @GetMapping + public ResponseEntity> getMoodChart( + @AuthenticationPrincipal UserDetailsImpl userDetails, + @Parameter(description = "년도") @RequestParam("year") Integer year, + @Parameter(description = "월") @RequestParam("month") Integer month, + @Parameter(description = "마지막으로 조회한 일") @RequestParam("day") Integer day, + @Parameter(description = "한 페이지 속 데이터 갯수") @RequestParam("size") Integer size, + @Parameter(description = "조회하고자 하는 memberId") @RequestParam("memberId") Long memberId) { + return ResponseEntity.ok( + new ApiSuccessResponse<>(moodChartService.getMoodChart(memberId, year, month, day, size))); } @Operation( @@ -57,9 +77,25 @@ public ResponseEntity> getMoodCha @GetMapping("/percents") public ResponseEntity>> getMoodChartPercents( @AuthenticationPrincipal UserDetailsImpl userDetails) { - return ResponseEntity.ok(new ApiSuccessResponse<>(moodChartService.getActivityChart(userDetails))); + return ResponseEntity.ok( + new ApiSuccessResponse<>(moodChartService.getActivityChart(userDetails.getMemberId()))); } + @Operation( + summary = "의사/센터의 특정 환자의 기분 별 활동 차트 안의 기분 percent 조회" + ) + @ApiResponse( + responseCode = "200", description = "기분 별 활동 차트 안의 기분 percent 조회 성공 응답입니다.", useReturnTypeSchema = true + ) + @GetMapping("/percents/{memberId}") + public ResponseEntity>> getMoodChartPercents( + @AuthenticationPrincipal UserDetailsImpl userDetails, + @PathVariable("memberId") Long memberId) { + return ResponseEntity.ok( + new ApiSuccessResponse<>(moodChartService.getActivityChart(memberId))); + } + + @Operation( summary = "특정 기분에 대한 활동 퍼센트 조회" ) @@ -71,7 +107,22 @@ public ResponseEntity>> getA @AuthenticationPrincipal UserDetailsImpl userDetails, @Parameter(description = "감정") @RequestParam("feelingType") FeelingType feelingType) { return ResponseEntity.ok( - new ApiSuccessResponse<>(moodChartService.getActivityPercentChart(userDetails, feelingType))); + new ApiSuccessResponse<>(moodChartService.getActivityPercentChart(userDetails.getMemberId(), feelingType))); + } + + @Operation( + summary = "의사/센터의 특정 환자의 특정 기분에 대한 활동 퍼센트 조회" + ) + @ApiResponse( + responseCode = "200", description = "특정 기분에 대한 활동 퍼센트 조회 성공 응답입니다.", useReturnTypeSchema = true + ) + @GetMapping("/percent/activity") + public ResponseEntity>> getActivityPercentChart( + @AuthenticationPrincipal UserDetailsImpl userDetails, + @Parameter(description = "감정") @RequestParam("feelingType") FeelingType feelingType, + @Parameter(description = "조회하고자 하는 환자 ID") @RequestParam("memberId") Long memberId) { + return ResponseEntity.ok( + new ApiSuccessResponse<>(moodChartService.getActivityPercentChart(memberId, feelingType))); } diff --git a/src/main/java/com/remind/api/mood/controller/MoodController.java b/src/main/java/com/remind/api/mood/controller/MoodController.java index 00fc0b1..f2787fe 100644 --- a/src/main/java/com/remind/api/mood/controller/MoodController.java +++ b/src/main/java/com/remind/api/mood/controller/MoodController.java @@ -64,6 +64,21 @@ public ResponseEntity> get( @AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("moodDate") LocalDate localDate) { return ResponseEntity.ok( - new ApiSuccessResponse<>(SUCCESS, moodService.get(userDetails, localDate))); + new ApiSuccessResponse<>(SUCCESS, moodService.get(userDetails.getMemberId(), localDate))); + } + + @Operation( + summary = "의사/센터가 환자의 특정 날짜의 오늘의 기분 정보 조회" + ) + @ApiResponse( + responseCode = "200", description = "오늘의 기분 조회 성공 응답입니다.", useReturnTypeSchema = true + ) + @GetMapping("/{memberId}/{moodDate}") + public ResponseEntity> get( + @AuthenticationPrincipal UserDetailsImpl userDetails, + @PathVariable("memberId") Long memberId, + @PathVariable("moodDate") LocalDate localDate) { + return ResponseEntity.ok( + new ApiSuccessResponse<>(SUCCESS, moodService.get(memberId, localDate))); } } diff --git a/src/main/java/com/remind/api/mood/service/MoodChartService.java b/src/main/java/com/remind/api/mood/service/MoodChartService.java index 7a6458a..0e12d51 100644 --- a/src/main/java/com/remind/api/mood/service/MoodChartService.java +++ b/src/main/java/com/remind/api/mood/service/MoodChartService.java @@ -27,13 +27,13 @@ public class MoodChartService { private final MoodConsecutiveRepository moodConsecutiveRepository; @Transactional(readOnly = true) - public MoodChartPagingResponseDto getMoodChart(UserDetailsImpl userDetails, Integer year, Integer month, + public MoodChartPagingResponseDto getMoodChart(Long memberId, Integer year, Integer month, Integer day, Integer size) { List response = new ArrayList<>(); boolean hasNext = false; // 요청한 정보에 대해 커서 기반 pagination ( 월의 1일부터 조회하기 위해서는 day = 0 값을 받아야 한다. ) - Slice moodChartDtos = moodChartPagingRepository.getMoodChartPaging2(userDetails.getMemberId(), + Slice moodChartDtos = moodChartPagingRepository.getMoodChartPaging2(memberId, LocalDate.of(year, month, day + 1), Pageable.ofSize(size)); // 다음 페이지 존재 여부 @@ -47,14 +47,14 @@ public MoodChartPagingResponseDto getMoodChart(UserDetailsImpl userDetails, Inte } @Transactional(readOnly = true) - public List getActivityChart(UserDetailsImpl userDetails) { - return moodChartCacheService.getActivityFeelingTypePercent(userDetails.getMemberId()); + public List getActivityChart(Long memberId) { + return moodChartCacheService.getActivityFeelingTypePercent(memberId); } @Transactional(readOnly = true) - public List getActivityPercentChart(UserDetailsImpl userDetails, + public List getActivityPercentChart(Long memberId, FeelingType feelingType) { - return moodChartCacheService.getActivityPercentChart(userDetails.getMemberId(), feelingType); + return moodChartCacheService.getActivityPercentChart(memberId, feelingType); } diff --git a/src/main/java/com/remind/api/mood/service/MoodService.java b/src/main/java/com/remind/api/mood/service/MoodService.java index b5f4291..00faab0 100644 --- a/src/main/java/com/remind/api/mood/service/MoodService.java +++ b/src/main/java/com/remind/api/mood/service/MoodService.java @@ -90,9 +90,9 @@ public Long create(UserDetailsImpl userDetails, MoodSaveRequestDto dto) { * 특정 날짜의 오늘의 기분 정보 조회 */ @Transactional(readOnly = true) - public MoodResponseDto get(UserDetailsImpl userDetails, LocalDate localDate) { + public MoodResponseDto get(Long memberId, LocalDate localDate) { - Mood mood = moodRepository.findMoodByPatientAndMoodDate(userDetails.getMemberId(), localDate) + Mood mood = moodRepository.findMoodByPatientAndMoodDate(memberId, localDate) .orElseThrow(() -> new MoodException(MOOD_NOT_FOUND)); List modelActivities = dateMoodActivityRepository.getModelActivities(mood.getId()); diff --git a/src/main/java/com/remind/core/security/config/SecuirityConfig.java b/src/main/java/com/remind/core/security/config/SecuirityConfig.java index 24713aa..7ff3180 100644 --- a/src/main/java/com/remind/core/security/config/SecuirityConfig.java +++ b/src/main/java/com/remind/core/security/config/SecuirityConfig.java @@ -102,8 +102,10 @@ private RequestMatcher[] authorizeRequestMathcers() { antMatcher(POST, "/mood"), antMatcher(GET, "/mood"), antMatcher(GET, "/mood/{moodDate}"), + antMatcher(GET, "/mood/{memberId}/{moodDate}"), antMatcher(GET, "/mood/chart"), antMatcher(GET, "/mood/chart/percents"), + antMatcher(GET, "/mood/chart/percents/{memberId}"), antMatcher(GET, "/mood/chart/percent/activity"), antMatcher(POST, "/prescription/relation/request"), antMatcher(POST, "/prescription/relation/accept"),