-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
95 additions
and
224 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
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
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
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
53 changes: 0 additions & 53 deletions
53
common-module/src/main/java/com/foodgo/commonmodule/common/ApiResponse.java
This file was deleted.
Oops, something went wrong.
121 changes: 33 additions & 88 deletions
121
common-module/src/main/java/com/foodgo/commonmodule/common/ApplicationResponse.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 |
---|---|---|
@@ -1,108 +1,53 @@ | ||
package com.foodgo.commonmodule.common; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.jackson.Jacksonized; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Data | ||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Jacksonized | ||
@JsonPropertyOrder({"statusCode", "message", "content"}) | ||
public class ApplicationResponse<T> { | ||
private ApplicationResult result; | ||
private T payload; | ||
|
||
public static <T> ApplicationResponse<T> ok(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.OK.value()) | ||
.message("API 호출 성공") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> ok(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.OK.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
// @JsonProperty("isSuccess") | ||
// private final Boolean isSuccess; | ||
|
||
public static <T> ApplicationResponse<T> badRequest(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.BAD_REQUEST.value()) | ||
.message("잘못된 요청입니다.") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
@JsonProperty("statusCode") | ||
@NonNull | ||
private final String statusCode; | ||
|
||
public static <T> ApplicationResponse<T> badRequest(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.BAD_REQUEST.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
@JsonProperty("message") | ||
@NonNull | ||
private final String message; | ||
|
||
public static <T> ApplicationResponse<T> notAuthenticated(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.UNAUTHORIZED.value()) | ||
.message("잘못된 접근입니다.") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonProperty("content") | ||
private T content; | ||
|
||
public static <T> ApplicationResponse<T> notAuthenticated(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.UNAUTHORIZED.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
// 성공한 경우 응답 생성 | ||
public static <T> ApplicationResponse<T> onSuccess(T content) { | ||
// return new ApiResponse<>(true, code.getReasonHttpStatus().getCode(), code.getReasonHttpStatus().getMessage(), result); | ||
return new ApplicationResponse<>(HttpStatus.OK.name(), HttpStatus.OK.getReasonPhrase(), content); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> server(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.message("API 호출 실패") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
// 실패한 경우 응답 생성 | ||
public static <T> ApplicationResponse<T> onFailure(String statusCode, String message) { | ||
// return new ApiResponse<>(false, code, message, data); | ||
return new ApplicationResponse<>(statusCode, message, null); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> server(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
public static <T> ApplicationResponse<T> onFailure(String statusCode, String message, T content) { | ||
return new ApplicationResponse<>(statusCode, message, content); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> custom(T payload, Integer code, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(code) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
// Json serialize | ||
public String toJsonString() throws JsonProcessingException { | ||
return new ObjectMapper().writeValueAsString(this); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
common-module/src/main/java/com/foodgo/commonmodule/common/ApplicationResult.java
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.