source: src/main/java/com/project/beautycenter/service/impl/KlientiServiceImpl.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: 1.9 KB
Line 
1package com.project.beautycenter.service.impl;
2
3import com.project.beautycenter.model.Klienti;
4import com.project.beautycenter.model.Users;
5import com.project.beautycenter.repository.KlientiRepository;
6import com.project.beautycenter.repository.UsersRepository;
7import com.project.beautycenter.service.KlientiService;
8import org.springframework.stereotype.Service;
9
10import java.util.List;
11
12
13@Service
14public 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}
Note: See TracBrowser for help on using the repository browser.