Changeset 0c37625 for src/main/java


Ignore:
Timestamp:
10/07/21 20:22:23 (3 years ago)
Author:
NikolaCenevski <cenevskinikola@…>
Branches:
master
Children:
ee0e297
Parents:
276a8b6
Message:

Moderator pagination

Location:
src/main/java/it/finki/charitable
Files:
7 edited

Legend:

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

    r276a8b6 r0c37625  
    127127                        @RequestParam String sort,
    128128                        @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);
    130130        if (postList.getSize() == 0) {
    131131            model.addAttribute("noPosts", true);
     
    204204        reasonService.save(reason);
    205205        reportPost.getReasons().add(reason);
     206        reportPost.setNumReports(reportPost.getNumReports() + 1);
    206207        reportPostService.save(reportPost);
    207208        return String.format("redirect:/post?postid=%d", postid);
  • src/main/java/it/finki/charitable/controller/ModeratorController.java

    r276a8b6 r0c37625  
    66import it.finki.charitable.services.ReasonService;
    77import it.finki.charitable.services.ReportPostService;
     8import org.springframework.data.domain.Page;
    89import org.springframework.security.core.context.SecurityContextHolder;
    910import org.springframework.stereotype.Controller;
     
    3334
    3435    @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) {
    3842            model.addAttribute("noPosts", true);
    3943            return "postApproval";
    4044        }
     45        model.addAttribute("totalPages", postList.getTotalPages());
    4146        model.addAttribute("postList", postList);
    4247        return "postApproval";
     
    9297
    9398    @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) {
    97105            model.addAttribute("noPosts", true);
    98106            return "reportedPosts";
  • src/main/java/it/finki/charitable/entities/ReportPost.java

    r276a8b6 r0c37625  
    22
    33import javax.persistence.*;
     4import java.time.LocalDate;
    45import java.util.ArrayList;
    56import java.util.List;
     
    3233    private List<Reason> reasons = new ArrayList<>();
    3334
     35    private int numReports = 0;
     36
    3437    public Long getId() {
    3538        return id;
     
    5558        this.reasons = reasons;
    5659    }
     60
     61    public int getNumReports() {
     62        return numReports;
     63    }
     64
     65    public void setNumReports(int numReports) {
     66        this.numReports = numReports;
     67    }
    5768}
  • src/main/java/it/finki/charitable/repository/ReportPostRepository.java

    r276a8b6 r0c37625  
    33import it.finki.charitable.entities.DonationPost;
    44import it.finki.charitable.entities.ReportPost;
     5import org.springframework.data.domain.Page;
     6import org.springframework.data.domain.Pageable;
    57import org.springframework.data.jpa.repository.JpaRepository;
    68import org.springframework.stereotype.Repository;
  • src/main/java/it/finki/charitable/security/SecurityConfig.java

    r276a8b6 r0c37625  
    6767        RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
    6868        if(authentication.getAuthorities().toString().contains("MODERATOR")) {
    69             redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/moderator/approval");
     69            redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/moderator/approval?page=1&sort=id");
    7070        } else {
    7171            redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/");
  • src/main/java/it/finki/charitable/services/DonationPostService.java

    r276a8b6 r0c37625  
    5454    }
    5555
    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) {
    5757        Sort s = Sort.by(sort);
    5858        s = order.equals("asc") ? s.ascending() : s.descending();
    5959        Pageable pageable = PageRequest.of(pageNo - 1, pageSize, s);
    60         return donationPostRepository.findAllByApproved(pageable, true);
     60        return donationPostRepository.findAllByApproved(pageable, approved);
    6161    }
    6262}
  • src/main/java/it/finki/charitable/services/ReportPostService.java

    r276a8b6 r0c37625  
    55import it.finki.charitable.entities.ReportPost;
    66import it.finki.charitable.repository.ReportPostRepository;
     7import org.springframework.data.domain.Page;
     8import org.springframework.data.domain.PageRequest;
     9import org.springframework.data.domain.Pageable;
     10import org.springframework.data.domain.Sort;
    711import org.springframework.stereotype.Service;
    812
     
    1822    }
    1923
    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);
    2229    }
    2330
Note: See TracChangeset for help on using the changeset viewer.