Skip to content

Commit

Permalink
feat: PageResponse κ΅¬ν˜„ (#26)
Browse files Browse the repository at this point in the history
* feat: `PageResponse` κ΅¬ν˜„

* refactor: 각 ν•„λ“œμ— `final` μΆ”κ°€
  • Loading branch information
punchdrunkard authored Aug 7, 2024
1 parent e859544 commit b021827
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/odiga/fiesta/common/ApiResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponse<T> {

private int statusCode;
private HttpStatus status; // reason phrase
private String message;
private T data;
private final int statusCode;
private final HttpStatus status; // reason phrase
private final String message;
private final T data;

@Builder
private ApiResponse(HttpStatus status, String message, T data) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/odiga/fiesta/common/PageResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.odiga.fiesta.common;

import java.util.List;

import lombok.Builder;
import lombok.Getter;

@Getter
public class PageResponse<T> {

private final List<T> content;
private final int offset;
private final int pageSize;
private final int totalElements;
private final int totalPages;

@Builder
public PageResponse(List<T> content, int offset, int pageSize, int totalElements, int totalPages) {
this.content = content;
this.offset = offset;
this.pageSize = pageSize;
this.totalElements = totalElements;
this.totalPages = totalPages;
}

public static <T> PageResponse<T> of(List<T> content, int offset, int pageSize, int totalElements, int totalPages) {
return PageResponse.<T>builder()
.content(content)
.offset(offset)
.pageSize(pageSize)
.totalElements(totalElements)
.totalPages(totalPages)
.build();
}

}

0 comments on commit b021827

Please sign in to comment.