Skip to content

Commit

Permalink
#1 feat: BaseResponse 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim committed Jan 16, 2024
1 parent 8e54358 commit 64a5d56
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/java/com/kkobugi/puremarket/common/BaseResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.kkobugi.puremarket.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Getter;

import static com.kkobugi.puremarket.common.BaseResponseStatus.SUCCESS;

@Getter
@AllArgsConstructor
@JsonPropertyOrder({"isSuccess", "code", "message", "result"})
public class BaseResponse<T> {

@JsonProperty("isSuccess")
private final Boolean isSuccess;
private final String message;
private final int code;

@JsonInclude(JsonInclude.Include.NON_NULL)
private T result;

public BaseResponse(T result) {
this.isSuccess = SUCCESS.isSuccess();
this.message = SUCCESS.getMessage();
this.code = SUCCESS.getCode();
this.result = result;
}

public BaseResponse(BaseResponseStatus status) {
this.isSuccess = status.isSuccess();
this.message = status.getMessage();
this.code = status.getCode();
}

// 요청은 성공했지만 데이터에 이상이 있는 경우
public BaseResponse(T result, BaseResponseStatus status) {
this.isSuccess = status.isSuccess();
this.message = status.getMessage();
this.code = status.getCode();
this.result = result;
}
}

0 comments on commit 64a5d56

Please sign in to comment.