-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend pagination models Paginate guild users endpoint Cache discord guild members
- Loading branch information
1 parent
8434388
commit f139d7c
Showing
7 changed files
with
104 additions
and
18 deletions.
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/de/webalf/slotbot/model/dtos/website/pagination/FrontendPage.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,49 @@ | ||
package de.webalf.slotbot.model.dtos.website.pagination; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
import org.springframework.data.domain.Page; | ||
|
||
/** | ||
* Page metadata used by the frontend. Replacement for {@link org.springframework.hateoas.PagedModel.PageMetadata} | ||
* | ||
* @author Alf | ||
* @since 28.02.2023 | ||
*/ | ||
@Value | ||
@Builder(access = AccessLevel.PRIVATE) | ||
public class FrontendPage { | ||
/** | ||
* Size of the payload | ||
*/ | ||
int size; | ||
|
||
/** | ||
* Total count of elements | ||
*/ | ||
long totalElements; | ||
|
||
/** | ||
* Count of available pages | ||
*/ | ||
int totalPages; | ||
|
||
/** | ||
* Current page number | ||
*/ | ||
int number; | ||
|
||
/** | ||
* Creates a {@link FrontendPage} object by the given page | ||
*/ | ||
static FrontendPage of(@NonNull Page<?> page) { | ||
return FrontendPage.builder() | ||
.size(page.getSize()) | ||
.totalElements(page.getTotalElements()) | ||
.totalPages(page.getTotalPages()) | ||
.number(page.getNumber()) | ||
.build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/de/webalf/slotbot/model/dtos/website/pagination/FrontendPageable.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,40 @@ | ||
package de.webalf.slotbot.model.dtos.website.pagination; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This model provides the expected paginated format for the frontend and is a replacement for {@link org.springframework.hateoas.PagedModel} | ||
* | ||
* @param <T> type of the content, usually DTOs | ||
* @author Alf | ||
* @since 28.02.2023 | ||
*/ | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@Value | ||
public class FrontendPageable<T> { | ||
/** | ||
* Info about this page | ||
*/ | ||
FrontendPage page; | ||
/** | ||
* Actual page content | ||
*/ | ||
List<T> content; | ||
|
||
/** | ||
* Creates a {@link FrontendPageable} object by the given page | ||
*/ | ||
public static <T> FrontendPageable<T> of(@NonNull Page<T> page) { | ||
final List<T> content = page.getContent(); | ||
return FrontendPageable.<T>builder() | ||
.content(content) | ||
.page(FrontendPage.of(page)) | ||
.build(); | ||
} | ||
} |
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
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
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