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

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

prototip part1

  • Property mode set to 100644
File size: 1.6 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 void delete(DonationPost donationPost) {
44 donationPostRepository.delete(donationPost);
45 }
46
47 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort) {
48 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(sort));
49 return donationPostRepository.findAll(pageable);
50 }
51}
Note: See TracBrowser for help on using the repository browser.