|
| 1 | +package org.runnect.server.health.controller; |
| 2 | + |
| 3 | +import javax.validation.Valid; |
| 4 | +import lombok.RequiredArgsConstructor; |
| 5 | +import org.runnect.server.common.constant.SuccessStatus; |
| 6 | +import org.runnect.server.common.dto.ApiResponseDto; |
| 7 | +import org.runnect.server.common.resolver.userId.UserId; |
| 8 | +import org.runnect.server.health.dto.request.HealthDataRequestDto; |
| 9 | +import org.runnect.server.health.dto.response.CreateHealthDataResponseDto; |
| 10 | +import org.runnect.server.health.dto.response.GetHealthDataResponseDto; |
| 11 | +import org.runnect.server.health.dto.response.GetHealthSummaryResponseDto; |
| 12 | +import org.runnect.server.health.service.HealthService; |
| 13 | +import org.springframework.http.HttpStatus; |
| 14 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 15 | +import org.springframework.web.bind.annotation.GetMapping; |
| 16 | +import org.springframework.web.bind.annotation.PathVariable; |
| 17 | +import org.springframework.web.bind.annotation.PostMapping; |
| 18 | +import org.springframework.web.bind.annotation.RequestBody; |
| 19 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 20 | +import org.springframework.web.bind.annotation.RequestParam; |
| 21 | +import org.springframework.web.bind.annotation.ResponseStatus; |
| 22 | +import org.springframework.web.bind.annotation.RestController; |
| 23 | + |
| 24 | +@RestController |
| 25 | +@RequiredArgsConstructor |
| 26 | +@RequestMapping("/api") |
| 27 | +public class HealthController { |
| 28 | + |
| 29 | + private final HealthService healthService; |
| 30 | + |
| 31 | + @PostMapping("record/{recordId}/health") |
| 32 | + @ResponseStatus(HttpStatus.CREATED) |
| 33 | + public ApiResponseDto<CreateHealthDataResponseDto> createHealthData( |
| 34 | + @UserId Long userId, |
| 35 | + @PathVariable(name = "recordId") Long recordId, |
| 36 | + @RequestBody @Valid final HealthDataRequestDto request) { |
| 37 | + return ApiResponseDto.success(SuccessStatus.CREATE_HEALTH_DATA_SUCCESS, |
| 38 | + healthService.createHealthData(userId, recordId, request)); |
| 39 | + } |
| 40 | + |
| 41 | + @GetMapping("record/{recordId}/health") |
| 42 | + @ResponseStatus(HttpStatus.OK) |
| 43 | + public ApiResponseDto<GetHealthDataResponseDto> getHealthData( |
| 44 | + @UserId Long userId, |
| 45 | + @PathVariable(name = "recordId") Long recordId) { |
| 46 | + return ApiResponseDto.success(SuccessStatus.GET_HEALTH_DATA_SUCCESS, |
| 47 | + healthService.getHealthData(userId, recordId)); |
| 48 | + } |
| 49 | + |
| 50 | + @GetMapping("health/summary") |
| 51 | + @ResponseStatus(HttpStatus.OK) |
| 52 | + public ApiResponseDto<GetHealthSummaryResponseDto> getHealthSummary( |
| 53 | + @UserId Long userId, |
| 54 | + @RequestParam(name = "startDate") String startDate, |
| 55 | + @RequestParam(name = "endDate") String endDate) { |
| 56 | + return ApiResponseDto.success(SuccessStatus.GET_HEALTH_SUMMARY_SUCCESS, |
| 57 | + healthService.getHealthSummary(userId, startDate, endDate)); |
| 58 | + } |
| 59 | + |
| 60 | + @DeleteMapping("record/{recordId}/health") |
| 61 | + @ResponseStatus(HttpStatus.OK) |
| 62 | + public ApiResponseDto deleteHealthData( |
| 63 | + @UserId Long userId, |
| 64 | + @PathVariable(name = "recordId") Long recordId) { |
| 65 | + healthService.deleteHealthData(userId, recordId); |
| 66 | + return ApiResponseDto.success(SuccessStatus.DELETE_HEALTH_DATA_SUCCESS); |
| 67 | + } |
| 68 | +} |
0 commit comments