package com.project.beautycenter.service.impl; import com.project.beautycenter.model.Klienti; import com.project.beautycenter.model.Users; import com.project.beautycenter.repository.KlientiRepository; import com.project.beautycenter.repository.UsersRepository; import com.project.beautycenter.service.KlientiService; import org.springframework.stereotype.Service; import java.util.List; @Service public class KlientiServiceImpl implements KlientiService { private final KlientiRepository klientiRepository; private final UsersRepository usersRepository; public KlientiServiceImpl(KlientiRepository klientiRepository, UsersRepository usersRepository) { this.klientiRepository = klientiRepository; this.usersRepository = usersRepository; } @Override public List listAll() { return this.klientiRepository.findAll(); } @Override public Klienti findById(Integer id) { return this.klientiRepository.findById(id).orElseThrow(NullPointerException::new); } @Override public Klienti delete(Integer id) { Klienti klient = this.findById(id); this.klientiRepository.delete(klient); return klient; } @Override public Klienti create(Users users, String ime, String prezime, String telBr, String email) { Users user = this.usersRepository.getById(users.getId()); Klienti klienti = new Klienti(user, ime, prezime, telBr, email); return this.klientiRepository.save(klienti); } @Override public Klienti update(Integer id, String ime, String prezime, String telBr, String email) { Klienti klienti = this.klientiRepository.findById(id).orElseThrow(NullPointerException::new); klienti.setId(id); klienti.setIme(ime); klienti.setPrezime(prezime); klienti.setTelBr(telBr); klienti.setEMail(email); return this.klientiRepository.save(klienti); } }