1 | package com.project.beautycenter.service.impl;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.project.beautycenter.model.Klienti;
|
---|
5 | import com.project.beautycenter.model.Ocena;
|
---|
6 | import com.project.beautycenter.model.Rezervacija;
|
---|
7 | import com.project.beautycenter.model.Uslugi;
|
---|
8 | import com.project.beautycenter.model.exceptions.InvalidOcenaIdException;
|
---|
9 | import com.project.beautycenter.repository.OcenaRepository;
|
---|
10 | import com.project.beautycenter.repository.UslugiRepository;
|
---|
11 | import com.project.beautycenter.service.OcenaService;
|
---|
12 | import org.springframework.stereotype.Service;
|
---|
13 |
|
---|
14 | import java.util.List;
|
---|
15 |
|
---|
16 | @Service
|
---|
17 | public 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 | }
|
---|