Changeset 0c37625
- Timestamp:
- 10/07/21 20:22:23 (3 years ago)
- Branches:
- master
- Children:
- ee0e297
- Parents:
- 276a8b6
- Location:
- src/main
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/controller/DonationPostController.java
r276a8b6 r0c37625 127 127 @RequestParam String sort, 128 128 @RequestParam(required = false,defaultValue = "") String order) { 129 Page<DonationPost> postList = donationPostService.findPaginated(page,6, sort, order );129 Page<DonationPost> postList = donationPostService.findPaginated(page,6, sort, order, true); 130 130 if (postList.getSize() == 0) { 131 131 model.addAttribute("noPosts", true); … … 204 204 reasonService.save(reason); 205 205 reportPost.getReasons().add(reason); 206 reportPost.setNumReports(reportPost.getNumReports() + 1); 206 207 reportPostService.save(reportPost); 207 208 return String.format("redirect:/post?postid=%d", postid); -
src/main/java/it/finki/charitable/controller/ModeratorController.java
r276a8b6 r0c37625 6 6 import it.finki.charitable.services.ReasonService; 7 7 import it.finki.charitable.services.ReportPostService; 8 import org.springframework.data.domain.Page; 8 9 import org.springframework.security.core.context.SecurityContextHolder; 9 10 import org.springframework.stereotype.Controller; … … 33 34 34 35 @RequestMapping("moderator/approval") 35 public String approval(Model model) { 36 List<DonationPost> postList = donationPostService.findAllByApproved(false); 37 if (postList.size() == 0) { 36 public String approval(Model model, 37 @RequestParam int page, 38 @RequestParam String sort, 39 @RequestParam(required = false,defaultValue = "") String order) { 40 Page<DonationPost> postList = donationPostService.findPaginated(page, 6, sort, order, false); 41 if (postList.getSize() == 0) { 38 42 model.addAttribute("noPosts", true); 39 43 return "postApproval"; 40 44 } 45 model.addAttribute("totalPages", postList.getTotalPages()); 41 46 model.addAttribute("postList", postList); 42 47 return "postApproval"; … … 92 97 93 98 @RequestMapping("/moderator/report") 94 public String reportedPosts(Model model) { 95 List<ReportPost> postList = reportPostService.findAll(); 96 if (postList.size() == 0) { 99 public String reportedPosts(Model model, 100 @RequestParam int page, 101 @RequestParam String sort, 102 @RequestParam(required = false,defaultValue = "") String order) { 103 Page<ReportPost> postList = reportPostService.findAll(page, 6, sort, order); 104 if (postList.getSize() == 0) { 97 105 model.addAttribute("noPosts", true); 98 106 return "reportedPosts"; -
src/main/java/it/finki/charitable/entities/ReportPost.java
r276a8b6 r0c37625 2 2 3 3 import javax.persistence.*; 4 import java.time.LocalDate; 4 5 import java.util.ArrayList; 5 6 import java.util.List; … … 32 33 private List<Reason> reasons = new ArrayList<>(); 33 34 35 private int numReports = 0; 36 34 37 public Long getId() { 35 38 return id; … … 55 58 this.reasons = reasons; 56 59 } 60 61 public int getNumReports() { 62 return numReports; 63 } 64 65 public void setNumReports(int numReports) { 66 this.numReports = numReports; 67 } 57 68 } -
src/main/java/it/finki/charitable/repository/ReportPostRepository.java
r276a8b6 r0c37625 3 3 import it.finki.charitable.entities.DonationPost; 4 4 import it.finki.charitable.entities.ReportPost; 5 import org.springframework.data.domain.Page; 6 import org.springframework.data.domain.Pageable; 5 7 import org.springframework.data.jpa.repository.JpaRepository; 6 8 import org.springframework.stereotype.Repository; -
src/main/java/it/finki/charitable/security/SecurityConfig.java
r276a8b6 r0c37625 67 67 RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); 68 68 if(authentication.getAuthorities().toString().contains("MODERATOR")) { 69 redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/moderator/approval ");69 redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/moderator/approval?page=1&sort=id"); 70 70 } else { 71 71 redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/"); -
src/main/java/it/finki/charitable/services/DonationPostService.java
r276a8b6 r0c37625 54 54 } 55 55 56 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort, String order ) {56 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort, String order, boolean approved) { 57 57 Sort s = Sort.by(sort); 58 58 s = order.equals("asc") ? s.ascending() : s.descending(); 59 59 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, s); 60 return donationPostRepository.findAllByApproved(pageable, true);60 return donationPostRepository.findAllByApproved(pageable, approved); 61 61 } 62 62 } -
src/main/java/it/finki/charitable/services/ReportPostService.java
r276a8b6 r0c37625 5 5 import it.finki.charitable.entities.ReportPost; 6 6 import it.finki.charitable.repository.ReportPostRepository; 7 import org.springframework.data.domain.Page; 8 import org.springframework.data.domain.PageRequest; 9 import org.springframework.data.domain.Pageable; 10 import org.springframework.data.domain.Sort; 7 11 import org.springframework.stereotype.Service; 8 12 … … 18 22 } 19 23 20 public List<ReportPost> findAll() { 21 return reportPostRepository.findAll(); 24 public Page<ReportPost> findAll(int pageNo, int pageSize, String sort, String order) { 25 Sort s = Sort.by(sort); 26 s = order.equals("asc") ? s.ascending() : s.descending(); 27 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, s); 28 return reportPostRepository.findAll(pageable); 22 29 } 23 30 -
src/main/resources/templates/common/navbar.html
r276a8b6 r0c37625 24 24 <li class="nav-item"> 25 25 <a sec:authorize="isAnonymous() or hasAuthority('USER')" th:href="@{/album?page=1&sort=id}" class="nav-link px-2 text-white">Posts</a> 26 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/approval }" class="nav-link px-2 text-white">Posts for approval</a>26 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/approval?page=1&sort=id}" class="nav-link px-2 text-white">Posts for approval</a> 27 27 </li> 28 28 <li class="nav-item"> 29 29 <a sec:authorize="hasAuthority('USER')" th:href="@{/upload}" class="nav-link px-2 text-white">Upload</a> 30 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/report }" class="nav-link px-2 text-white">Reported posts</a>30 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/report?page=1&sort=id}" class="nav-link px-2 text-white">Reported posts</a> 31 31 </li> 32 32 </ul> -
src/main/resources/templates/postApproval.html
r276a8b6 r0c37625 16 16 <p th:if="${noPosts}">No posts</p> 17 17 <div th:unless="${noPosts}" class="album py-5 bg-light"> 18 18 19 <div class="container"> 19 20 <div class="row"> 21 <div class="col-md-2"> 22 <label class="form-label" for="sortBy">Sort By</label> 23 <select class="input-group-text" id="sortBy"> 24 <option value="id">Default</option> 25 <option value="title">Title</option> 26 <option value="dateDue">Date due</option> 27 <option value="fundsNeeded">Funds needed</option> 28 </select> 29 </div> 30 <div class="col-md-2"> 31 <label class="form-label" for="order">Order</label> 32 <select class="input-group-text" id="order"> 33 <option value="asc">Ascending</option> 34 <option value="desc">Descending</option> 35 </select> 36 </div> 37 </div> 38 <br> 20 39 <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3"> 21 40 <div class="col" th:each="post : ${postList}"> … … 37 56 </div> 38 57 </div> 39 <hr class="ui-menu-divider" /> 58 <hr class="ui-menu-divider"/> 59 <nav> 60 <div id="pagination"></div> 61 </nav> 40 62 </div> 41 63 42 64 </main> 43 65 <script src="/js/bootstrap.min.js"></script> 66 <script id="helper" src="/js/pagination.js" th:data-pages="${totalPages}"></script> 44 67 </body> 45 68 </html> -
src/main/resources/templates/reportedPosts.html
r276a8b6 r0c37625 17 17 <div th:unless="${noPosts}" class="album py-5 bg-light"> 18 18 <div class="container"> 19 19 <div class="row"> 20 <div class="col-md-2"> 21 <label class="form-label" for="sortBy">Sort By</label> 22 <select class="input-group-text" id="sortBy"> 23 <option value="id">Default</option> 24 <option value="numReports">Number of reports</option> 25 </select> 26 </div> 27 <div class="col-md-2"> 28 <label class="form-label" for="order">Order</label> 29 <select class="input-group-text" id="order"> 30 <option value="asc">Ascending</option> 31 <option value="desc">Descending</option> 32 </select> 33 </div> 34 </div> 35 <br/> 20 36 <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3"> 21 37 <div class="col" th:each="post : ${postList}"> … … 30 46 <a class="btn btn-sm btn-outline-secondary" th:href="@{/moderator/reportPost(postid=${post.id})}">Open</a> 31 47 </div> 32 <span class="text-muted"> Date due: <small th:text="${post.donationPost.dateDue}"></small></span>48 <span class="text-muted">Number of reports: <small th:text="${post.numReports}"></small></span> 33 49 </div> 34 50 </div> … … 38 54 </div> 39 55 <hr class="ui-menu-divider" /> 56 <nav> 57 <div id="pagination"></div> 58 </nav> 40 59 </div> 41 60 42 61 </main> 43 62 <script src="/js/bootstrap.min.js"></script> 63 <script id="helper" src="/js/pagination.js" th:data-pages="${totalPages}"></script> 44 64 </body> 45 65 </html>
Note:
See TracChangeset
for help on using the changeset viewer.