Skip to content

Commit 91025c8

Browse files
committed
[#6] feat: Create common response DTO
response에 사용될 공통 형식인 ApiResult 클래스 생성
1 parent 7cbb434 commit 91025c8

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package team9.baseball.DTO.response;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class ApiResult<T> {
9+
private T data;
10+
private String error;
11+
12+
private ApiResult(T data, String error) {
13+
this.data = data;
14+
this.error = error;
15+
}
16+
17+
public static <T> ApiResult<T> succeed(T data) {
18+
return new ApiResult(data, null);
19+
}
20+
21+
public static ApiResult<?> failed(String errorMessage) {
22+
return new ApiResult<>(null, errorMessage);
23+
}
24+
25+
public static ApiResult<?> failed(Throwable throwable) {
26+
return failed(throwable.getMessage());
27+
}
28+
29+
public T getData() {
30+
return data;
31+
}
32+
33+
public String getError() {
34+
return error;
35+
}
36+
}

0 commit comments

Comments
 (0)