source: src/main/java/it/finki/charitable/services/DonationPostService.java@ 5306751

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

Dodadeno posts to be approved

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package it.finki.charitable.services;
2
3import it.finki.charitable.entities.AppUser;
4import it.finki.charitable.entities.DonationPost;
5import it.finki.charitable.repository.DonationPostRepository;
6import org.springframework.data.domain.Page;
7import org.springframework.data.domain.PageRequest;
8import org.springframework.data.domain.Pageable;
9import org.springframework.data.domain.Sort;
10import org.springframework.stereotype.Service;
11
12import java.util.List;
13
14@Service
15public class DonationPostService {
16
17 private final DonationPostRepository donationPostRepository;
18
19 public DonationPostService(DonationPostRepository donationPostRepository) {
20 this.donationPostRepository = donationPostRepository;
21 }
22
23 public DonationPost save(DonationPost donationPost) {
24 return donationPostRepository.save(donationPost);
25 }
26
27 public DonationPost getById(Long id) {
28 if(donationPostRepository.existsById(id)) {
29 return donationPostRepository.getById(id);
30 }
31
32 return null;
33 }
34
35 public List<DonationPost> findAll() {
36 return donationPostRepository.findAll();
37 }
38
39 public List<DonationPost> findAllByUser(AppUser user) {
40 return donationPostRepository.findAllByUser(user);
41 }
42
43 public List<DonationPost> findAllByApproved(Boolean approved) {
44 return donationPostRepository.findAllByApproved(approved);
45 }
46
47 public void delete(DonationPost donationPost) {
48 donationPostRepository.delete(donationPost);
49 }
50
51 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort) {
52 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(sort));
53 return donationPostRepository.findAll(pageable);
54 }
55}
Note: See TracBrowser for help on using the repository browser.