Skip to content
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

[hotfix] 예외 반환 형식 변경 #25

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/hatcher/haemo/common/BaseException.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ public enum BaseResponseStatus {
public int getCode() {
return httpStatus.value();
}
public HttpStatus getHttpStatus() {return httpStatus; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.hatcher.haemo.recruitment.dto;

public record RecruitmentListResponse() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<RecruitmentListResponse> getRecruitmentList() {
// try {
// return BaseResponse.success(recruitmentService.getRecruitmentList());
// } catch (BaseException e) {
// throw e;
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,26 @@ public class UserController {
// 회원가입
@PostMapping(value = "/signup")
public BaseResponse<TokenResponse> 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<TokenResponse> 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<String> 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<String> 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();
}
}
Loading