personal-finances/Common/src/main/java/dev/mvvasilev/common/controller/AbstractRestController.java

23 lines
757 B
Java
Raw Normal View History

2023-12-15 20:04:57 +02:00
package dev.mvvasilev.common.controller;
import dev.mvvasilev.common.web.APIErrorDTO;
import dev.mvvasilev.common.web.APIResponseDTO;
import java.util.List;
public class AbstractRestController {
protected <T> APIResponseDTO<T> withStatus(int statusCode, String statusText, T body) {
return new APIResponseDTO<>(body, null, statusCode, statusText);
}
protected <T> APIResponseDTO<T> withSingleError(int statusCode, String statusText, String errorMessage, String errorCode, String stacktrace) {
return new APIResponseDTO<>(null, List.of(new APIErrorDTO(errorMessage, errorCode, stacktrace)), statusCode, statusText);
}
protected <T> APIResponseDTO<T> ok(T body) {
return withStatus(200, "ok", body);
}
}