-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#6] feat: Create common response DTO
response에 사용될 공통 형식인 ApiResult 클래스 생성
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
BE/baseball/src/main/java/team9/baseball/DTO/response/ApiResult.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,36 @@ | ||
package team9.baseball.DTO.response; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class ApiResult<T> { | ||
private T data; | ||
private String error; | ||
|
||
private ApiResult(T data, String error) { | ||
this.data = data; | ||
this.error = error; | ||
} | ||
|
||
public static <T> ApiResult<T> succeed(T data) { | ||
return new ApiResult(data, null); | ||
} | ||
|
||
public static ApiResult<?> failed(String errorMessage) { | ||
return new ApiResult<>(null, errorMessage); | ||
} | ||
|
||
public static ApiResult<?> failed(Throwable throwable) { | ||
return failed(throwable.getMessage()); | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public String getError() { | ||
return error; | ||
} | ||
} |