1 | package mk.ukim.finki.busngo.service.impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.busngo.model.entities.Kaznazaneregistriran;
|
---|
4 | import mk.ukim.finki.busngo.model.entities.Kondukter;
|
---|
5 | import mk.ukim.finki.busngo.model.entities.Kontroli;
|
---|
6 | import mk.ukim.finki.busngo.repository.KaznaZaNeregistriranRepository;
|
---|
7 | import mk.ukim.finki.busngo.service.KaznaZaNeregistriranService;
|
---|
8 | import mk.ukim.finki.busngo.service.KondukterService;
|
---|
9 | import mk.ukim.finki.busngo.service.KontrolaService;
|
---|
10 | import org.springframework.stereotype.Service;
|
---|
11 |
|
---|
12 | import java.sql.Timestamp;
|
---|
13 | import java.time.LocalDateTime;
|
---|
14 | import java.util.List;
|
---|
15 | @Service
|
---|
16 | public class KaznaZaNeregistriranServiceImpl implements KaznaZaNeregistriranService {
|
---|
17 | private final KaznaZaNeregistriranRepository kaznaZaNeregistriranRepository;
|
---|
18 | private final KontrolaService kontrolaService;
|
---|
19 | private final KondukterService kondukterService;
|
---|
20 |
|
---|
21 | public KaznaZaNeregistriranServiceImpl(KaznaZaNeregistriranRepository kaznaZaNeregistriranRepository, KontrolaService kontrolaService, KondukterService kondukterService) {
|
---|
22 | this.kaznaZaNeregistriranRepository = kaznaZaNeregistriranRepository;
|
---|
23 | this.kontrolaService = kontrolaService;
|
---|
24 | this.kondukterService = kondukterService;
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public List<Kaznazaneregistriran> findAll() {
|
---|
29 | return kaznaZaNeregistriranRepository.findAll();
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public Kaznazaneregistriran findById(Long id) {
|
---|
34 | return kaznaZaNeregistriranRepository.findById(id).orElseThrow(RuntimeException::new);
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public Kaznazaneregistriran create(Long kontrolaId, String dokument, Double iznos, String telefon, String ime, String adresa, String email) {
|
---|
39 | Kondukter byEmail = kondukterService.findByEmail(email);
|
---|
40 | Kontroli kontroli = kontrolaService.findById(kontrolaId);
|
---|
41 | Kaznazaneregistriran kaznazaneregistriran = new Kaznazaneregistriran();
|
---|
42 | kaznazaneregistriran.setKznAdresa(adresa);
|
---|
43 | kaznazaneregistriran.setKznIme(ime);
|
---|
44 | kaznazaneregistriran.setKznTelefon(telefon);
|
---|
45 | kaznazaneregistriran.setKzDatum(Timestamp.valueOf(LocalDateTime.now()));
|
---|
46 | kaznazaneregistriran.setKontroliByKontrolaId(kontroli);
|
---|
47 | kaznazaneregistriran.setKorisnikByKondukterKId(byEmail);
|
---|
48 | kaznazaneregistriran.setKzIznos(iznos);
|
---|
49 | kaznazaneregistriran.setKzDokument(dokument);
|
---|
50 | kaznazaneregistriran.setKzPlateno(false);
|
---|
51 | return kaznaZaNeregistriranRepository.save(kaznazaneregistriran);
|
---|
52 | }
|
---|
53 | }
|
---|