From 0666a7071ec1357457181dd4d7dc7ec510c1678f Mon Sep 17 00:00:00 2001 From: joonghyun Date: Thu, 21 Mar 2024 22:25:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?hotfix:=20=EC=98=88=EC=99=B8=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=ED=98=95=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../hatcher/haemo/common/BaseException.java | 18 ++++++------ .../common/enums/BaseResponseStatus.java | 1 + .../haemo/common/enums/RecruitType.java | 2 +- .../presentation/RecruitmentController.java | 24 +++++++++------- .../haemo/user/application/AuthService.java | 2 +- .../user/presentation/UserController.java | 28 ++++--------------- 7 files changed, 34 insertions(+), 42 deletions(-) diff --git a/build.gradle b/build.gradle index 1e2c14c..d42fe04 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'io.jsonwebtoken:jjwt:0.9.1' + implementation 'javax.xml.bind:jaxb-api:2.3.1' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/com/hatcher/haemo/common/BaseException.java b/src/main/java/com/hatcher/haemo/common/BaseException.java index b1bf4ba..4555284 100644 --- a/src/main/java/com/hatcher/haemo/common/BaseException.java +++ b/src/main/java/com/hatcher/haemo/common/BaseException.java @@ -1,13 +1,15 @@ package com.hatcher.haemo.common; import com.hatcher.haemo.common.enums.BaseResponseStatus; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; +import org.springframework.web.server.ResponseStatusException; -@Getter -@Setter -@AllArgsConstructor -public class BaseException extends Exception { - private BaseResponseStatus status; +public class BaseException extends ResponseStatusException { + private final boolean success; + private final Object data; + + public BaseException(BaseResponseStatus status) { + super(status.getHttpStatus(), status.getMessage()); + this.success = false; + this.data = null; + } } diff --git a/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java b/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java index 975aa3b..377e4ed 100644 --- a/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java +++ b/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java @@ -66,5 +66,6 @@ public enum BaseResponseStatus { public int getCode() { return httpStatus.value(); } + public HttpStatus getHttpStatus() {return httpStatus; } } diff --git a/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java b/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java index d716fc4..544b19d 100644 --- a/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java +++ b/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java @@ -20,7 +20,7 @@ public enum RecruitType { public static RecruitType getEnumByName(String name) throws BaseException { return Arrays.stream(RecruitType.values()) - .filter(contents -> contents.name().equalsIgnoreCase(name)) + .filter(recruitType -> recruitType.name().equalsIgnoreCase(name)) .findFirst() .orElseThrow(() -> new BaseException(WRONG_RECRUIT_TYPE)); } diff --git a/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java b/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java index 2bc1346..7fbaf7a 100644 --- a/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java +++ b/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java @@ -3,12 +3,10 @@ import com.hatcher.haemo.common.BaseException; import com.hatcher.haemo.common.BaseResponse; import com.hatcher.haemo.recruitment.application.RecruitmentService; +import com.hatcher.haemo.recruitment.dto.RecruitmentListResponse; import com.hatcher.haemo.recruitment.dto.RecruitmentPostRequest; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import static com.hatcher.haemo.common.constants.RequestURI.recruitment; @@ -22,11 +20,17 @@ public class RecruitmentController { // 모집글 등록 @PostMapping("") public BaseResponse postRecruitment(@RequestBody RecruitmentPostRequest recruitmentPostRequest) { - try { - recruitmentService.postRecruitment(recruitmentPostRequest); - return BaseResponse.success(); - } catch (BaseException e) { - return BaseResponse.failure(e.getStatus()); - } + recruitmentService.postRecruitment(recruitmentPostRequest); + return BaseResponse.success(); } + +// // 모집글 목록 조회 +// @GetMapping("") +// public BaseResponse getRecruitmentList() { +// try { +// return BaseResponse.success(recruitmentService.getRecruitmentList()); +// } catch (BaseException e) { +// throw e; +// } +// } } diff --git a/src/main/java/com/hatcher/haemo/user/application/AuthService.java b/src/main/java/com/hatcher/haemo/user/application/AuthService.java index 9af1227..9961686 100644 --- a/src/main/java/com/hatcher/haemo/user/application/AuthService.java +++ b/src/main/java/com/hatcher/haemo/user/application/AuthService.java @@ -18,7 +18,7 @@ public class AuthService { @Value("${jwt.access-token-validity-in-millis}") - private int accessTokenExpirationTime; + private long accessTokenExpirationTime; @Value("${jwt.secret-key}") private String secretKey; diff --git a/src/main/java/com/hatcher/haemo/user/presentation/UserController.java b/src/main/java/com/hatcher/haemo/user/presentation/UserController.java index 4cc206e..564be33 100644 --- a/src/main/java/com/hatcher/haemo/user/presentation/UserController.java +++ b/src/main/java/com/hatcher/haemo/user/presentation/UserController.java @@ -18,42 +18,26 @@ public class UserController { // 회원가입 @PostMapping(value = "/signup") public BaseResponse signup(@RequestBody SignupRequest signupRequest) { - try { - return BaseResponse.success(userService.signup(signupRequest)); - } catch(BaseException e) { - return BaseResponse.failure(e.getStatus()); - } + return BaseResponse.success(userService.signup(signupRequest)); } // 로그인 @PostMapping("/login") public BaseResponse login(@RequestBody LoginRequest loginRequest) { - try { - return BaseResponse.success(userService.login(loginRequest)); - } catch(BaseException e) { - return BaseResponse.failure(e.getStatus()); - } + return BaseResponse.success(userService.login(loginRequest)); } // 닉네임 중복 체크 @PostMapping("/nickname") public BaseResponse validateNickname(@RequestBody NicknameRequest nicknameRequest) { - try { - userService.validateNickname(nicknameRequest.nickname()); - return BaseResponse.success(); - } catch (BaseException e){ - return BaseResponse.failure(e.getStatus()); - } + userService.validateNickname(nicknameRequest.nickname()); + return BaseResponse.success(); } // 아이디 중복 체크 @PostMapping("/loginId") public BaseResponse validateLoginId(@RequestBody LoginIdRequest loginIdRequest) { - try { - userService.validateLoginId(loginIdRequest.loginId()); - return BaseResponse.success(); - } catch (BaseException e){ - return BaseResponse.failure(e.getStatus()); - } + userService.validateLoginId(loginIdRequest.loginId()); + return BaseResponse.success(); } } From 9418af0b96105f37681011c730b1fe6c2e78289c Mon Sep 17 00:00:00 2001 From: joonghyun Date: Thu, 21 Mar 2024 22:35:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?hotfix:=20RecruitmentListResponse=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haemo/recruitment/dto/RecruitmentListResponse.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentListResponse.java diff --git a/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentListResponse.java b/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentListResponse.java new file mode 100644 index 0000000..ab657e1 --- /dev/null +++ b/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentListResponse.java @@ -0,0 +1,4 @@ +package com.hatcher.haemo.recruitment.dto; + +public record RecruitmentListResponse() { +}