package com.project.beautycenter.service.impl; import com.project.beautycenter.model.Klienti; import com.project.beautycenter.model.Ocena; import com.project.beautycenter.model.Rezervacija; import com.project.beautycenter.model.Uslugi; import com.project.beautycenter.model.exceptions.InvalidOcenaIdException; import com.project.beautycenter.repository.OcenaRepository; import com.project.beautycenter.repository.UslugiRepository; import com.project.beautycenter.service.OcenaService; import org.springframework.stereotype.Service; import java.util.List; @Service public class OcenaServiceImpl implements OcenaService { private final OcenaRepository ocenaRepository; private final UslugiRepository uslugiRepository; public OcenaServiceImpl(OcenaRepository ocenaRepository, UslugiRepository uslugiRepository) { this.ocenaRepository = ocenaRepository; this.uslugiRepository = uslugiRepository; } @Override public List listAll() { return this.ocenaRepository.findAll(); } @Override public Ocena findbyId(Integer id) { return this.ocenaRepository.findById(id).orElseThrow(NullPointerException::new); } @Override public Ocena delete(Integer id) { Ocena ocena = this.ocenaRepository.findById(id).orElseThrow(InvalidOcenaIdException::new); Uslugi usluga = ocena.getUslugi(); List cleared = ocena.getUslugi().removeOcenaOdUsluga(ocena); this.uslugiRepository.save(usluga); this.ocenaRepository.delete(ocena); return ocena; } @Override public void rateWithAppointment(Rezervacija brRez, List uslugi, Integer vrednost, String komentar, Klienti klient) { for (Uslugi usluga : uslugi) { Ocena o = new Ocena(brRez, usluga, vrednost, komentar, klient); this.ocenaRepository.save(o); } } @Override public List listAllWithBrRezNotNull() { return this.ocenaRepository.getAllByRezervacijaIsNotNull(); } }