source: src/main/java/com/project/beautycenter/service/impl/OcenaServiceImpl.java

Last change on this file was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package com.project.beautycenter.service.impl;
2
3
4import com.project.beautycenter.model.Klienti;
5import com.project.beautycenter.model.Ocena;
6import com.project.beautycenter.model.Rezervacija;
7import com.project.beautycenter.model.Uslugi;
8import com.project.beautycenter.model.exceptions.InvalidOcenaIdException;
9import com.project.beautycenter.repository.OcenaRepository;
10import com.project.beautycenter.repository.UslugiRepository;
11import com.project.beautycenter.service.OcenaService;
12import org.springframework.stereotype.Service;
13
14import java.util.List;
15
16@Service
17public class OcenaServiceImpl implements OcenaService {
18 private final OcenaRepository ocenaRepository;
19 private final UslugiRepository uslugiRepository;
20
21 public OcenaServiceImpl(OcenaRepository ocenaRepository, UslugiRepository uslugiRepository) {
22 this.ocenaRepository = ocenaRepository;
23 this.uslugiRepository = uslugiRepository;
24 }
25
26 @Override
27 public List<Ocena> listAll() {
28 return this.ocenaRepository.findAll();
29 }
30
31 @Override
32 public Ocena findbyId(Integer id) {
33 return this.ocenaRepository.findById(id).orElseThrow(NullPointerException::new);
34 }
35
36 @Override
37 public Ocena delete(Integer id) {
38 Ocena ocena = this.ocenaRepository.findById(id).orElseThrow(InvalidOcenaIdException::new);
39 Uslugi usluga = ocena.getUslugi();
40 List<Ocena> cleared = ocena.getUslugi().removeOcenaOdUsluga(ocena);
41 this.uslugiRepository.save(usluga);
42 this.ocenaRepository.delete(ocena);
43 return ocena;
44 }
45
46 @Override
47 public void rateWithAppointment(Rezervacija brRez, List<Uslugi> uslugi, Integer vrednost, String komentar, Klienti klient) {
48 for (Uslugi usluga : uslugi) {
49 Ocena o = new Ocena(brRez, usluga, vrednost, komentar, klient);
50 this.ocenaRepository.save(o);
51 }
52
53 }
54
55 @Override
56 public List<Ocena> listAllWithBrRezNotNull() {
57 return this.ocenaRepository.getAllByRezervacijaIsNotNull();
58 }
59}
Note: See TracBrowser for help on using the repository browser.