[850b344] | 1 | package com.project.beautycenter.service.impl;
|
---|
| 2 |
|
---|
| 3 | import com.project.beautycenter.model.Klienti;
|
---|
| 4 | import com.project.beautycenter.model.Users;
|
---|
| 5 | import com.project.beautycenter.repository.KlientiRepository;
|
---|
| 6 | import com.project.beautycenter.repository.UsersRepository;
|
---|
| 7 | import com.project.beautycenter.service.KlientiService;
|
---|
| 8 | import org.springframework.stereotype.Service;
|
---|
| 9 |
|
---|
| 10 | import java.util.List;
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | @Service
|
---|
| 14 | public class KlientiServiceImpl implements KlientiService {
|
---|
| 15 | private final KlientiRepository klientiRepository;
|
---|
| 16 | private final UsersRepository usersRepository;
|
---|
| 17 |
|
---|
| 18 | public KlientiServiceImpl(KlientiRepository klientiRepository, UsersRepository usersRepository) {
|
---|
| 19 | this.klientiRepository = klientiRepository;
|
---|
| 20 | this.usersRepository = usersRepository;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | @Override
|
---|
| 24 | public List<Klienti> listAll() {
|
---|
| 25 | return this.klientiRepository.findAll();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | @Override
|
---|
| 29 | public Klienti findById(Integer id) {
|
---|
| 30 | return this.klientiRepository.findById(id).orElseThrow(NullPointerException::new);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | @Override
|
---|
| 34 | public Klienti delete(Integer id) {
|
---|
| 35 | Klienti klient = this.findById(id);
|
---|
| 36 | this.klientiRepository.delete(klient);
|
---|
| 37 | return klient;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | @Override
|
---|
| 41 | public Klienti create(Users users, String ime, String prezime, String telBr, String email) {
|
---|
| 42 |
|
---|
| 43 | Users user = this.usersRepository.getById(users.getId());
|
---|
| 44 | Klienti klienti = new Klienti(user, ime, prezime, telBr, email);
|
---|
| 45 |
|
---|
| 46 | return this.klientiRepository.save(klienti);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | @Override
|
---|
| 50 | public Klienti update(Integer id, String ime, String prezime, String telBr, String email) {
|
---|
| 51 | Klienti klienti = this.klientiRepository.findById(id).orElseThrow(NullPointerException::new);
|
---|
| 52 | klienti.setId(id);
|
---|
| 53 | klienti.setIme(ime);
|
---|
| 54 | klienti.setPrezime(prezime);
|
---|
| 55 | klienti.setTelBr(telBr);
|
---|
| 56 | klienti.setEMail(email);
|
---|
| 57 | return this.klientiRepository.save(klienti);
|
---|
| 58 | }
|
---|
| 59 | }
|
---|