From 26adcb767e61fc3596336e16738c4e3530093063 Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 10 Jul 2024 02:03:22 +0900 Subject: [PATCH] =?UTF-8?q?RAC-410=20fix=20:=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthController.java | 50 ++++++++------- .../image/presentation/ImageController.java | 18 +++--- .../presentation/MentoringController.java | 60 +++++++++--------- .../salary/presentation/SalaryController.java | 14 +++-- .../senior/presentation/SeniorController.java | 62 ++++++++++--------- .../user/presentation/UserController.java | 22 ++++--- .../exception/GlobalExceptionHandler.java | 18 ++++-- 7 files changed, 133 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java index fc68e522..71d5b0c8 100644 --- a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java @@ -17,6 +17,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -24,6 +25,7 @@ import static com.postgraduate.domain.auth.presentation.constant.AuthResponseMessage.*; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_CREATE; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.CREATE_SENIOR; +import static com.postgraduate.global.dto.ResponseDto.create; @RestController @RequiredArgsConstructor @@ -36,93 +38,93 @@ public class AuthController { @PostMapping("/login/{provider}") @Operation(summary = "소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).") - public ResponseDto authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { + public ResponseEntity> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getUser(request); if (authUser.user() == null) - return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser); + return ResponseEntity.ok(create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser)); JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user()); - return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/dev/login/{provider}") @Operation(summary = "개발용 소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).") - public ResponseDto authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { + public ResponseEntity> authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getDevUser(request); if (authUser.user() == null) - return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser); + return ResponseEntity.ok(create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser)); JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user()); - return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/logout") @Operation(summary = "로그아웃", description = "토큰 같이 보내주세요") - public ResponseDto logout(@AuthenticationPrincipal User user) { + public ResponseEntity> logout(@AuthenticationPrincipal User user) { jwtUseCase.logout(user); - return ResponseDto.create(AUTH_DELETE.getCode(), LOGOUT_USER.getMessage()); + return ResponseEntity.ok(create(AUTH_DELETE.getCode(), LOGOUT_USER.getMessage())); } @PostMapping("/signout/{provider}/{userId}") @Operation(summary = "회원 탈퇴 | 관리자 토큰 필요", description = "회원 탈퇴 진행") - public ResponseDto signOut(@PathVariable Provider provider, @PathVariable Long userId) { + public ResponseEntity> signOut(@PathVariable Provider provider, @PathVariable Long userId) { SignOutUseCase signOutUseCase = selectOauth.selectSignOut(provider); signOutUseCase.signOut(userId); - return ResponseDto.create(AUTH_DELETE.getCode(), SIGNOUT_USER.getMessage()); + return ResponseEntity.ok(create(AUTH_DELETE.getCode(), SIGNOUT_USER.getMessage())); } @PostMapping("/user/signup") @Operation(summary = "대학생 회원가입", description = "로그인 API에서 반환한 socialId, 닉네임, 번호, 마케팅 수신여부, 희망 학과, 희망 분야, 매칭 희망 여부") - public ResponseDto signUpUser(@RequestBody @Valid SignUpRequest request) { + public ResponseEntity> signUpUser(@RequestBody @Valid SignUpRequest request) { User user = signUpUseCase.userSignUp(request); JwtTokenResponse jwtToken = jwtUseCase.signIn(user); - return ResponseDto.create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/user/token") @Operation(summary = "후배로 변경 | 토큰 필요", description = "후배로 변경 가능한 경우 후배 토큰 발급") - public ResponseDto changeUserToken(@AuthenticationPrincipal User user) { + public ResponseEntity> changeUserToken(@AuthenticationPrincipal User user) { JwtTokenResponse jwtToken = jwtUseCase.changeUser(user); - return ResponseDto.create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/user/change") @Operation(summary = "후배로 추가 가입 | 토큰 필요", description = "대학원생 대학생으로 변경 추가 가입") - public ResponseDto changeUser(@AuthenticationPrincipal User user, + public ResponseEntity> changeUser(@AuthenticationPrincipal User user, @RequestBody @Valid UserChangeRequest changeRequest) { signUpUseCase.changeUser(user, changeRequest); JwtTokenResponse jwtToken = jwtUseCase.changeUser(user); - return ResponseDto.create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/senior/signup") @Operation(summary = "대학원생 가입 - 필수 과정만", description = "대학원생 회원가입 - 필수 과정만") - public ResponseDto singUpSenior(@RequestBody @Valid SeniorSignUpRequest request) { + public ResponseEntity> singUpSenior(@RequestBody @Valid SeniorSignUpRequest request) { User user = signUpUseCase.seniorSignUp(request); JwtTokenResponse jwtToken = jwtUseCase.signIn(user); - return ResponseDto.create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage(), jwtToken); + return ResponseEntity.ok(create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage(), jwtToken)); } @PostMapping("/senior/change") @Operation(summary = "선배로 추가 가입 | 토큰 필요", description = "대학생 대학원생으로 변경 추가 가입") - public ResponseDto changeSenior(@AuthenticationPrincipal User user, + public ResponseEntity> changeSenior(@AuthenticationPrincipal User user, @RequestBody @Valid SeniorChangeRequest changeRequest) { User changeUser = signUpUseCase.changeSenior(user, changeRequest); JwtTokenResponse jwtToken = jwtUseCase.changeSenior(changeUser); - return ResponseDto.create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage(), jwtToken); + return ResponseEntity.ok(create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage(), jwtToken)); } @PostMapping("/senior/token") @Operation(summary = "선배로 변경 | 토큰 필요", description = "선배로 변경 가능한 경우 선배 토큰 발급") - public ResponseDto changeSeniorToken(@AuthenticationPrincipal User user) { + public ResponseEntity> changeSeniorToken(@AuthenticationPrincipal User user) { JwtTokenResponse jwtToken = jwtUseCase.changeSenior(user); - return ResponseDto.create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/refresh") @Operation(summary = "토큰 재발급 | 토큰 필요", description = "refreshToken 으로 토큰 재발급") - public ResponseDto refresh(@AuthenticationPrincipal User user, HttpServletRequest request) { + public ResponseEntity> refresh(@AuthenticationPrincipal User user, HttpServletRequest request) { JwtTokenResponse jwtToken = jwtUseCase.regenerateToken(user, request); - return ResponseDto.create(AUTH_UPDATE.getCode(), SUCCESS_REGENERATE_TOKEN.getMessage(), jwtToken); + return ResponseEntity.ok(create(AUTH_UPDATE.getCode(), SUCCESS_REGENERATE_TOKEN.getMessage(), jwtToken)); } } diff --git a/src/main/java/com/postgraduate/domain/image/presentation/ImageController.java b/src/main/java/com/postgraduate/domain/image/presentation/ImageController.java index 71e85b1e..fa3e5a64 100644 --- a/src/main/java/com/postgraduate/domain/image/presentation/ImageController.java +++ b/src/main/java/com/postgraduate/domain/image/presentation/ImageController.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -17,6 +18,7 @@ import static com.postgraduate.domain.image.presentation.constant.ImageResponseCode.IMAGE_CREATE; import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.ISSUE_URL; import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.UPLOAD_URL; +import static com.postgraduate.global.dto.ResponseDto.create; @RestController @RequiredArgsConstructor @@ -28,29 +30,29 @@ public class ImageController { @PostMapping("/url/profile") @Operation(description = "USER Profile 등록 URL API - 이미지 풀네임으로 주세요 xxx.확장자, 이미지 이름을 유니크하게 만들어주세요 UUID+파일명 등등") - public ResponseDto getProfilePreSignedUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) { + public ResponseEntity> getProfilePreSignedUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) { PreSignedUrlResponse profileUrl = preSignedUseCase.getProfileUrl(preSignedUrlRequest); - return ResponseDto.create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), profileUrl); + return ResponseEntity.ok(create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), profileUrl)); } @PostMapping("/url/certification") @Operation(description = "Senior 학생증 인증 등록 URL API - 이미지 풀네임으로 주세요 xxx.확장자, 이미지 이름을 유니크하게 만들어주세요 UUID+파일명 등등") - public ResponseDto getCertificationPreSignedUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) { + public ResponseEntity> getCertificationPreSignedUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) { PreSignedUrlResponse certificationUrl = preSignedUseCase.getCertificationUrl(preSignedUrlRequest); - return ResponseDto.create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), certificationUrl); + return ResponseEntity.ok(create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), certificationUrl)); } @PostMapping("/upload/profile") @Operation(summary = "USER Profile 업로드 후 업로드 URL return / 토큰 필요", description = "profileFile 사진 Multipart File로 보내주세요") - public ResponseDto getProfileUrl(@AuthenticationPrincipal User user, @RequestPart MultipartFile profileFile) { + public ResponseEntity> getProfileUrl(@AuthenticationPrincipal User user, @RequestPart MultipartFile profileFile) { ImageUrlResponse imageUrlResponse = imageUploadUseCase.uploadProfile(user, profileFile); - return ResponseDto.create(IMAGE_CREATE.getCode(), UPLOAD_URL.getMessage(), imageUrlResponse); + return ResponseEntity.ok(create(IMAGE_CREATE.getCode(), UPLOAD_URL.getMessage(), imageUrlResponse)); } @PostMapping("/upload/certification") @Operation(summary = "SENIOR Certification 업로드 후 업로드 URL return", description = "certificationFile 사진 Multipart File로 보내주세요") - public ResponseDto getCertificationUrl(@RequestPart MultipartFile certificationFile) { + public ResponseEntity> getCertificationUrl(@RequestPart MultipartFile certificationFile) { ImageUrlResponse imageUrlResponse = imageUploadUseCase.uploadCertification(certificationFile); - return ResponseDto.create(IMAGE_CREATE.getCode(), UPLOAD_URL.getMessage(), imageUrlResponse); + return ResponseEntity.ok(create(IMAGE_CREATE.getCode(), UPLOAD_URL.getMessage(), imageUrlResponse)); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index a5a9c625..6bb430a3 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -13,11 +13,13 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; +import static com.postgraduate.global.dto.ResponseDto.create; @RestController @RequiredArgsConstructor @@ -30,99 +32,99 @@ public class MentoringController { @GetMapping("/me/waiting") @Operation(summary = "[대학생] 신청한 멘토링 목록 조회", description = "대학생이 신청한 멘토링 목록을 조회합니다.") - public ResponseDto getWaitingMentorings(@AuthenticationPrincipal User user) { + public ResponseEntity> getWaitingMentorings(@AuthenticationPrincipal User user) { WaitingMentoringResponse mentoringResponse = userInfoUseCase.getWaiting(user); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse)); } @GetMapping("/me/expected") @Operation(summary = "[대학생] 예정된 멘토링 목록 조회", description = "대학생이 예정된 멘토링 목록을 조회합니다.") - public ResponseDto getExpectedMentorings(@AuthenticationPrincipal User user) { + public ResponseEntity> getExpectedMentorings(@AuthenticationPrincipal User user) { ExpectedMentoringResponse mentoringResponse = userInfoUseCase.getExpected(user); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse)); } @GetMapping("/me/done") @Operation(summary = "[대학생] 완료한 멘토링 목록 조회", description = "대학생이 완료한 멘토링 목록을 조회합니다.") - public ResponseDto getDoneMentorings(@AuthenticationPrincipal User user) { + public ResponseEntity> getDoneMentorings(@AuthenticationPrincipal User user) { DoneMentoringResponse mentoringResponse = userInfoUseCase.getDone(user); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse)); } @GetMapping("/me/{mentoringId}") - @Operation(summary = "[대학생] 신청한 멘토링 상세조회", description = "대학생이 신청한 멘토링을 상세조회합니다. <완료> 상태의 멘토링은 상세조회되지 않습니다.") - public ResponseDto getMentoringDetail(@AuthenticationPrincipal User user, + @Operation(summary = "[대학생] 신청한 멘토링 상세조회", description = "대학생이 신청한 멘토링을 상세조회합니다. <완료>> 상태의 멘토링은 상세조회되지 않습니다.") + public ResponseEntity> getMentoringDetail(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) { AppliedMentoringDetailResponse mentoringDetail = userInfoUseCase.getMentoringDetail(user, mentoringId); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail)); } @PostMapping("/applying") @Operation(summary = "[대학생] 멘토링 신청", description = "대학생이 멘토링을 신청합니다.") - public ResponseDto applyForMentoringWithPayment(@AuthenticationPrincipal User user, @RequestBody MentoringApplyRequest request) { + public ResponseEntity> applyForMentoringWithPayment(@AuthenticationPrincipal User user, @RequestBody MentoringApplyRequest request) { ApplyingResponse applyingResponse = manageUseCase.applyMentoring(user, request); - return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage(), applyingResponse); + return ResponseEntity.ok(create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage(), applyingResponse)); } @PatchMapping("/me/{mentoringId}/done") @Operation(summary = "[대학생] 멘토링 상태 업데이트(완료)", description = "대학생이 멘토링을 완료합니다.") - public ResponseDto updateMentoringDone(@AuthenticationPrincipal User user, + public ResponseEntity> updateMentoringDone(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) { manageUseCase.updateDone(user, mentoringId); - return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + return ResponseEntity.ok(create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage())); } @PatchMapping("/me/{mentoringId}/cancel") @Operation(summary = "[대학생] 멘토링 상태 업데이트(취소)", description = "대학생이 신청한 멘토링을 취소합니다.") - public ResponseDto updateMentoringCancel(@AuthenticationPrincipal User user, + public ResponseEntity> updateMentoringCancel(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) { manageUseCase.updateCancel(user, mentoringId); - return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + return ResponseEntity.ok(create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage())); } @GetMapping("/senior/me/waiting") @Operation(summary = "[대학원생] 신청받은 확정대기 멘토링 목록 조회", description = "대학원생이 신청받은 확정대기 상태의 멘토링 목록을 조회합니다.") - public ResponseDto getSeniorWaitingMentorings(@AuthenticationPrincipal User user) { + public ResponseEntity> getSeniorWaitingMentorings(@AuthenticationPrincipal User user) { WaitingSeniorMentoringResponse mentoringResponse = seniorInfoUseCase.getSeniorWaiting(user); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse)); } @GetMapping("/senior/me/expected") @Operation(summary = "[대학원생] 신청받은 예정된 멘토링 목록 조회", description = "대학원생이 신청받은 예정 상태의 멘토링 목록을 조회합니다.") - public ResponseDto getSeniorExpectedMentorings(@AuthenticationPrincipal User user) { + public ResponseEntity> getSeniorExpectedMentorings(@AuthenticationPrincipal User user) { ExpectedSeniorMentoringResponse mentoringResponse = seniorInfoUseCase.getSeniorExpected(user); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse)); } @GetMapping("/senior/me/done") @Operation(summary = "[대학원생] 신청받은 완료된 멘토링 목록 조회", description = "대학원생이 신청받은 완료 상태의 멘토링 목록을 조회합니다.") - public ResponseDto getSeniorDoneMentorings(@AuthenticationPrincipal User user) { + public ResponseEntity> getSeniorDoneMentorings(@AuthenticationPrincipal User user) { DoneSeniorMentoringResponse mentoringResponse = seniorInfoUseCase.getSeniorDone(user); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse)); } @GetMapping("/senior/me/{mentoringId}") - @Operation(summary = "[대학원생] 신청받은 멘토링 상세조회", description = "대학원생이 신청받은 멘토링을 상세조회합니다. <완료> 상태의 멘토링은 상세조회되지 않습니다.") - public ResponseDto getSeniorMentoringDetail(@AuthenticationPrincipal User user, - @PathVariable Long mentoringId) { + @Operation(summary = "[대학원생] 신청받은 멘토링 상세조회", description = "대학원생이 신청받은 멘토링을 상세조회합니다. <완료>> 상태의 멘토링은 상세조회되지 않습니다.") + public ResponseEntity> getSeniorMentoringDetail(@AuthenticationPrincipal User user, + @PathVariable Long mentoringId) { SeniorMentoringDetailResponse seniorMentoringDetail = seniorInfoUseCase.getSeniorMentoringDetail(user, mentoringId); - return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), seniorMentoringDetail); + return ResponseEntity.ok(create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), seniorMentoringDetail)); } @PatchMapping("/senior/me/{mentoringId}/expected") @Operation(summary = "[대학원생] 멘토링 상태 업데이트(예정된 멘토링)", description = "대학원생이 멘토링을 수락합니다.") - public ResponseDto updateMentoringExpected(@AuthenticationPrincipal User user, + public ResponseEntity> updateMentoringExpected(@AuthenticationPrincipal User user, @PathVariable Long mentoringId, @RequestBody @Valid MentoringDateRequest dateRequest) { Boolean accountPresent = manageUseCase.updateExpected(user, mentoringId, dateRequest); - return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage(), accountPresent); + return ResponseEntity.ok(create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage(), accountPresent)); } @PatchMapping("/senior/me/{mentoringId}/refuse") @Operation(summary = "[대학원생] 멘토링 상태 업데이트(거절)", description = "대학원생이 멘토링을 거절하고 거절사유를 변경합니다.") - public ResponseDto updateMentoringCancel(@AuthenticationPrincipal User user, + public ResponseEntity> updateMentoringCancel(@AuthenticationPrincipal User user, @PathVariable Long mentoringId, @RequestBody @Valid MentoringRefuseRequest request) { manageUseCase.updateRefuse(user, mentoringId, request); - return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + return ResponseEntity.ok(create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage())); } } diff --git a/src/main/java/com/postgraduate/domain/salary/presentation/SalaryController.java b/src/main/java/com/postgraduate/domain/salary/presentation/SalaryController.java index 5f2dc0b1..d70a69e7 100644 --- a/src/main/java/com/postgraduate/domain/salary/presentation/SalaryController.java +++ b/src/main/java/com/postgraduate/domain/salary/presentation/SalaryController.java @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -16,6 +17,7 @@ import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseCode.SALARY_FIND; import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseMessage.GET_SALARY_INFO; import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseMessage.GET_SALARY_LIST_INFO; +import static com.postgraduate.global.dto.ResponseDto.create; @RestController @RequiredArgsConstructor @@ -26,22 +28,22 @@ public class SalaryController { @GetMapping() @Operation(summary = "대학원생 정산 예정액, 다음 정산 예정일 조회", description = "마이페이지에서 공통으로 보이는 정산 예정 정보입니다.") - public ResponseDto getSalary(@AuthenticationPrincipal User user) { + public ResponseEntity> getSalary(@AuthenticationPrincipal User user) { SalaryInfoResponse salary = salaryInfoUseCase.getSalary(user); - return ResponseDto.create(SALARY_FIND.getCode(), GET_SALARY_INFO.getMessage(), salary); + return ResponseEntity.ok(create(SALARY_FIND.getCode(), GET_SALARY_INFO.getMessage(), salary)); } @GetMapping("/waiting") @Operation(summary = "대학원생 정산예정 목록 조회", description = "정산 예정 탭에서 보이는 목록입니다.") - public ResponseDto getWaitingSalary(@AuthenticationPrincipal User user) { + public ResponseEntity> getWaitingSalary(@AuthenticationPrincipal User user) { SalaryDetailsResponse salary = salaryInfoUseCase.getSalaryDetail(user, false); - return ResponseDto.create(SALARY_FIND.getCode(), GET_SALARY_LIST_INFO.getMessage(), salary); + return ResponseEntity.ok(create(SALARY_FIND.getCode(), GET_SALARY_LIST_INFO.getMessage(), salary)); } @GetMapping("/done") @Operation(summary = "대학원생 정산완료 목록 조회", description = "정산 완료 탭에서 보이는 목록입니다.") - public ResponseDto getDoneSalary(@AuthenticationPrincipal User user) { + public ResponseEntity> getDoneSalary(@AuthenticationPrincipal User user) { SalaryDetailsResponse salary = salaryInfoUseCase.getSalaryDetail(user, true); - return ResponseDto.create(SALARY_FIND.getCode(), GET_SALARY_LIST_INFO.getMessage(), salary); + return ResponseEntity.ok(create(SALARY_FIND.getCode(), GET_SALARY_LIST_INFO.getMessage(), salary)); } } diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java index 17479a0a..08a43f0b 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java @@ -12,11 +12,13 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.*; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.*; +import static com.postgraduate.global.dto.ResponseDto.create; @RestController @@ -30,116 +32,116 @@ public class SeniorController { @GetMapping("/all") @Operation(summary = "모든 SeniorID 조회") - public ResponseDto getAllSeniorId() { + public ResponseEntity> getAllSeniorId() { AllSeniorIdResponse seniorIds = seniorInfoUseCase.getAllSeniorId(); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_ID_LIST.getMessage(), seniorIds); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_ID_LIST.getMessage(), seniorIds)); } @PatchMapping("/certification") @Operation(summary = "대학원생 인증 | 토큰 필요", description = "이미지 업로드 이후 url 담아서 요청") - public ResponseDto updateCertification(@AuthenticationPrincipal User user, + public ResponseEntity> updateCertification(@AuthenticationPrincipal User user, @RequestBody @Valid SeniorCertificationRequest certificationRequest) { seniorManageUseCase.updateCertification(user, certificationRequest); - return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_CERTIFICATION.getMessage()); + return ResponseEntity.ok(create(SENIOR_UPDATE.getCode(), UPDATE_CERTIFICATION.getMessage())); } @PatchMapping("/profile") @Operation(summary = "대학원생 프로필 등록 | 토큰 필요") - public ResponseDto singUpSenior(@AuthenticationPrincipal User user, + public ResponseEntity> singUpSenior(@AuthenticationPrincipal User user, @RequestBody @Valid SeniorProfileRequest profileRequest) { SeniorProfileUpdateResponse updateResponse = seniorManageUseCase.signUpProfile(user, profileRequest); - return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_PROFILE.getMessage(), updateResponse); + return ResponseEntity.ok(create(SENIOR_UPDATE.getCode(), UPDATE_PROFILE.getMessage(), updateResponse)); } @PostMapping("/account") @Operation(summary = "대학원생 정산 계좌 생성 | 토큰 필요") - public ResponseDto updateAccount(@AuthenticationPrincipal User user, + public ResponseEntity> updateAccount(@AuthenticationPrincipal User user, @RequestBody @Valid SeniorAccountRequest accountRequest) { seniorManageUseCase.saveAccount(user, accountRequest); - return ResponseDto.create(SENIOR_CREATE.getCode(), CREATE_ACCOUNT.getMessage()); + return ResponseEntity.ok(create(SENIOR_CREATE.getCode(), CREATE_ACCOUNT.getMessage())); } @GetMapping("/me") @Operation(summary = "대학원생 마이페이지 기본 정보 조회 | 토큰 필요", description = "닉네임, 프로필 사진, 인증 여부") - public ResponseDto getSeniorInfo(@AuthenticationPrincipal User user) { + public ResponseEntity> getSeniorInfo(@AuthenticationPrincipal User user) { SeniorMyPageResponse seniorMyPageResponse = seniorMyPageUseCase.getSeniorMyPage(user); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorMyPageResponse); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorMyPageResponse)); } @GetMapping("/me/profile") @Operation(summary = "대학원생 마이페이지 프로필 수정시 기존 정보 조회 | 토큰 필요") - public ResponseDto getSeniorProfile(@AuthenticationPrincipal User user) { + public ResponseEntity> getSeniorProfile(@AuthenticationPrincipal User user) { SeniorMyPageProfileResponse myPageProfile = seniorMyPageUseCase.getSeniorMyPageProfile(user); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_MYPAGE_PROFILE.getMessage(), myPageProfile); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_MYPAGE_PROFILE.getMessage(), myPageProfile)); } @PatchMapping("/me/profile") @Operation(summary = "대학원생 마이페이지 프로필 수정 | 토큰 필요") - public ResponseDto updateSeniorProfile(@AuthenticationPrincipal User user, + public ResponseEntity> updateSeniorProfile(@AuthenticationPrincipal User user, @RequestBody @Valid SeniorMyPageProfileRequest myPageProfileRequest) { SeniorProfileUpdateResponse updateResponse = seniorManageUseCase.updateSeniorMyPageProfile(user, myPageProfileRequest); - return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_PROFILE.getMessage(), updateResponse); + return ResponseEntity.ok(create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_PROFILE.getMessage(), updateResponse)); } @GetMapping("/me/account") @Operation(summary = "대학원생 마이페이지 계정 설정시 기존 정보 조회 | 토큰 필요") - public ResponseDto getSeniorUserAccount(@AuthenticationPrincipal User user) { + public ResponseEntity> getSeniorUserAccount(@AuthenticationPrincipal User user) { SeniorMyPageUserAccountResponse seniorOriginInfo = seniorMyPageUseCase.getSeniorMyPageUserAccount(user); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_MYPAGE_ACCOUNT.getMessage(), seniorOriginInfo); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_MYPAGE_ACCOUNT.getMessage(), seniorOriginInfo)); } @PatchMapping("/me/account") @Operation(summary = "대학원생 마이페이지 계정 설정 | 토큰 필요") - public ResponseDto updateSeniorUserAccount(@AuthenticationPrincipal User user, + public ResponseEntity> updateSeniorUserAccount(@AuthenticationPrincipal User user, @RequestBody @Valid SeniorMyPageUserAccountRequest myPageUserAccountRequest) { seniorManageUseCase.updateSeniorMyPageUserAccount(user, myPageUserAccountRequest); - return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_ACCOUNT.getMessage()); + return ResponseEntity.ok(create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_ACCOUNT.getMessage())); } @GetMapping("/{seniorId}") @Operation(summary = "대학원생 상세 조회 | 토큰 필요") - public ResponseDto getSeniorDetails(@AuthenticationPrincipal User user, + public ResponseEntity> getSeniorDetails(@AuthenticationPrincipal User user, @PathVariable Long seniorId) { SeniorDetailResponse seniorDetail = seniorInfoUseCase.getSeniorDetail(user, seniorId); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorDetail); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorDetail)); } @GetMapping("/{seniorId}/profile") @Operation(summary = "대학원생 닉네임~연구실 등 기본 정보 확인 | 토큰 필요", description = "신청서 완료 후 결제시 노출 필요") - public ResponseDto getSeniorProfile(@AuthenticationPrincipal User user, @PathVariable Long seniorId) { + public ResponseEntity> getSeniorProfile(@AuthenticationPrincipal User user, @PathVariable Long seniorId) { SeniorProfileResponse seniorProfile = seniorInfoUseCase.getSeniorProfile(user, seniorId); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorProfile); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorProfile)); } @GetMapping("/{seniorId}/times") @Operation(summary = "대학원생 가능 시간 확인 | 토큰 필요", description = "신청서 작성에서 가능 시간 작성시 노출 필요") - public ResponseDto getSeniorTimes(@PathVariable Long seniorId) { + public ResponseEntity> getSeniorTimes(@PathVariable Long seniorId) { AvailableTimesResponse times = seniorInfoUseCase.getSeniorTimes(seniorId); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_TIME.getMessage(), times); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_TIME.getMessage(), times)); } @GetMapping("/search") @Operation(summary = "대학원생 검색어 검색", description = "find 필수, sort 선택 - 안보낼 경우 아예 파라미터 추가x (조회수 낮은순 low, 높은순 high), page선택 (안보내면 기본 1페이지)") - public ResponseDto getSearchSenior(@RequestParam String find, + public ResponseEntity> getSearchSenior(@RequestParam String find, @RequestParam(required = false) String sort, @RequestParam(required = false) Integer page) { AllSeniorSearchResponse searchSenior = seniorInfoUseCase.getSearchSenior(find, page, sort); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_LIST_INFO.getMessage(), searchSenior); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_LIST_INFO.getMessage(), searchSenior)); } @GetMapping("/field") @Operation(summary = "대학원생 필드 검색", description = "분야 (분야1,분야2 이런식으로, 다른분야 : others, 전체 : all), 대학원 필수 (대학원1,대학원2 이런식으로, 다른학교 : others, 전체 : all), 페이지 선택 ") - public ResponseDto getFieldSenior(@RequestParam String field, + public ResponseEntity> getFieldSenior(@RequestParam String field, @RequestParam String postgradu, @RequestParam(required = false) Integer page) { AllSeniorSearchResponse searchSenior = seniorInfoUseCase.getFieldSenior(field, postgradu, page); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_LIST_INFO.getMessage(), searchSenior); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_SENIOR_LIST_INFO.getMessage(), searchSenior)); } @GetMapping("/me/role") @Operation(summary = "후배 전환시 가능 여부 확인 | 토큰 필요", description = "true-가능, false-불가능") - public ResponseDto checkRole(@AuthenticationPrincipal User user) { + public ResponseEntity> checkRole(@AuthenticationPrincipal User user) { SeniorPossibleResponse possibleResponse = seniorMyPageUseCase.checkUser(user); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_USER_CHECK.getMessage(), possibleResponse); + return ResponseEntity.ok(create(SENIOR_FIND.getCode(), GET_USER_CHECK.getMessage(), possibleResponse)); } } diff --git a/src/main/java/com/postgraduate/domain/user/presentation/UserController.java b/src/main/java/com/postgraduate/domain/user/presentation/UserController.java index a721ef3d..6ab5b550 100644 --- a/src/main/java/com/postgraduate/domain/user/presentation/UserController.java +++ b/src/main/java/com/postgraduate/domain/user/presentation/UserController.java @@ -12,12 +12,14 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_FIND; import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_UPDATE; import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.*; +import static com.postgraduate.global.dto.ResponseDto.create; @RestController @RequiredArgsConstructor @@ -29,37 +31,37 @@ public class UserController { @GetMapping("/me") @Operation(summary = "사용자 마이페이지 정보 조회 | 토큰 필요", description = "닉네임, 프로필") - public ResponseDto getUserInfo(@AuthenticationPrincipal User user) { + public ResponseEntity> getUserInfo(@AuthenticationPrincipal User user) { UserMyPageResponse userInfo = myPageUseCase.getUserInfo(user); - return ResponseDto.create(USER_FIND.getCode(), GET_USER_INFO.getMessage(), userInfo); + return ResponseEntity.ok(create(USER_FIND.getCode(), GET_USER_INFO.getMessage(), userInfo)); } @GetMapping("/me/info") @Operation(summary = "대학생 마이페이지 정보 수정 화면 기존 정보 | 토큰 필요", description = "프로필사진, 닉네임, 번호") - public ResponseDto getOriginUserInfo(@AuthenticationPrincipal User user) { + public ResponseEntity> getOriginUserInfo(@AuthenticationPrincipal User user) { UserInfoResponse originInfo = myPageUseCase.getUserOriginInfo(user); - return ResponseDto.create(USER_FIND.getCode(), GET_USER_INFO.getMessage(), originInfo); + return ResponseEntity.ok(create(USER_FIND.getCode(), GET_USER_INFO.getMessage(), originInfo)); } @PatchMapping("/me/info") @Operation(summary = "대학생 마이페이지 정보 수정 | 토큰 필요", description = "프로필사진, 닉네임, 번호") - public ResponseDto updateInfo(@AuthenticationPrincipal User user, + public ResponseEntity> updateInfo(@AuthenticationPrincipal User user, @RequestBody @Valid UserInfoRequest userInfoRequest) { manageUseCase.updateInfo(user, userInfoRequest); - return ResponseDto.create(USER_UPDATE.getCode(), UPDATE_USER_INFO.getMessage()); + return ResponseEntity.ok(create(USER_UPDATE.getCode(), UPDATE_USER_INFO.getMessage())); } @GetMapping("/me/role") @Operation(summary = "선배 전환시 가능 여부 확인 | 토큰 필요", description = "true-가능, false-불가능") - public ResponseDto checkRole(@AuthenticationPrincipal User user) { + public ResponseEntity> checkRole(@AuthenticationPrincipal User user) { UserPossibleResponse possibleResponse = myPageUseCase.checkSenior(user); - return ResponseDto.create(USER_FIND.getCode(), GET_SENIOR_CHECK.getMessage(), possibleResponse); + return ResponseEntity.ok(create(USER_FIND.getCode(), GET_SENIOR_CHECK.getMessage(), possibleResponse)); } @GetMapping("/nickname") @Operation(summary = "사용자 닉네임 중복체크", description = "true-사용가능, false-사용불가능") - public ResponseDto duplicatedNickName(@RequestParam String nickName) { + public ResponseEntity> duplicatedNickName(@RequestParam String nickName) { Boolean checkDup = manageUseCase.duplicatedNickName(nickName); - return ResponseDto.create(USER_FIND.getCode(), GET_NICKNAME_CHECK.getMessage(), checkDup); + return ResponseEntity.ok(create(USER_FIND.getCode(), GET_NICKNAME_CHECK.getMessage(), checkDup)); } } diff --git a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java index 825acc95..06b96a5a 100644 --- a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java @@ -7,11 +7,15 @@ import com.postgraduate.global.aop.logging.service.LogService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpStatus; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import static com.postgraduate.global.dto.ResponseDto.create; + @Slf4j @RestControllerAdvice @RequiredArgsConstructor @@ -23,14 +27,20 @@ public class GlobalExceptionHandler { private static final String LOG_FORMAT = "Code : {}, Message : {}"; @ExceptionHandler(ApplicationException.class) - public ResponseDto handleApplicationException(ApplicationException ex) { - return ResponseDto.create(ex.getCode(), ex.getMessage()); + public ResponseEntity> handleApplicationException(ApplicationException ex) { + return ResponseEntity.ok(create(ex.getCode(), ex.getMessage())); } @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseDto handleArgumentValidException(MethodArgumentNotValidException ex) { + public ResponseEntity> handleArgumentValidException(MethodArgumentNotValidException ex) { logService.save(new LogRequest(env, "@Valid", ex.getBindingResult().getAllErrors().get(0).getDefaultMessage())); log.error(LOG_FORMAT, "@Valid Error", "MethodArgumentNotValidException"); - return ResponseDto.create(ErrorCode.VALID_BLANK.getCode(), ex.getBindingResult().getAllErrors().get(0).getDefaultMessage()); + return ResponseEntity.ok(create(ErrorCode.VALID_BLANK.getCode(), ex.getBindingResult().getAllErrors().get(0).getDefaultMessage())); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity> handleInternalServerException(Exception ex) { + log.error(LOG_FORMAT, "500", ex.getStackTrace()); + return ResponseEntity.internalServerError().build(); } }