-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT] 건강상태 CRUD api 구현 #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9c6fc9e
4f53873
aa122fc
229ccc4
d490375
4ba38d7
18aa3b9
26ad687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.onebridge.ouch.apiPayload.code.error; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum MedicalHistoryErrorCode implements ErrorCode { | ||
|
|
||
| USER_NOT_FOUND(HttpStatus.NOT_FOUND, "HEALTH-STATUS400", "User not found."), | ||
| MEDICAL_HISTORY_NOT_FOUND(HttpStatus.NOT_FOUND, "HEALTH-STATUS401", "Health status not found."); | ||
|
|
||
| private final HttpStatus httpStatus; | ||
| private final String code; | ||
| private final String message; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. api URI restful하게 바꿔주세요. /health-status 으로 시작하는 건 좋은 것 같습니다. 추후 도메인 수정해놓겠습니다.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 전반적으로 다른 pr에서 리뷰한 거랑 거의 비슷한 문제들이 있는 것 같아서 참고해서 수정해주세요.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확인했습니다 :) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package com.onebridge.ouch.controller.medicalHistory; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.onebridge.ouch.apiPayload.ApiResponse; | ||
| import com.onebridge.ouch.dto.medicalHistory.request.MedicalHistoryCreateRequest; | ||
| import com.onebridge.ouch.dto.medicalHistory.request.MedicalHistoryUpdateRequest; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.DateAndDisease; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.GetMedicalHistoryResponse; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.MedicalHistoryCreateResponse; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.MedicalHistoryUpdateResponse; | ||
| import com.onebridge.ouch.security.authorization.UserId; | ||
| import com.onebridge.ouch.service.medicalHistory.MedicalHistoryService; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Tag(name = "건강 상태 API", description = "건강 상태 API") | ||
| @RestController | ||
| @RequestMapping("/health-status") | ||
| @RequiredArgsConstructor | ||
| public class MedicalHistoryController { | ||
|
|
||
| private final MedicalHistoryService medicalHistoryService; | ||
|
|
||
| //건강상태 생성 | ||
| @Operation(summary = "건강상태 생성 API", description = "건강상태 생성 API 입니다.") | ||
| @PostMapping | ||
| public ResponseEntity<ApiResponse<MedicalHistoryCreateResponse>> createMedicalHistory( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Post에서 응답은 따로 필요 없으니 Void로 받으시면 되시고 관련 dto도 없에주시면 감사하겠습니다.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영했습니다:) |
||
| @RequestBody @Valid MedicalHistoryCreateRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| MedicalHistoryCreateResponse response = medicalHistoryService.createMedicalHistory(request, userId); | ||
| return ResponseEntity.ok(ApiResponse.created(response)); | ||
| } | ||
|
|
||
| //특정 건강상태 조회 | ||
| @Operation(summary = "건강상태 조회 API", description = "건강상태 조회 API 입니다.") | ||
| @GetMapping("/{healthStatusId}") | ||
| public ResponseEntity<ApiResponse<GetMedicalHistoryResponse>> getMedicalHistory(@PathVariable Long healthStatusId, | ||
| @UserId Long userId | ||
| ) { | ||
| GetMedicalHistoryResponse response = medicalHistoryService.getMedicalHistory(healthStatusId, userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
|
||
| //특정 사용자의 모든 건강상태 조회 | ||
| @Operation(summary = "특정 사용자의 모든 건강상태 조회 API", description = "특정 사용자의 모든 건강상태 조회 API 입니다.") | ||
| @GetMapping | ||
| public ResponseEntity<ApiResponse<List<DateAndDisease>>> getUsersAllMedicalHistory( | ||
| @UserId Long userId | ||
| ) { | ||
| List<DateAndDisease> list = medicalHistoryService.getUsersAllMedicalHistory(userId); | ||
| return ResponseEntity.ok(ApiResponse.success(list)); | ||
| } | ||
|
|
||
| //특정 건강상태 수정 | ||
| @Operation(summary = "건강상태 수정 API", description = "건강상태 수정 API 입니다.") | ||
| @PutMapping("/{healthStatusId}") | ||
| public ResponseEntity<ApiResponse<MedicalHistoryUpdateResponse>> updateMedicalHistory( | ||
| @RequestBody @Valid MedicalHistoryUpdateRequest request, | ||
| @PathVariable Long healthStatusId, | ||
| @UserId Long userId | ||
| ) { | ||
| MedicalHistoryUpdateResponse response = medicalHistoryService.updateMedicalHistory(request, healthStatusId, | ||
| userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응답 삭제2 |
||
|
|
||
| //특정 건강상태 삭제 | ||
| @Operation(summary = "건강상태 삭제 API", description = "건강상태 삭제 API 입니다.") | ||
| @DeleteMapping("/{healthStatusId}") | ||
| public ResponseEntity<ApiResponse<Void>> deleteMedicalHistory(@PathVariable Long healthStatusId, | ||
| @UserId Long userId | ||
| ) { | ||
| medicalHistoryService.deleteMedicalHistory(healthStatusId, userId); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.onebridge.ouch.converter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.onebridge.ouch.domain.MedicalHistory; | ||
| import com.onebridge.ouch.domain.User; | ||
| import com.onebridge.ouch.dto.medicalHistory.request.MedicalHistoryCreateRequest; | ||
| import com.onebridge.ouch.dto.medicalHistory.request.MedicalHistoryUpdateRequest; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.DateAndDisease; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.GetMedicalHistoryResponse; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.MedicalHistoryCreateResponse; | ||
| import com.onebridge.ouch.dto.medicalHistory.response.MedicalHistoryUpdateResponse; | ||
|
|
||
| @Component | ||
| public class MedicalHistoryConverter { | ||
|
|
||
| public MedicalHistoryCreateResponse medicalHistoryToMedicalHistoryResponse(MedicalHistory medicalHistory, | ||
| Long userId) { | ||
| return new MedicalHistoryCreateResponse(medicalHistory.getId(), | ||
| medicalHistory.getDisease(), | ||
| medicalHistory.getAllergy(), | ||
| medicalHistory.getBloodPressure(), medicalHistory.getBloodSugar(), medicalHistory.getMedicineHistory()); | ||
| } | ||
|
|
||
| public List<DateAndDisease> medicalHistoryToGetUsersAllMedicalHistoryResponse( | ||
| List<MedicalHistory> medicalHistory) { | ||
|
|
||
| List<DateAndDisease> list = new ArrayList<>(); | ||
|
|
||
| for (MedicalHistory history : medicalHistory) { | ||
| list.add(new DateAndDisease(history.getId(), history.getUpdatedAt().toString(), history.getDisease())); | ||
| } | ||
|
|
||
| return list; | ||
| } | ||
|
|
||
| public GetMedicalHistoryResponse medicalHistoryToGetMedicalHistoryResponse(MedicalHistory medicalHistory) { | ||
| return new GetMedicalHistoryResponse(medicalHistory.getId(), medicalHistory.getDisease(), | ||
| medicalHistory.getAllergy(), medicalHistory.getBloodPressure(), medicalHistory.getBloodSugar(), | ||
| medicalHistory.getMedicineHistory()); | ||
| } | ||
|
|
||
| public MedicalHistoryUpdateResponse medicalHistoryToMedicalHistoryUpdateResponse(MedicalHistory medicalHistory) { | ||
| return new MedicalHistoryUpdateResponse(medicalHistory.getId(), medicalHistory.getDisease(), | ||
| medicalHistory.getAllergy(), medicalHistory.getBloodPressure(), medicalHistory.getBloodSugar(), | ||
| medicalHistory.getMedicineHistory()); | ||
| } | ||
|
|
||
| public MedicalHistory medicalHistoryCreateRequestToMedicalHistory(MedicalHistoryCreateRequest request, User user) { | ||
| return MedicalHistory.builder() | ||
| .user(user) | ||
| .disease(request.getDisease()) | ||
| .allergy(request.getAllergy()) | ||
| .bloodPressure(request.getBloodPressure()) | ||
| .bloodSugar(request.getBloodSugar()) | ||
| .medicineHistory(request.getMedicineHistory()) | ||
| .build(); | ||
| } | ||
|
|
||
| public MedicalHistory medicalHistoryUpdateRequestToMedicalHistory(MedicalHistory medicalHistory, | ||
| MedicalHistoryUpdateRequest request) { | ||
| return medicalHistory.toBuilder() | ||
| .disease(request.getDisease()) | ||
| .allergy(request.getAllergy()) | ||
| .bloodPressure(request.getBloodPressure()) | ||
| .bloodSugar(request.getBloodSugar()) | ||
| .medicineHistory(request.getMedicineHistory()) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.onebridge.ouch.dto.medicalHistory.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class MedicalHistoryCreateRequest { | ||
|
|
||
| @NotBlank(message = "Disease is required.") | ||
| private String disease; | ||
|
|
||
| @NotBlank(message = "Allergy is required.") | ||
| private String allergy; | ||
|
|
||
| @NotNull(message = "Blood pressure is required.") | ||
| private Long bloodPressure; | ||
|
|
||
| @NotNull(message = "Blood sugar level is required.") | ||
| private Long bloodSugar; | ||
|
|
||
| @NotBlank(message = "Medical History is required.") | ||
| private String medicineHistory; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.onebridge.ouch.dto.medicalHistory.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class MedicalHistoryUpdateRequest { | ||
|
|
||
| @NotBlank(message = "Disease is required.") | ||
| private String disease; | ||
|
|
||
| @NotBlank(message = "Allergy is required.") | ||
| private String allergy; | ||
|
|
||
| @NotNull(message = "Blood pressure is required.") | ||
| private Long bloodPressure; | ||
|
|
||
| @NotNull(message = "Blood sugar level is required.") | ||
| private Long bloodSugar; | ||
|
|
||
| @NotBlank(message = "Medical History is required.") | ||
| private String medicineHistory; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.onebridge.ouch.dto.medicalHistory.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class DateAndDisease { | ||
|
|
||
| private Long id; | ||
| private String date; | ||
| private String disease; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.onebridge.ouch.dto.medicalHistory.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| public class GetMedicalHistoryResponse { | ||
|
|
||
| private Long id; | ||
| private String disease; | ||
| private String allergy; | ||
| private Long bloodPressure; | ||
| private Long bloodSugar; | ||
| private String medicineHistory; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.onebridge.ouch.dto.medicalHistory.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class MedicalHistoryCreateResponse { | ||
| private Long id; | ||
| private String disease; | ||
| private String allergy; | ||
| private Long bloodPressure; | ||
| private Long bloodSugar; | ||
| private String medicineHistory; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.onebridge.ouch.dto.medicalHistory.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class MedicalHistoryUpdateResponse { | ||
| private Long id; | ||
| private String disease; | ||
| private String allergy; | ||
| private Long bloodPressure; | ||
| private Long bloodSugar; | ||
| private String medicineHistory; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.onebridge.ouch.repository.medicalHistory; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.onebridge.ouch.domain.MedicalHistory; | ||
|
|
||
| @Repository | ||
| public interface MedicalHistoryRepository extends JpaRepository<MedicalHistory, Long> { | ||
| List<MedicalHistory> findAllByUserId(Long userId); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USER_NOT_FOUND는 기존 에러 사용해주세요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반영했습니다:)