Changeset 0c37625 for src/main/java
- Timestamp:
- 10/07/21 20:22:23 (3 years ago)
- Branches:
- master
- Children:
- ee0e297
- Parents:
- 276a8b6
- 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 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
Note:
See TracChangeset
for help on using the changeset viewer.