feat: api wrapping
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.kamco.cd.kamcoback.config.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.kamco.cd.kamcoback.config.enums.EnumType;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@@ -18,10 +20,17 @@ public class ApiResponseDto<T> {
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private T errorData;
|
||||
|
||||
@JsonIgnore private HttpStatus httpStatus = HttpStatus.OK;
|
||||
|
||||
public ApiResponseDto(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private ApiResponseDto(T data, HttpStatus httpStatus) {
|
||||
this.data = data;
|
||||
this.httpStatus = httpStatus;
|
||||
}
|
||||
|
||||
public ApiResponseDto(ApiResponseCode code) {
|
||||
this.error = new Error(code.getId(), code.getMessage());
|
||||
}
|
||||
@@ -35,8 +44,17 @@ public class ApiResponseDto<T> {
|
||||
this.errorData = errorData;
|
||||
}
|
||||
|
||||
// HTTP 상태 코드가 내장된 ApiResponseDto 반환 메서드들
|
||||
public static <T> ApiResponseDto<T> createOK(T data) {
|
||||
return new ApiResponseDto<>(data);
|
||||
return new ApiResponseDto<>(data, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
public static <T> ApiResponseDto<T> ok(T data) {
|
||||
return new ApiResponseDto<>(data, HttpStatus.OK);
|
||||
}
|
||||
|
||||
public static <T> ApiResponseDto<T> deleteOk(T data) {
|
||||
return new ApiResponseDto<>(data, HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
public static ApiResponseDto<String> createException(ApiResponseCode code) {
|
||||
|
||||
Reference in New Issue
Block a user