Skip to content

Commit

Permalink
Feat/81 의사/센터 앱에서 환자의 무드 및 차트 조회 기능 추가 (#82)
Browse files Browse the repository at this point in the history
* feat(#81): 의사/센터 앱에서 환자 무드 및 차트 조회 기능 추가

* refactor(#81): 메소드 파라미터 리팩토링
  • Loading branch information
lsm-del authored May 23, 2024
1 parent 80281ea commit 0d40a83
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +46,26 @@ public ResponseEntity<ApiSuccessResponse<MoodChartPagingResponseDto>> 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<ApiSuccessResponse<MoodChartPagingResponseDto>> 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(
Expand All @@ -57,9 +77,25 @@ public ResponseEntity<ApiSuccessResponse<MoodChartPagingResponseDto>> getMoodCha
@GetMapping("/percents")
public ResponseEntity<ApiSuccessResponse<List<MoodPercentResponseDto>>> 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<ApiSuccessResponse<List<MoodPercentResponseDto>>> getMoodChartPercents(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable("memberId") Long memberId) {
return ResponseEntity.ok(
new ApiSuccessResponse<>(moodChartService.getActivityChart(memberId)));
}


@Operation(
summary = "특정 기분에 대한 활동 퍼센트 조회"
)
Expand All @@ -71,7 +107,22 @@ public ResponseEntity<ApiSuccessResponse<List<ActivityPercentResponseDto>>> 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<ApiSuccessResponse<List<ActivityPercentResponseDto>>> 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)));
}


Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/remind/api/mood/controller/MoodController.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public ResponseEntity<ApiSuccessResponse<MoodResponseDto>> 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<ApiSuccessResponse<MoodResponseDto>> get(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable("memberId") Long memberId,
@PathVariable("moodDate") LocalDate localDate) {
return ResponseEntity.ok(
new ApiSuccessResponse<>(SUCCESS, moodService.get(memberId, localDate)));
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/remind/api/mood/service/MoodChartService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MoodChartResponseDto> response = new ArrayList<>();
boolean hasNext = false;
// 요청한 정보에 대해 커서 기반 pagination ( 월의 1일부터 조회하기 위해서는 day = 0 값을 받아야 한다. )
Slice<MoodChartDto> moodChartDtos = moodChartPagingRepository.getMoodChartPaging2(userDetails.getMemberId(),
Slice<MoodChartDto> moodChartDtos = moodChartPagingRepository.getMoodChartPaging2(memberId,
LocalDate.of(year, month, day + 1), Pageable.ofSize(size));

// 다음 페이지 존재 여부
Expand All @@ -47,14 +47,14 @@ public MoodChartPagingResponseDto getMoodChart(UserDetailsImpl userDetails, Inte
}

@Transactional(readOnly = true)
public List<MoodPercentResponseDto> getActivityChart(UserDetailsImpl userDetails) {
return moodChartCacheService.getActivityFeelingTypePercent(userDetails.getMemberId());
public List<MoodPercentResponseDto> getActivityChart(Long memberId) {
return moodChartCacheService.getActivityFeelingTypePercent(memberId);
}

@Transactional(readOnly = true)
public List<ActivityPercentResponseDto> getActivityPercentChart(UserDetailsImpl userDetails,
public List<ActivityPercentResponseDto> getActivityPercentChart(Long memberId,
FeelingType feelingType) {
return moodChartCacheService.getActivityPercentChart(userDetails.getMemberId(), feelingType);
return moodChartCacheService.getActivityPercentChart(memberId, feelingType);

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/remind/api/mood/service/MoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelActivityResponseDto> modelActivities = dateMoodActivityRepository.getModelActivities(mood.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 0d40a83

Please sign in to comment.