PostsResponseDTO.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package es.uv.garcosda.models;
  2. import java.io.Serializable;
  3. import java.util.List;
  4. import org.springframework.data.domain.Page;
  5. import es.uv.garcosda.domain.Post;
  6. public class PostsResponseDTO implements Serializable {
  7. private static final long serialVersionUID = 1L;
  8. private List<Post> posts;
  9. private long totalRecords;
  10. private int currentPage;
  11. private int pageSize;
  12. private boolean hasNextPage;
  13. private boolean hasPrevPage;
  14. public PostsResponseDTO() { }
  15. public PostsResponseDTO(List<Post> posts, long totalRecords, int currentPage, int pageSize, boolean hasNextPage, boolean hasPrevPage) {
  16. this.posts = posts;
  17. this.totalRecords = totalRecords;
  18. this.currentPage = currentPage;
  19. this.pageSize = pageSize;
  20. this.hasNextPage = hasNextPage;
  21. this.hasPrevPage = hasPrevPage;
  22. }
  23. public PostsResponseDTO(Page<Post> pageData) {
  24. this.posts = pageData.getContent();
  25. this.totalRecords = pageData.getTotalElements();
  26. this.currentPage = pageData.getNumber();
  27. this.pageSize = pageData.getSize();
  28. this.hasNextPage = pageData.hasNext();
  29. this.hasPrevPage = pageData.hasPrevious();
  30. }
  31. public List<Post> getPosts() {
  32. return posts;
  33. }
  34. public long getTotalRecords() {
  35. return totalRecords;
  36. }
  37. public int getCurrentPage() {
  38. return currentPage;
  39. }
  40. public int getPageSize() {
  41. return pageSize;
  42. }
  43. public boolean isHasNextPage() {
  44. return hasNextPage;
  45. }
  46. public boolean isHasPrevPage() {
  47. return hasPrevPage;
  48. }
  49. }