-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c6fc9e
[FEAT] 건강상태 CRUD api 구현
kdy2224 4f53873
[REFACT] 건강상태 api 리팩토링
kdy2224 aa122fc
[REFACT] 건강상태 converter 수정
kdy2224 229ccc4
[REFACT] 건강상태 api 피드백 반영
kdy2224 d490375
[REFACT] @UserId 로 변경
kdy2224 4ba38d7
[CHORE] MedicalHistoryController 에 스웨거 세부 설정 추가
kdy2224 18aa3b9
[CHORE] 리뷰/피드백 반영
kdy2224 26ad687
[REFACT] MedicalHistoryService 의 midecal history 조회 쿼리 메서드 변경
kdy2224 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/com/onebridge/ouch/apiPayload/code/error/MedicalHistoryErrorCode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 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 { | ||
|
|
||
| MEDICAL_HISTORY_NOT_FOUND(HttpStatus.NOT_FOUND, "HEALTH-STATUS401", "건강상태가 존재하지 않습니다."); | ||
|
|
||
| private final HttpStatus httpStatus; | ||
| private final String code; | ||
| private final String message; | ||
| } |
88 changes: 88 additions & 0 deletions
88
src/main/java/com/onebridge/ouch/controller/medicalHistory/MedicalHistoryController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| 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.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<Void>> createMedicalHistory( | ||
| @RequestBody @Valid MedicalHistoryCreateRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| medicalHistoryService.createMedicalHistory(request, userId); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
|
|
||
| //특정 건강상태 조회 | ||
| @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<Void>> updateMedicalHistory( | ||
| @RequestBody @Valid MedicalHistoryUpdateRequest request, | ||
| @PathVariable Long healthStatusId, | ||
| @UserId Long userId | ||
| ) { | ||
| medicalHistoryService.updateMedicalHistory(request, healthStatusId, userId); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
|
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()); | ||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
src/main/java/com/onebridge/ouch/converter/MedicalHistoryConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| 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; | ||
|
|
||
| @Component | ||
| public class MedicalHistoryConverter { | ||
|
|
||
| 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 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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/onebridge/ouch/dto/medicalHistory/request/MedicalHistoryCreateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/onebridge/ouch/dto/medicalHistory/request/MedicalHistoryUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/onebridge/ouch/dto/medicalHistory/response/DateAndDisease.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/onebridge/ouch/dto/medicalHistory/response/GetMedicalHistoryResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/onebridge/ouch/repository/medicalHistory/MedicalHistoryRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.onebridge.ouch.repository.medicalHistory; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| 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); | ||
|
|
||
| Optional<MedicalHistory> findByIdAndUserId(Long medicalHistoryId, Long userId); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
api URI restful하게 바꿔주세요. /health-status 으로 시작하는 건 좋은 것 같습니다. 추후 도메인 수정해놓겠습니다.
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.
전반적으로 다른 pr에서 리뷰한 거랑 거의 비슷한 문제들이 있는 것 같아서 참고해서 수정해주세요.
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.
확인했습니다 :)