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

Last change on this file since 0f4f552 was ab49338, checked in by KostaFortumanov <kfortumanov@…>, 3 years ago

Dodadeno prijavuvanje na objavi

  • Property mode set to 100644
File size: 1.9 KB
Line 
1package it.finki.charitable.services;
2
3import it.finki.charitable.entities.AppUser;
4import it.finki.charitable.entities.DonationPost;
5import it.finki.charitable.entities.Moderator;
6import it.finki.charitable.repository.DonationPostRepository;
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 DonationPostService {
17
18 private final DonationPostRepository donationPostRepository;
19
20 public DonationPostService(DonationPostRepository donationPostRepository) {
21 this.donationPostRepository = donationPostRepository;
22 }
23
24 public DonationPost save(DonationPost donationPost) {
25 return donationPostRepository.save(donationPost);
26 }
27
28 public DonationPost getById(Long id) {
29 if(donationPostRepository.existsById(id)) {
30 return donationPostRepository.getById(id);
31 }
32
33 return null;
34 }
35
36 public List<DonationPost> findAll() {
37 return donationPostRepository.findAll();
38 }
39
40 public List<DonationPost> findAllByUser(AppUser user) {
41 return donationPostRepository.findAllByUser(user);
42 }
43
44 public List<DonationPost> findAllByApproved(Boolean approved) {
45 return donationPostRepository.findAllByApproved(approved);
46 }
47
48 public List<DonationPost> findAllByModerator(Moderator moderator) {
49 return donationPostRepository.findAllByModerator(moderator);
50 }
51
52 public void delete(DonationPost donationPost) {
53 donationPostRepository.delete(donationPost);
54 }
55
56 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort) {
57 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(sort));
58 return donationPostRepository.findAll(pageable);
59 }
60}
Note: See TracBrowser for help on using the repository browser.