Changeset ee0e297
- Timestamp:
- 10/07/21 20:29:27 (3 years ago)
- Branches:
- master
- Children:
- 7888b17
- Parents:
- 0c37625
- Location:
- src/main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/controller/DonationPostController.java
r0c37625 ree0e297 128 128 @RequestParam(required = false,defaultValue = "") String order) { 129 129 Page<DonationPost> postList = donationPostService.findPaginated(page,6, sort, order, true); 130 if (postList.get Size() == 0) {130 if (postList.getTotalElements() == 0) { 131 131 model.addAttribute("noPosts", true); 132 132 return "album"; -
src/main/java/it/finki/charitable/controller/ModeratorController.java
r0c37625 ree0e297 39 39 @RequestParam(required = false,defaultValue = "") String order) { 40 40 Page<DonationPost> postList = donationPostService.findPaginated(page, 6, sort, order, false); 41 if (postList.get Size() == 0) {41 if (postList.getTotalElements() == 0) { 42 42 model.addAttribute("noPosts", true); 43 43 return "postApproval"; … … 72 72 donationPostService.save(post); 73 73 emailService.sendApprovalEmail(post.getUser().getEmail(), "CharitAbleMk: " + post.getTitle() + " has been approved", postid); 74 return "redirect:/moderator/approval ";74 return "redirect:/moderator/approval?page=1&sort=id"; 75 75 } 76 76 … … 81 81 emailService.sendNoApprovalEmail(post.getUser().getEmail(), "CharitAbleMk: " + post.getTitle() + " has not been approved", description); 82 82 deleteDonationPost(post); 83 return "redirect:/moderator/approval ";83 return "redirect:/moderator/approval?page=1&sort=id"; 84 84 } 85 85 86 86 @RequestMapping("/moderator/myApprovedPosts") 87 public String myApprovedPosts(Model model) { 87 public String myApprovedPosts(Model model, 88 @RequestParam int page, 89 @RequestParam String sort, 90 @RequestParam(required = false,defaultValue = "") String order) { 88 91 Moderator moderator = (Moderator) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 89 List<DonationPost> postList = donationPostService.findAllByModerator(moderator);90 if (postList. size() == 0) {92 Page<DonationPost> postList = donationPostService.findAllByModerator(page, 6, sort, order, moderator); 93 if (postList.getTotalElements() == 0) { 91 94 model.addAttribute("noPosts", true); 92 95 return "postApproval"; 93 96 } 97 model.addAttribute("totalPages", postList.getTotalPages()); 94 98 model.addAttribute("postList", postList); 95 99 return "postApproval"; … … 102 106 @RequestParam(required = false,defaultValue = "") String order) { 103 107 Page<ReportPost> postList = reportPostService.findAll(page, 6, sort, order); 104 if (postList.get Size() == 0) {108 if (postList.getTotalElements() == 0) { 105 109 model.addAttribute("noPosts", true); 106 110 return "reportedPosts"; 107 111 } 112 model.addAttribute("totalPages",postList.getTotalPages()); 108 113 model.addAttribute("postList", postList); 109 114 return "reportedPosts"; … … 130 135 ReportPost post = reportPostService.findById(postid); 131 136 deleteReportPost(post); 132 return "redirect:/moderator/report ";137 return "redirect:/moderator/report?page=1&sort=id"; 133 138 } 134 139 … … 141 146 deleteReportPost(post); 142 147 deleteDonationPost(donationPost); 143 return "redirect:/moderator/approval ";148 return "redirect:/moderator/approval?page=1&sort=id"; 144 149 } 145 150 -
src/main/java/it/finki/charitable/repository/DonationPostRepository.java
r0c37625 ree0e297 15 15 List<DonationPost> findAllByUser(AppUser user); 16 16 List<DonationPost> findAllByApproved(Boolean approved); 17 List<DonationPost> findAllByModerator(Moderator moderator);17 Page<DonationPost> findAllByModerator(Pageable pageable, Moderator moderator); 18 18 Page<DonationPost> findAllByApproved(Pageable pageable, boolean approved); 19 19 } -
src/main/java/it/finki/charitable/services/DonationPostService.java
r0c37625 ree0e297 46 46 } 47 47 48 public List<DonationPost> findAllByModerator(Moderator moderator) { 49 return donationPostRepository.findAllByModerator(moderator); 48 public Page<DonationPost> findAllByModerator(int pageNo, int pageSize, String sort, String order, Moderator moderator) { 49 Sort s = Sort.by(sort); 50 s = order.equals("asc") ? s.ascending() : s.descending(); 51 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, s); 52 return donationPostRepository.findAllByModerator(pageable, moderator); 50 53 } 51 54 -
src/main/resources/templates/common/navbar.html
r0c37625 ree0e297 39 39 <a sec:authorize="isAnonymous()" type="button" class="btn btn-warning" th:href="@{/register}">Sign-up</a> 40 40 <a sec:authorize="isAuthenticated() and hasAuthority('USER')" type="button" class="btn btn-outline-light me-2" th:href="@{/userInformation}">My profile - <span th:text="${user.firstName}"></span></a> 41 <a sec:authorize="isAuthenticated() and hasAuthority('MODERATOR')" type="button" class="btn btn-outline-light me-2" th:href="@{/moderator/myApprovedPosts }">My approved posts - <span th:text="${user.firstName} + ${user.lastName}"></span></a>41 <a sec:authorize="isAuthenticated() and hasAuthority('MODERATOR')" type="button" class="btn btn-outline-light me-2" th:href="@{/moderator/myApprovedPosts?page=1&sort=id}">My approved posts - <span th:text="${user.firstName} + ${user.lastName}"></span></a> 42 42 <a sec:authorize="isAuthenticated()" type="button" class="btn btn-warning" th:href="@{/logout}">Logout</a> 43 43 </div>
Note:
See TracChangeset
for help on using the changeset viewer.