From 458011644cefb36ab3c5fe8caf0e50ba0dfd8a5a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 11 Mar 2022 14:26:24 +0400 Subject: [PATCH] #5 -- add pagination, styles and footer --- data/db.mv.db | Bin 40960 -> 61440 bytes .../ru/ulstu/controller/NewsController.java | 25 ++++- .../ru/ulstu/model/OffsetablePageRequest.java | 93 ++++++++++++++++++ .../ru/ulstu/repository/NewsRepository.java | 4 + .../java/ru/ulstu/service/NewsService.java | 6 ++ src/main/resources/public/css/main.css | 23 ++++- src/main/resources/templates/admin.html | 2 +- src/main/resources/templates/default.html | 1 + src/main/resources/templates/news.html | 10 ++ 9 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/model/OffsetablePageRequest.java diff --git a/data/db.mv.db b/data/db.mv.db index d6e4cd9f6c6e1bcfbe2afeae7d02b1f7788bef06..06af13aad16e56b9be7343f62f4e00221e501083 100644 GIT binary patch literal 61440 zcmeG_TZ|jmb==jCEKAz8R+g=|bH!S*l+w%$Uo*2!VRK2Ymewv;BDpImHL@KJhbz`x za?OY0_M^3(7YZkhks_&zCTW7^RiH)OG>)A(mYoIxS|Dz?DQW}(iUcT{CM_EO6#Yoi zy5~OU^0i#OYH2eofiw5c%)RHHd(OG%oVn-B>{KXFsMPGoregG%EB}r&rKzeKurIc% zk4@Q{9kA<;)pUwenqG=ohE;N6W}sB7uUgG1EpW-HH_Ejtxv^Ann)XGfKBX0lF-NnV zoj&i+!+?hY4+9Z}}W}0C*ViFyLXp z!+?hY4+9GGUD5|{YjtiBd?R=$d!*BI6hvrR-ItET6CTWYGI#m?Atqk z?mOVSlMqnQ*23b<5ND$ZvEzu8*=qjFxnIFzCUg2a6sG^kCD2Lk}g= z7JWLVk~)+2Xpt)g@@sbhu6}%kQ+$|FyiO=S9H^8pIrBj7p;AO8g)@ZMHC5(?u%WAr z3$!q2gNTi}z>JxyV1sC=P>2Rv)mFnP#+yrGi%d*n4PYn18eb4#84N6kF(L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NUY%fk{}6wb#s4Dt#dXs;4zzGYy|&jgx}-2w9}sYh}L&AM93C+d%Q zd$f^(N3<%}li!7Xs}dw3mq0<uimSqe6R9*jaRw&Ag^+cdX=+{y~+m-y-KXktK4nsRc;cma;1q^`L>x?xk0>& z+{mlMn|YPK8n1G_nOFHM@G5&fCHNi?uY#|U!ubYD@b}OKP6_yPg0BQxjS}D!L)&6- zVsJjYF!(O>Dvy5>AWa>oM!iMX0ylyFn{xrRFdDNk4{;!A=$-I^jyGuQ?pAxGDtA51 zhY#anNLjMpO%Utd6w%&I5bNCxk>1S^>D?63-pvr{-4wCjO(E^w43XZ=5b50%(cVoE x>)iyg-c9eMy_+K1yBYF4O!V-`{~pHoFuQnZ51Ik@D~XZPp+bV diff --git a/src/main/java/ru/ulstu/controller/NewsController.java b/src/main/java/ru/ulstu/controller/NewsController.java index 111a1ca..34e8ba3 100644 --- a/src/main/java/ru/ulstu/controller/NewsController.java +++ b/src/main/java/ru/ulstu/controller/NewsController.java @@ -6,6 +6,7 @@ package ru.ulstu.controller; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -14,14 +15,21 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.model.News; +import ru.ulstu.model.OffsetablePageRequest; import ru.ulstu.service.NewsService; import javax.validation.Valid; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.IntStream; @Controller @RequestMapping("news") public class NewsController { + private final static int DEFAULT_PAGE_SIZE = 10; private final NewsService newsService; public NewsController(NewsService newsService) { @@ -29,8 +37,21 @@ public class NewsController { } @GetMapping("/news") - public String index(Model model) { - model.addAttribute("news", newsService.getAll()); + public String listNews(Model model, + @RequestParam Optional page, + @RequestParam Optional size) { + int currentPage = page.orElse(1); + int pageSize = size.orElse(DEFAULT_PAGE_SIZE); + + Page newsPage = newsService.getNews(new OffsetablePageRequest(currentPage - 1, pageSize)); + model.addAttribute("news", newsPage); + int totalPages = newsPage.getTotalPages(); + if (totalPages > 0) { + List pageNumbers = IntStream.rangeClosed(1, totalPages) + .boxed() + .collect(Collectors.toList()); + model.addAttribute("pageNumbers", pageNumbers); + } return "news"; } diff --git a/src/main/java/ru/ulstu/model/OffsetablePageRequest.java b/src/main/java/ru/ulstu/model/OffsetablePageRequest.java new file mode 100644 index 0000000..c715296 --- /dev/null +++ b/src/main/java/ru/ulstu/model/OffsetablePageRequest.java @@ -0,0 +1,93 @@ +package ru.ulstu.model; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + +import java.io.Serializable; + +public class OffsetablePageRequest implements Pageable, Serializable { + private final int offset; + private final int count; + private final Sort sort; + + public OffsetablePageRequest(int page, long pageSize) { + this(pageSize * page, pageSize, Sort.by("id")); + } + + public OffsetablePageRequest(long offset, long count, Sort sort) { + if (offset < 0) { + throw new IllegalArgumentException("Offset value must not be less than zero!"); + } + if (count < 1) { + throw new IllegalArgumentException("Count value must not be less than one!"); + } + this.offset = (int) offset; + this.count = (int) count; + this.sort = sort; + } + + @Override + public Sort getSort() { + return sort; + } + + @Override + public int getPageSize() { + return count; + } + + @Override + public int getPageNumber() { + return offset / count; + } + + @Override + public long getOffset() { + return offset; + } + + @Override + public boolean hasPrevious() { + return offset > 0; + } + + @Override + public Pageable next() { + return new OffsetablePageRequest(getOffset() + getPageSize(), getPageSize(), getSort()); + } + + @Override + public Pageable previousOrFirst() { + return hasPrevious() ? previous() : first(); + } + + public Pageable previous() { + return getOffset() == 0 ? this : new OffsetablePageRequest(getOffset() - getPageSize(), getPageSize(), getSort()); + } + + @Override + public Pageable first() { + return new OffsetablePageRequest(0, getPageSize(), getSort()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final OffsetablePageRequest other = (OffsetablePageRequest) obj; + return this.offset == other.offset && this.count == other.count; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + offset; + result = prime * result + count; + return result; + } +} diff --git a/src/main/java/ru/ulstu/repository/NewsRepository.java b/src/main/java/ru/ulstu/repository/NewsRepository.java index 6bd607a..f7f4fcf 100644 --- a/src/main/java/ru/ulstu/repository/NewsRepository.java +++ b/src/main/java/ru/ulstu/repository/NewsRepository.java @@ -1,5 +1,7 @@ package ru.ulstu.repository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.model.News; @@ -7,4 +9,6 @@ import java.util.List; public interface NewsRepository extends JpaRepository { List findFirst3ByOrderByDateDesc(); + + Page findByOrderByDateDesc(Pageable pageable); } diff --git a/src/main/java/ru/ulstu/service/NewsService.java b/src/main/java/ru/ulstu/service/NewsService.java index 3f743f0..f49dbdd 100644 --- a/src/main/java/ru/ulstu/service/NewsService.java +++ b/src/main/java/ru/ulstu/service/NewsService.java @@ -1,5 +1,7 @@ package ru.ulstu.service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import ru.ulstu.model.News; import ru.ulstu.repository.NewsRepository; @@ -50,4 +52,8 @@ public class NewsService { public List getLast() { return newsRepository.findFirst3ByOrderByDateDesc(); } + + public Page getNews(Pageable pageable) { + return newsRepository.findByOrderByDateDesc(pageable); + } } diff --git a/src/main/resources/public/css/main.css b/src/main/resources/public/css/main.css index 9b299ad..bbdc26e 100644 --- a/src/main/resources/public/css/main.css +++ b/src/main/resources/public/css/main.css @@ -31,4 +31,25 @@ .link-dark, .link-dark:visited, .link-dark:focus, .link-dark:any-link { color: black; -} \ No newline at end of file +} + +.pagination { + display: inline-block; +} + +.pagination a { + color: black; + float: left; + padding: 5px 5px; + text-decoration: none; +} + +.pagination a.active { + background-color: gray; + color: white; + border-radius: 2px; +} + +footer { + height: 50px; +} diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html index f37ada4..22e05cf 100644 --- a/src/main/resources/templates/admin.html +++ b/src/main/resources/templates/admin.html @@ -7,7 +7,7 @@ diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 3146bbf..99f7ed0 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -64,6 +64,7 @@
+
\ No newline at end of file diff --git a/src/main/resources/templates/news.html b/src/main/resources/templates/news.html index 1f6edf8..3b444e5 100644 --- a/src/main/resources/templates/news.html +++ b/src/main/resources/templates/news.html @@ -36,5 +36,15 @@ class="news-date">
+ + +