-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT] 자가진단표 api 구현 #37
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 all commits
22f78fb
a9df269
f304e4c
1514b96
4fc707e
83cedcd
da1e282
9ae2386
366b76c
d52b4cb
1e77e1a
205f8ab
7d1a5c6
92e9546
3a8b337
8ea9137
7b0763b
19142e7
5406415
2c087be
f6969f9
cb44a53
e5cfa6c
7346d74
67b38e9
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,20 @@ | ||
| package com.onebridge.ouch.apiPayload.code.error; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum DiagnosisErrorCode implements ErrorCode { | ||
|
|
||
| SYMPTOM_NOT_FOUND(HttpStatus.NOT_FOUND, "DIAGNOSIS401", "입력한 증상이 존재하지 않습니다."), | ||
| DIAGNOSIS_NOT_FOUND(HttpStatus.NOT_FOUND, "DIAGNOSIS402", "자가진단표가 존재하지 않습니다."), | ||
| SYMPTOM_ALREADY_ADDED(HttpStatus.BAD_REQUEST, "DIAGNOSIS403", "해당 증상이 이미 존재합니다."), | ||
| ; | ||
|
|
||
| private final HttpStatus httpStatus; | ||
| private final String code; | ||
| private final String message; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| package com.onebridge.ouch.controller.selfDiagnosis; | ||
|
|
||
| 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.selfDiagnosis.request.AddSymptomsToDiagnosisRequest; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.request.DiagnosisCreateRequest; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.request.DiagnosisUpdateRequest; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.GetDiagnosisByUserIdResponse; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.GetDiagnosisResponse; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.GetSymptomsOfDiagnosisResponse; | ||
| import com.onebridge.ouch.security.authorization.UserId; | ||
| import com.onebridge.ouch.service.selfDiagnosis.SelfDiagnosisService; | ||
|
|
||
| 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("/self-diagnosis") | ||
| @RequiredArgsConstructor | ||
| public class SelfDiagnosisController { | ||
|
|
||
| private final SelfDiagnosisService selfDiagnosisService; | ||
|
|
||
| //자가진단표 생성 | ||
| @Operation(summary = "자가진단표 생성 API", description = "자가진단표 생성 API 입니다.") | ||
| @PostMapping | ||
| public ResponseEntity<ApiResponse<Void>> createDiagnosis( //request dto 에 userid 지우기 | ||
| @RequestBody @Valid DiagnosisCreateRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| selfDiagnosisService.createDiagnosis(request, 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. Post하는 데 응답이 필요 없어서 DiagnosisCreateResponseDetailed 파일 지워주시고, ResponseEntity.ok(ApiResponse.successWithNoData()); 리턴하시면 될 것 같습니다.
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. 반영했습니다:) |
||
|
|
||
| //(자가진단표)id로 자가진단표 조회 | ||
| @Operation(summary = "자가진단표 조회 API", description = "자가진단표 조회 API 입니다.") | ||
| @GetMapping("/{diagnosisId}") | ||
|
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. 유저 정보를 파싱하는 식으로 하시지 않으셨는데, 특정 유저가 자기의 특정 자가진단을 보는 것을 의도하셨으면 밑처럼 @AuthenticationPrincipal 통해 유저 정보를 받아와야 합니다
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. 확인했습니다 |
||
| public ResponseEntity<ApiResponse<GetDiagnosisResponse>> getDiagnosisById( | ||
| @PathVariable Long diagnosisId, | ||
| @UserId Long userId | ||
| ) { | ||
| GetDiagnosisResponse response = selfDiagnosisService.getDiagnosis(diagnosisId, userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
|
||
| //사용자 모든 자가진단표 조회 | ||
| @Operation(summary = "특정 사용자의 모든 자가진단표 조회 API", description = "특정 사용자의 모든 자가진단표 조회 API 입니다.") | ||
| @GetMapping | ||
| public ResponseEntity<ApiResponse<List<GetDiagnosisByUserIdResponse>>> getAllDiagnosisByUserId( | ||
| @UserId Long userId | ||
| ) { | ||
| List<GetDiagnosisByUserIdResponse> list = selfDiagnosisService.getAllDiagnosisByUserId(userId); | ||
| return ResponseEntity.ok(ApiResponse.success(list)); | ||
| } | ||
|
|
||
| //자가진단표 삭제 | ||
| @Operation(summary = "자가진단표 삭제 API", description = "자가진단표 삭제 API 입니다.") | ||
| @DeleteMapping("/{diagnosisId}") | ||
| public ResponseEntity<ApiResponse<Void>> deleteDiagnosis(@PathVariable Long diagnosisId, | ||
| @UserId Long userId | ||
| ) { | ||
| selfDiagnosisService.deleteDiagnosis(diagnosisId, 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. 자기 자가진단만 삭제할 수 있도록 유저 정보를 파싱해서 받아야 합니다.
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. 확인했습니다 |
||
|
|
||
| //특정 자가진단표의 증상 목록 조회 | ||
| @Operation(summary = "특정 자가진단표의 증상 목록 조회 API", description = "특정 자가진단표의 증상 목록 조회 API 입니다.") | ||
| @GetMapping("/{diagnosisId}/symptoms") | ||
| public ResponseEntity<ApiResponse<GetSymptomsOfDiagnosisResponse>> getSymptomsOfDiagnosis( | ||
| @PathVariable Long diagnosisId, | ||
| @UserId Long userId | ||
| ) { | ||
| GetSymptomsOfDiagnosisResponse response = selfDiagnosisService.getSymptomsOfDiagnosis(diagnosisId, userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
|
||
| //자가진단표 수정 | ||
| @Operation(summary = "자가진단표 수정 API", description = "자가진단표 수정 API 입니다.") | ||
| @PutMapping("/{diagnosisId}") | ||
| public ResponseEntity<ApiResponse<Void>> updateDiagnosis(@PathVariable Long diagnosisId, | ||
| @RequestBody @Valid DiagnosisUpdateRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| selfDiagnosisService.updateDiagnosis(diagnosisId, userId, request); | ||
| 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. 여기도 응답 없에주세요.
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. 반영했습니다:) |
||
|
|
||
| //자가진단표에 증상 추가 | ||
| @Operation(summary = "특정 자가진단표에 증상 추가 API", description = "특정 자가진단표에 증상 추가 API 입니다.") | ||
| @PostMapping("/{diagnosisId}/symptoms") | ||
| public ResponseEntity<ApiResponse<Void>> addSymptomsToSelfDiagnosis(@PathVariable Long diagnosisId, | ||
| @RequestBody @Valid AddSymptomsToDiagnosisRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| selfDiagnosisService.addSymptomsToSelfDiagnosis(diagnosisId, request, 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. 이것도 유저 정보를 받는 식으로 하셔야 합니다. 그래야 보안상으로 안전합니다.
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,33 @@ | ||
| package com.onebridge.ouch.controller.symptom; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| 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.symptom.response.GetSymptomResponse; | ||
| import com.onebridge.ouch.service.symptom.SymptomService; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Tag(name = "증상 API", description = "증상 API 입니다.") | ||
| @RestController | ||
| @RequestMapping("/symptoms") | ||
| @RequiredArgsConstructor | ||
| public class SymptomController { | ||
|
|
||
| private final SymptomService symptomService; | ||
|
|
||
| //증상 목록 조회 | ||
| @Operation(summary = "증상 목록 조회 API", description = "증상 목록 조회 API 입니다.") | ||
| @GetMapping | ||
| public ResponseEntity<ApiResponse<List<GetSymptomResponse>>> getSymptomsList() { | ||
| List<GetSymptomResponse> list = symptomService.getSymptomsList(); | ||
| return ResponseEntity.ok(ApiResponse.success(list)); | ||
| } | ||
| } |
|
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. dto <-> 엔티티 양방향 변환을 의도하신 걸로 보이는데, 전반적으로 메소드명을 2를 붙여서 구분하기 보단 좀 더 직관적으로 바꾸시면 좋을 것 같습니다.
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,84 @@ | ||
| package com.onebridge.ouch.converter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.onebridge.ouch.domain.SelfDiagnosis; | ||
| import com.onebridge.ouch.domain.Symptom; | ||
| import com.onebridge.ouch.domain.User; | ||
| import com.onebridge.ouch.domain.mapping.DiagnosisSymptom; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.request.DiagnosisCreateRequest; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.request.DiagnosisUpdateRequest; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.DiagnosisUpdateResponse; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.GetDiagnosisByUserIdResponse; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.GetDiagnosisResponse; | ||
| import com.onebridge.ouch.dto.selfDiagnosis.response.GetSymptomsOfDiagnosisResponse; | ||
|
|
||
| @Component | ||
| public class SelfDiagnosisConverter { | ||
|
|
||
| public DiagnosisUpdateResponse diagnosisToDiagnosisUpdateResponse(SelfDiagnosis updatedDiagnosis) { | ||
| List<String> symptoms = symptomListForResponseDto(updatedDiagnosis); | ||
| return new DiagnosisUpdateResponse(updatedDiagnosis.getId(), updatedDiagnosis.getVisitType(), symptoms, | ||
| updatedDiagnosis.getDuration(), updatedDiagnosis.getPainSeverity(), updatedDiagnosis.getAdditionalNote(), | ||
| updatedDiagnosis.getCreatedAt().toString()); | ||
| } | ||
|
|
||
| public GetDiagnosisResponse diagnosisToGetDiagnosisResponse(SelfDiagnosis diagnosis) { | ||
| List<String> symptoms = symptomListForResponseDto(diagnosis); | ||
| return new GetDiagnosisResponse(diagnosis.getUser().getId(), diagnosis.getVisitType(), symptoms, | ||
| diagnosis.getDuration(), | ||
| diagnosis.getPainSeverity(), diagnosis.getAdditionalNote(), diagnosis.getCreatedAt().toString()); | ||
| } | ||
|
|
||
| public GetDiagnosisByUserIdResponse diagnosisToGetDiagnosisByUserIdResponse(SelfDiagnosis diagnosis) { | ||
| List<String> symptoms = symptomListForResponseDto(diagnosis); | ||
| return new GetDiagnosisByUserIdResponse(diagnosis.getId(), diagnosis.getVisitType(), symptoms, | ||
| diagnosis.getDuration(), diagnosis.getPainSeverity(), diagnosis.getAdditionalNote(), | ||
| diagnosis.getCreatedAt().toString()); | ||
| } | ||
|
|
||
| public GetSymptomsOfDiagnosisResponse diagnosisToGetSymptomsOfDiagnosisResponse(SelfDiagnosis diagnosis) { | ||
| List<String> symptoms = symptomListForResponseDto(diagnosis); | ||
| return new GetSymptomsOfDiagnosisResponse(symptoms); | ||
| } | ||
|
|
||
| public SelfDiagnosis diagnosisCreateRequestToSelfDiagnosis(DiagnosisCreateRequest request, User user) { | ||
| return SelfDiagnosis.builder() | ||
| .user(user) | ||
| .visitType(request.getVisitType()) | ||
| .diagnosisSymptomList(new ArrayList<>()) | ||
| .duration(request.getDuration()) | ||
| .painSeverity(request.getPainSeverity()) | ||
| .additionalNote(request.getAdditionalNote()) | ||
| .build(); | ||
| } | ||
|
|
||
| public DiagnosisSymptom buildDiagnosisSymptom(SelfDiagnosis selfDiagnosis, Symptom foundSymptom) { | ||
| return DiagnosisSymptom.builder() | ||
| .selfDiagnosis(selfDiagnosis) | ||
| .symptom(foundSymptom) | ||
| .build(); | ||
| } | ||
|
|
||
| public SelfDiagnosis diagnosisUpdateRequestToSelfDiagnosis(SelfDiagnosis diagnosis, User user, | ||
| DiagnosisUpdateRequest request) { | ||
| return diagnosis.toBuilder() | ||
| .visitType(request.getVisitType()) | ||
| .diagnosisSymptomList(new ArrayList<>()) | ||
| .duration(request.getDuration()) | ||
| .painSeverity(request.getPainSeverity()) | ||
| .additionalNote(request.getAdditionalNote()) | ||
| .build(); | ||
| } | ||
|
|
||
| public List<String> symptomListForResponseDto(SelfDiagnosis selfDiagnosis) { | ||
| List<String> symptoms = new ArrayList<>(); | ||
| for (DiagnosisSymptom symptom : selfDiagnosis.getDiagnosisSymptomList()) { | ||
| symptoms.add(symptom.getSymptom().getName()); | ||
| } | ||
| return symptoms; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.onebridge.ouch.converter; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.onebridge.ouch.domain.Symptom; | ||
| import com.onebridge.ouch.dto.symptom.response.GetSymptomResponse; | ||
|
|
||
| @Component | ||
| public class SymptomConverter { | ||
|
|
||
| public GetSymptomResponse symptomToGetSymptomsResponse(Symptom symptom) { | ||
| return new GetSymptomResponse(symptom.getId(), symptom.getName()); | ||
| } | ||
|
|
||
| public List<GetSymptomResponse> symptomsToGetSymptomsResponse(List<Symptom> symptoms) { | ||
| return symptoms.stream().map(this::symptomToGetSymptomsResponse).toList(); | ||
| } | ||
| } |
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는 CommonErrorCode 파일에 이미 있으므로 거기서 가져와서 쓰면 좋을 것 같습니다. 유저 관련은 CommonErrorCode로 다른 코드 다 바꿔주세요.
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.
반영했습니다:)