Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
22f78fb
[FEAT] 자가진단표 api 구현
kdy2224 Apr 5, 2025
a9df269
[REFACT] 자가진단표 api 리팩토링
kdy2224 Apr 6, 2025
f304e4c
[CHORE] 오타 수정
kdy2224 Apr 6, 2025
1514b96
[REFACT] user api 리팩토링
kdy2224 Apr 7, 2025
4fc707e
[REFACT] 증상 목록 조회 api 수정
kdy2224 Apr 7, 2025
83cedcd
[REFACT] 자가진단표 api 컨버터 수정
kdy2224 Apr 7, 2025
da1e282
[CHORE] 사소한 코드 수정
kdy2224 Apr 7, 2025
9ae2386
[TEMP] 임시저장
kdy2224 Apr 19, 2025
366b76c
[REFACT] 자가진단표 api 피드백 반영
kdy2224 Apr 19, 2025
d52b4cb
[REFACT] @UserId 로 변경
kdy2224 Apr 19, 2025
1e77e1a
[CHORE] SelfDiagnosisController, SymptomController 에 스웨거 세부 설정 추가
kdy2224 Apr 22, 2025
205f8ab
[CHORE] 리뷰/피드백 반영
kdy2224 Apr 23, 2025
7d1a5c6
Merge remote-tracking branch 'ouch-cs/main' into feat/#36/self-diagnosis
kdy2224 Apr 23, 2025
92e9546
[CHORE] 불필요한 코드, 파일 삭제
kdy2224 Apr 23, 2025
3a8b337
[REFACT] selfDiagnosisService 의 self diagnosis 조회 쿼리 메서드 변경
kdy2224 Apr 23, 2025
8ea9137
[REFACT] 피드백/리뷰 반영
kdy2224 Apr 23, 2025
7b0763b
[CHORE] 피드백/리뷰 반영
kdy2224 Apr 23, 2025
19142e7
Merge remote-tracking branch 'ouch-cs/main' into feat/#36/self-diagnosis
kdy2224 Apr 24, 2025
5406415
Merge remote-tracking branch 'ouch-cs/main' into feat/#36/self-diagnosis
kdy2224 Apr 25, 2025
2c087be
[CHORE] SelfSymptom -> DiagnosisSymptom(이름변경)에 따른 수정사항 수정
kdy2224 Apr 25, 2025
f6969f9
[CHORE] SelfDiagnosisConverter 일부 메서드 이름 수정
kdy2224 Apr 26, 2025
cb44a53
[REFACT] 자가진단 수정하는 경우 tobuilder에서 user값을 받을 필요 없음, createAt 또한 엔티티 어노…
99hyuk Apr 27, 2025
e5cfa6c
[REFACT] 변수명 수정
99hyuk Apr 27, 2025
7346d74
[REFACT] SelfDiagnosis 엔티티 내 @SuperBuilder -> @Builder 로 수정 (상속 없음)
99hyuk Apr 27, 2025
67b38e9
[REFACT] BaseEntity에 빌더 패턴 필요 없음
99hyuk Apr 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "해당 증상이 이미 존재합니다."),
;
Copy link
Contributor

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로 다른 코드 다 바꿔주세요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다:)


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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post하는 데 응답이 필요 없어서 DiagnosisCreateResponseDetailed 파일 지워주시고, ResponseEntity.ok(ApiResponse.successWithNoData()); 리턴하시면 될 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다:)


//(자가진단표)id로 자가진단표 조회
@Operation(summary = "자가진단표 조회 API", description = "자가진단표 조회 API 입니다.")
@GetMapping("/{diagnosisId}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저 정보를 파싱하는 식으로 하시지 않으셨는데, 특정 유저가 자기의 특정 자가진단을 보는 것을 의도하셨으면 밑처럼 @AuthenticationPrincipal 통해 유저 정보를 받아와야 합니다

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자기 자가진단만 삭제할 수 있도록 유저 정보를 파싱해서 받아야 합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 응답 없에주세요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 유저 정보를 받는 식으로 하셔야 합니다. 그래야 보안상으로 안전합니다.
URI도 /{diagnosisId}/symptoms으로 바꾸시면 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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));
}
}
Original file line number Diff line number Diff line change
@@ -1,83 +1,39 @@
package com.onebridge.ouch.controller.user;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
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.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.dto.MessageResponse;
import com.onebridge.ouch.dto.MessageResponseDetailed;
import com.onebridge.ouch.dto.user.request.MypageUserInfoUpdateRequest;
import com.onebridge.ouch.dto.user.response.MypageUserInfoResponse;
import com.onebridge.ouch.apiPayload.ApiResponse;
import com.onebridge.ouch.dto.user.response.UserInfoResponse;
import com.onebridge.ouch.security.authorization.UserId;
import com.onebridge.ouch.service.user.UserService;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api")
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {

private final UserService userService;

public UserController(UserService userService) {
this.userService = userService;
}

//유저 조회(테스트용)
@GetMapping("/users/{userId}")
public UserInfoResponse getUserInfo(@PathVariable Long userId) {
return userService.getUserInfo(userId);
//유저 조회
@GetMapping
public ResponseEntity<ApiResponse<UserInfoResponse>> getUserInfo(
@UserId Long userId) {
UserInfoResponse response = userService.getUserInfo(userId);
return ResponseEntity.ok(ApiResponse.success(response));
}

//유저 탈퇴(비활성화)
@PatchMapping("/users/{userId}")
public ResponseEntity<?> deactivateUser(@PathVariable Long userId) {
@DeleteMapping
public ResponseEntity<ApiResponse<Void>> deactivateUser(
@UserId Long userId) {
userService.deactivateUser(userId);
MessageResponse body = new MessageResponse("Your account has been deactivated.");
HttpHeaders header = new HttpHeaders();
header.add(HttpHeaders.CONTENT_TYPE, "application/json");

return new ResponseEntity<>(body, header, HttpStatus.OK);
}

//유저 삭제(테스트용)
@DeleteMapping("/users/{userId}")
public ResponseEntity<?> deleteUser(@PathVariable Long userId) {
userService.deleteUser(userId);
MessageResponse body = new MessageResponse("Your account has been deleted.");
HttpHeaders header = new HttpHeaders();
header.add(HttpHeaders.CONTENT_TYPE, "application/json");

return new ResponseEntity<>(body, header, HttpStatus.OK);
}

//마이페이지(내 정보) 조회
@GetMapping("/mypage/users/{userId}")
public MypageUserInfoResponse myPageGetUserInfo(@PathVariable Long userId) {
return userService.myPageGetUserInfo(userId);
}

//내 정보 수정 (사용자로부터 모든 필드의 값을 받아 put 요청 처리)
@PutMapping("/mypage/users/{userId}")
public ResponseEntity<MessageResponseDetailed<String>> myPageUpdateUserInfo(@PathVariable Long userId,
@RequestBody @Valid MypageUserInfoUpdateRequest request) {
// System.out.println("userId = " + userId);
userService.myPageUpdateUserInfo(userId, request);
MessageResponseDetailed<String> body = new MessageResponseDetailed<>(
true,
"COMMON200",
"요청이 성공적으로 처리되었습니다.",
"유저 정보가 성공적으로 수정되었습니다."
);
return ResponseEntity.ok(body);
return ResponseEntity.ok(ApiResponse.successWithNoData());
}
}

Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dto <-> 엔티티 양방향 변환을 의도하신 걸로 보이는데, 전반적으로 메소드명을 2를 붙여서 구분하기 보단 좀 더 직관적으로 바꾸시면 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/onebridge/ouch/converter/SymptomConverter.java
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();
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/onebridge/ouch/converter/UserConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.stereotype.Component;

import com.onebridge.ouch.domain.User;
import com.onebridge.ouch.dto.user.response.MypageUserInfoResponse;
import com.onebridge.ouch.dto.user.response.UserInfoResponse;

@Component
Expand All @@ -14,8 +13,4 @@ public UserInfoResponse convertToUserInfoResponse(User user) {
user.getPhoneNumber(), user.getGender(), user.getBirthday(), user.getEmail(), user.getLanguage().getId(),
user.getNation().getId());
}

public MypageUserInfoResponse convertToMypageUserInfoResponse(User user) {
return new MypageUserInfoResponse(user.getNickname(), user.getEmail(), user.getLanguage().getId());
}
}
Loading