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.Kondukter;
|
---|
5 | import mk.ukim.finki.busngo.model.entities.Kontroli;
|
---|
6 | import mk.ukim.finki.busngo.repository.KontrolaRepository;
|
---|
7 | import mk.ukim.finki.busngo.service.InstancaNaLinijaService;
|
---|
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 |
|
---|
16 | @Service
|
---|
17 | public class KontrolaServiceImpl implements KontrolaService {
|
---|
18 | private final KontrolaRepository kontrolaRepository;
|
---|
19 | private final KondukterService kondukterService;
|
---|
20 | private final InstancaNaLinijaService instancaNaLinijaService;
|
---|
21 |
|
---|
22 | public KontrolaServiceImpl(KontrolaRepository kontrolaRepository, KondukterService kondukterService, InstancaNaLinijaService instancaNaLinijaService) {
|
---|
23 | this.kontrolaRepository = kontrolaRepository;
|
---|
24 | this.kondukterService = kondukterService;
|
---|
25 | this.instancaNaLinijaService = instancaNaLinijaService;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public List<Kontroli> findAll() {
|
---|
30 | return kontrolaRepository.findAll();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public Kontroli create(Long inlId, String email) {
|
---|
35 | Kondukter kondukter = kondukterService.findByEmail(email);
|
---|
36 | Instancanalinija instancanalinija = instancaNaLinijaService.findById(inlId);
|
---|
37 | Kontroli kontroli = new Kontroli();
|
---|
38 | kontroli.setKontrolaDatum(Timestamp.valueOf(LocalDateTime.now()));
|
---|
39 | kontroli.setKorisnikByKondukterKId(kondukter);
|
---|
40 | kontroli.setInstancanalinijaByInlId(instancanalinija);
|
---|
41 |
|
---|
42 | return kontrolaRepository.save(kontroli);
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public Kontroli findById(Long kontrolaId) {
|
---|
47 | return kontrolaRepository.findById(kontrolaId).orElseThrow(RuntimeException::new);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public List<Kontroli> findAllByInl(Long inlId) {
|
---|
52 | Instancanalinija instancanalinija = instancaNaLinijaService.findById(inlId);
|
---|
53 | return kontrolaRepository.findAllByInstancanalinijaByInlId(instancanalinija);
|
---|
54 | }
|
---|
55 | }
|
---|