source: src/main/java/it/finki/charitable/services/ReportPostService.java@ 7888b17

Last change on this file since 7888b17 was 0c37625, checked in by NikolaCenevski <cenevskinikola@…>, 3 years ago

Moderator pagination

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package it.finki.charitable.services;
2
3import it.finki.charitable.entities.DonationPost;
4import it.finki.charitable.entities.Reason;
5import it.finki.charitable.entities.ReportPost;
6import 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;
11import org.springframework.stereotype.Service;
12
13import java.util.List;
14
15@Service
16public class ReportPostService {
17
18 private final ReportPostRepository reportPostRepository;
19
20 public ReportPostService(ReportPostRepository reportPostRepository) {
21 this.reportPostRepository = reportPostRepository;
22 }
23
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);
29 }
30
31 public ReportPost findById(Long id) {
32 return reportPostRepository.getById(id);
33 }
34
35 public ReportPost findByDonationPost(DonationPost post) {
36 return reportPostRepository.findByDonationPost(post);
37 }
38
39 public void save(ReportPost post) {
40 reportPostRepository.save(post);
41 }
42
43 public void delete(ReportPost reportPost) {
44 reportPostRepository.delete(reportPost);
45 }
46}
Note: See TracBrowser for help on using the repository browser.