1 | package mk.ukim.finki.busngo.service.impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.busngo.model.entities.Instancanalinija;
|
---|
4 | import mk.ukim.finki.busngo.model.entities.Korisnik;
|
---|
5 | import mk.ukim.finki.busngo.model.entities.Patnik;
|
---|
6 | import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
|
---|
7 | import mk.ukim.finki.busngo.repository.PatnikRepository;
|
---|
8 | import mk.ukim.finki.busngo.service.InstancaNaLinijaService;
|
---|
9 | import mk.ukim.finki.busngo.service.PatnikService;
|
---|
10 | import org.springframework.stereotype.Service;
|
---|
11 |
|
---|
12 | import java.util.Collections;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | @Service
|
---|
16 | public class PatnikServiceImpl implements PatnikService {
|
---|
17 | private final PatnikRepository patnikRepository;
|
---|
18 | private final InstancaNaLinijaService instancaNaLinijaService;
|
---|
19 |
|
---|
20 | public PatnikServiceImpl(PatnikRepository patnikRepository, InstancaNaLinijaService instancaNaLinijaService) {
|
---|
21 | this.patnikRepository = patnikRepository;
|
---|
22 | this.instancaNaLinijaService = instancaNaLinijaService;
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | public List<Patnik> listAll() {
|
---|
27 | return patnikRepository.findAll();
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public Patnik findById(Long id) {
|
---|
32 | return patnikRepository.findById(id).orElseThrow(InvalidPatnikIdException::new);
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public Patnik loadUserByEmail(String email) {
|
---|
37 | return patnikRepository.findByKEmail(email).orElseThrow(InvalidPatnikIdException::new);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public Patnik save(Korisnik korisnik) {
|
---|
42 | Patnik patnik = new Patnik();
|
---|
43 | patnik.setKId(korisnik.getKId());
|
---|
44 | patnik.setKEmail(korisnik.getKEmail());
|
---|
45 | patnik.setKAdresa(korisnik.getKAdresa());
|
---|
46 | patnik.setKIme(korisnik.getKIme());
|
---|
47 | patnik.setKTelefon(korisnik.getKTelefon());
|
---|
48 | patnik.setKIsAdmin(korisnik.getKIsAdmin());
|
---|
49 | patnik.setKLozinka(korisnik.getKLozinka());
|
---|
50 |
|
---|
51 | return patnikRepository.save((Patnik) korisnik);
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | }
|
---|