Changeset ee0e297 for src/main


Ignore:
Timestamp:
10/07/21 20:29:27 (3 years ago)
Author:
KostaFortumanov <kfortumanov@…>
Branches:
master
Children:
7888b17
Parents:
0c37625
Message:

bug fix

Location:
src/main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/charitable/controller/DonationPostController.java

    r0c37625 ree0e297  
    128128                        @RequestParam(required = false,defaultValue = "") String order) {
    129129        Page<DonationPost> postList = donationPostService.findPaginated(page,6, sort, order, true);
    130         if (postList.getSize() == 0) {
     130        if (postList.getTotalElements() == 0) {
    131131            model.addAttribute("noPosts", true);
    132132            return "album";
  • src/main/java/it/finki/charitable/controller/ModeratorController.java

    r0c37625 ree0e297  
    3939                           @RequestParam(required = false,defaultValue = "") String order) {
    4040        Page<DonationPost> postList = donationPostService.findPaginated(page, 6, sort, order, false);
    41         if (postList.getSize() == 0) {
     41        if (postList.getTotalElements() == 0) {
    4242            model.addAttribute("noPosts", true);
    4343            return "postApproval";
     
    7272        donationPostService.save(post);
    7373        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";
    7575    }
    7676
     
    8181        emailService.sendNoApprovalEmail(post.getUser().getEmail(), "CharitAbleMk: " + post.getTitle() + " has not been approved", description);
    8282        deleteDonationPost(post);
    83         return "redirect:/moderator/approval";
     83        return "redirect:/moderator/approval?page=1&sort=id";
    8484    }
    8585
    8686    @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) {
    8891        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) {
    9194            model.addAttribute("noPosts", true);
    9295            return "postApproval";
    9396        }
     97        model.addAttribute("totalPages", postList.getTotalPages());
    9498        model.addAttribute("postList", postList);
    9599        return "postApproval";
     
    102106                                @RequestParam(required = false,defaultValue = "") String order) {
    103107        Page<ReportPost> postList = reportPostService.findAll(page, 6, sort, order);
    104         if (postList.getSize() == 0) {
     108        if (postList.getTotalElements() == 0) {
    105109            model.addAttribute("noPosts", true);
    106110            return "reportedPosts";
    107111        }
     112        model.addAttribute("totalPages",postList.getTotalPages());
    108113        model.addAttribute("postList", postList);
    109114        return "reportedPosts";
     
    130135        ReportPost post = reportPostService.findById(postid);
    131136        deleteReportPost(post);
    132         return "redirect:/moderator/report";
     137        return "redirect:/moderator/report?page=1&sort=id";
    133138    }
    134139
     
    141146        deleteReportPost(post);
    142147        deleteDonationPost(donationPost);
    143         return "redirect:/moderator/approval";
     148        return "redirect:/moderator/approval?page=1&sort=id";
    144149    }
    145150
  • src/main/java/it/finki/charitable/repository/DonationPostRepository.java

    r0c37625 ree0e297  
    1515    List<DonationPost> findAllByUser(AppUser user);
    1616    List<DonationPost> findAllByApproved(Boolean approved);
    17     List<DonationPost> findAllByModerator(Moderator moderator);
     17    Page<DonationPost> findAllByModerator(Pageable pageable, Moderator moderator);
    1818    Page<DonationPost> findAllByApproved(Pageable pageable, boolean approved);
    1919}
  • src/main/java/it/finki/charitable/services/DonationPostService.java

    r0c37625 ree0e297  
    4646    }
    4747
    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);
    5053    }
    5154
  • src/main/resources/templates/common/navbar.html

    r0c37625 ree0e297  
    3939                    <a sec:authorize="isAnonymous()" type="button" class="btn btn-warning" th:href="@{/register}">Sign-up</a>
    4040                    <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>
    4242                    <a sec:authorize="isAuthenticated()" type="button" class="btn btn-warning" th:href="@{/logout}">Logout</a>
    4343                </div>
Note: See TracChangeset for help on using the changeset viewer.