source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/service/impl/KaznaZaNeregistriranServiceImpl.java

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 2.4 KB
Line 
1package mk.ukim.finki.busngo.service.impl;
2
3import mk.ukim.finki.busngo.model.entities.Kaznazaneregistriran;
4import mk.ukim.finki.busngo.model.entities.Kondukter;
5import mk.ukim.finki.busngo.model.entities.Kontroli;
6import mk.ukim.finki.busngo.repository.KaznaZaNeregistriranRepository;
7import mk.ukim.finki.busngo.service.KaznaZaNeregistriranService;
8import mk.ukim.finki.busngo.service.KondukterService;
9import mk.ukim.finki.busngo.service.KontrolaService;
10import org.springframework.stereotype.Service;
11
12import java.sql.Timestamp;
13import java.time.LocalDateTime;
14import java.util.List;
15@Service
16public 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}
Note: See TracBrowser for help on using the repository browser.