[ab49338] | 1 | package it.finki.charitable.services;
|
---|
| 2 |
|
---|
| 3 | import it.finki.charitable.entities.DonationPost;
|
---|
| 4 | import it.finki.charitable.entities.Reason;
|
---|
| 5 | import it.finki.charitable.entities.ReportPost;
|
---|
| 6 | import it.finki.charitable.repository.ReportPostRepository;
|
---|
[0c37625] | 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;
|
---|
[ab49338] | 11 | import org.springframework.stereotype.Service;
|
---|
| 12 |
|
---|
| 13 | import java.util.List;
|
---|
| 14 |
|
---|
| 15 | @Service
|
---|
| 16 | public class ReportPostService {
|
---|
| 17 |
|
---|
| 18 | private final ReportPostRepository reportPostRepository;
|
---|
| 19 |
|
---|
| 20 | public ReportPostService(ReportPostRepository reportPostRepository) {
|
---|
| 21 | this.reportPostRepository = reportPostRepository;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[0c37625] | 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);
|
---|
[ab49338] | 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 | }
|
---|