Skip to content

Commit c5dd449

Browse files
committed
add core response objects
1 parent 0ab92b2 commit c5dd449

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package it.aboutbits.springboot.toolbox.mvc.response;
2+
3+
import org.springframework.lang.Nullable;
4+
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public record ErrorResponse(
9+
@Nullable String message,
10+
@Nullable Map<String, List<String>> errors
11+
) {
12+
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package it.aboutbits.springboot.toolbox.mvc.response;
2+
3+
import lombok.NonNull;
4+
5+
public record ItemResponse<T>(@NonNull T data) {
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package it.aboutbits.springboot.toolbox.mvc.response;
2+
3+
import lombok.NonNull;
4+
5+
import java.util.List;
6+
7+
public record ListResponse<T>(@NonNull List<T> data) {
8+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package it.aboutbits.springboot.toolbox.mvc.response;
2+
3+
import lombok.NonNull;
4+
import org.springframework.data.domain.Page;
5+
6+
import java.util.List;
7+
8+
public record PagedResponse<T>(
9+
@NonNull
10+
List<T> data,
11+
@NonNull
12+
MetaWithPagination meta
13+
) {
14+
15+
public record MetaWithPagination(
16+
@NonNull
17+
Pagination pagination
18+
) {
19+
public record Pagination(long page, int size, long totalElements) {
20+
public static Pagination of(@NonNull Page<?> page) {
21+
return new Pagination(
22+
page.getNumber(),
23+
page.getSize(),
24+
page.getTotalElements()
25+
);
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)