-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/common' into develop
- Loading branch information
Showing
8 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
31 changes: 31 additions & 0 deletions
31
blog/src/main/java/cloudclub/blog/common/enums/FailResponseStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cloudclub.blog.common.enums; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum FailResponseStatus { | ||
|
||
// example | ||
// HttpStatus 관련 논의 필요 | ||
BAD_REQUEST("BAD_REQUEST", "E400", HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), | ||
INVALID_PARAM_ERROR("INVALID_PARAM_ERROR", "E401", HttpStatus.BAD_REQUEST, "파라미터가 유효하지 않습니다."), | ||
INTERNAL_SERVER_ERROR("INTERNAL_SERVER_ERROR", | ||
"E500", | ||
HttpStatus.INTERNAL_SERVER_ERROR, | ||
"내부 서버 오류입니다."); | ||
|
||
private final String statusName; | ||
private final String statusCode; | ||
private final HttpStatus httpStatusCode; | ||
private final String message; | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return message; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
blog/src/main/java/cloudclub/blog/common/enums/SuccessResponseStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cloudclub.blog.common.enums; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SuccessResponseStatus { | ||
|
||
// S1XX : Server response success | ||
SUCCESS(HttpStatus.OK ,"S101", "요청이 성공하였습니다."), | ||
REDIRECT(HttpStatus.FOUND, "S102", "지정된 URL로 이동합니다."); | ||
// S2XX : something | ||
|
||
private HttpStatus httpStatus; | ||
private String statusCode; | ||
private String message; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
blog/src/main/java/cloudclub/blog/common/exception/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cloudclub.blog.common.exception; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import cloudclub.blog.common.enums.FailResponseStatus; | ||
import cloudclub.blog.common.model.ResponseDto; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
@ExceptionHandler(RestApiException.class) | ||
public <T> ResponseEntity<ResponseDto<T>> handleCustomException(final RestApiException e) { | ||
final FailResponseStatus errorCode = e.getFailResponseStatus(); | ||
e.printStackTrace(); | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(false) | ||
.statusCode(errorCode.getStatusCode().toString()) | ||
.message(errorCode.getMessage()) | ||
.data(null) | ||
.build(); | ||
return new ResponseEntity<>(dto, errorCode.getHttpStatusCode()); | ||
} | ||
|
||
@ExceptionHandler({Exception.class}) | ||
public <T> ResponseEntity<ResponseDto<T>> handleAllException(final Exception ex) { | ||
final FailResponseStatus errorCode = FailResponseStatus.INTERNAL_SERVER_ERROR; | ||
ex.printStackTrace(); | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(false) | ||
.statusCode(errorCode.getStatusCode().toString()) | ||
.message(errorCode.getMessage()) | ||
.data(null) | ||
.build(); | ||
return new ResponseEntity<>(dto, errorCode.getHttpStatusCode()); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
blog/src/main/java/cloudclub/blog/common/exception/RestApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cloudclub.blog.common.exception; | ||
|
||
import cloudclub.blog.common.enums.FailResponseStatus; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class RestApiException extends RuntimeException { | ||
|
||
private FailResponseStatus failResponseStatus; | ||
|
||
public RestApiException(FailResponseStatus e) { | ||
super(e.getMessage()); | ||
this.failResponseStatus = e; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
blog/src/main/java/cloudclub/blog/common/model/ResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cloudclub.blog.common.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ResponseDto<T> { | ||
|
||
private boolean successOrNot; | ||
private String statusCode; | ||
private String message; | ||
private T data; | ||
|
||
} | ||
|
19 changes: 19 additions & 0 deletions
19
blog/src/main/java/cloudclub/blog/common/model/ResponsePagingDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cloudclub.blog.common.model; | ||
|
||
import java.net.http.HttpResponse; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public class ResponsePagingDto<T> { | ||
private String statusCode; | ||
|
||
private String message; | ||
|
||
private Long page; | ||
|
||
private Integer size; | ||
|
||
private T data; | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
blog/src/main/java/cloudclub/blog/common/util/ResponseUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package cloudclub.blog.common.util; | ||
|
||
import cloudclub.blog.common.enums.SuccessResponseStatus; | ||
import cloudclub.blog.common.model.ResponseDto; | ||
import cloudclub.blog.common.model.ResponsePagingDto; | ||
import lombok.experimental.UtilityClass; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@UtilityClass | ||
public class ResponseUtil { | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse() { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(SuccessResponseStatus.SUCCESS.getStatusCode()) | ||
.message(SuccessResponseStatus.SUCCESS.getMessage()) | ||
.data(null) | ||
.build(); | ||
return new ResponseEntity<>(dto, SuccessResponseStatus.SUCCESS.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(HttpHeaders httpHeaders) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(SuccessResponseStatus.SUCCESS.getStatusCode()) | ||
.message(SuccessResponseStatus.SUCCESS.getMessage()) | ||
.data(null) | ||
.build(); | ||
return new ResponseEntity<>(dto, httpHeaders, SuccessResponseStatus.SUCCESS.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(T data) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(SuccessResponseStatus.SUCCESS.getStatusCode()) | ||
.message(SuccessResponseStatus.SUCCESS.getMessage()) | ||
.data(data) | ||
.build(); | ||
return new ResponseEntity<>(dto, SuccessResponseStatus.SUCCESS.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(T data, HttpHeaders httpHeaders) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(SuccessResponseStatus.SUCCESS.getStatusCode()) | ||
.message(SuccessResponseStatus.SUCCESS.getMessage()) | ||
.data(data) | ||
.build(); | ||
return new ResponseEntity<>(dto, httpHeaders, SuccessResponseStatus.SUCCESS.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(SuccessResponseStatus status) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(status.getStatusCode()) | ||
.message(status.getMessage()) | ||
.data(null) | ||
.build(); | ||
return new ResponseEntity<>(dto, status.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(SuccessResponseStatus status, HttpHeaders httpHeaders) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(status.getStatusCode()) | ||
.message(status.getMessage()) | ||
.data(null) | ||
.build(); | ||
return new ResponseEntity<>(dto, httpHeaders, status.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(SuccessResponseStatus status, T data) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(status.getStatusCode()) | ||
.message(status.getMessage()) | ||
.data(data) | ||
.build(); | ||
return new ResponseEntity<>(dto, status.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> createSuccessResponse(SuccessResponseStatus status, T data, HttpHeaders httpHeaders) { | ||
ResponseDto<T> dto = ResponseDto.<T>builder() | ||
.successOrNot(true) | ||
.statusCode(status.getStatusCode()) | ||
.message(status.getMessage()) | ||
.data(data) | ||
.build(); | ||
return new ResponseEntity<>(dto, httpHeaders, status.getHttpStatus()); | ||
} | ||
|
||
|
||
|
||
public static <T> ResponseEntity<ResponsePagingDto<T>> createSuccessResponse(T data, Pageable pageable) { | ||
ResponsePagingDto<T> dto = ResponsePagingDto.<T>builder() | ||
.statusCode(SuccessResponseStatus.SUCCESS.getStatusCode()) | ||
.message(SuccessResponseStatus.SUCCESS.getMessage()) | ||
.data(data) | ||
.page(pageable.getOffset()) | ||
.size(pageable.getPageSize()) | ||
.build(); | ||
return new ResponseEntity<>(dto, SuccessResponseStatus.SUCCESS.getHttpStatus()); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponsePagingDto<T>> createSuccessResponse(T data, HttpHeaders httpHeaders, Pageable pageable) { | ||
ResponsePagingDto<T> dto = ResponsePagingDto.<T>builder() | ||
.statusCode(SuccessResponseStatus.SUCCESS.getStatusCode()) | ||
.message(SuccessResponseStatus.SUCCESS.getMessage()) | ||
.data(data) | ||
.page(pageable.getOffset()) | ||
.size(pageable.getPageSize()) | ||
.build(); | ||
return new ResponseEntity<>(dto, httpHeaders, SuccessResponseStatus.SUCCESS.getHttpStatus()); | ||
} | ||
} |