source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/service/impl/InstancaNaLinijaServiceImpl.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: 3.0 KB
Line 
1package mk.ukim.finki.busngo.service.impl;
2
3import mk.ukim.finki.busngo.model.entities.*;
4import mk.ukim.finki.busngo.model.exceptions.InvalidInstancaNaLinijaIdException;
5import mk.ukim.finki.busngo.repository.InstancaNaLinijaRepository;
6import mk.ukim.finki.busngo.service.*;
7import org.springframework.stereotype.Service;
8
9import java.sql.Timestamp;
10import java.time.LocalDateTime;
11import java.util.List;
12
13@Service
14public class InstancaNaLinijaServiceImpl implements InstancaNaLinijaService{
15 private final InstancaNaLinijaRepository instancaNaLinijaRepository;
16 private final VozacService vozacService;
17 private final AvtobusService avtobusService;
18 private final LinijaService linijaService;
19 private final PostojkaNaLinijaService postojkaNaLinijaService;
20
21 public InstancaNaLinijaServiceImpl(InstancaNaLinijaRepository instancaNaLinijaRepository, VozacService vozacService, AvtobusService avtobusService, LinijaService linijaService, PostojkaNaLinijaService postojkaNaLinijaService) {
22 this.instancaNaLinijaRepository = instancaNaLinijaRepository;
23 this.vozacService = vozacService;
24 this.avtobusService = avtobusService;
25 this.linijaService = linijaService;
26 this.postojkaNaLinijaService = postojkaNaLinijaService;
27 }
28
29 @Override
30 public List<Instancanalinija> findAll() {
31 return instancaNaLinijaRepository.findAll();
32 }
33
34 @Override
35 public Instancanalinija findById(Long inlId) {
36 return instancaNaLinijaRepository.findById(inlId).orElseThrow(InvalidInstancaNaLinijaIdException::new);
37 }
38
39 @Override
40 public Instancanalinija start(Long liId, String a_registracija, String email) {
41 Linija linija = linijaService.findById(liId);
42 Avtobus avtobus = avtobusService.findById(a_registracija);
43 Vozac vozac = vozacService.findByEmail(email);
44 Instancanalinija instancanalinija = new Instancanalinija();
45 instancanalinija.setLinijaByLiId(linija);
46 instancanalinija.setAvtobusByARegistracija(avtobus);
47 instancanalinija.setKorisnikByVozacKId(vozac);
48 instancanalinija.setInlDatumStart(Timestamp.valueOf(LocalDateTime.now()));
49
50 return instancaNaLinijaRepository.save(instancanalinija);
51 }
52
53 @Override
54 public Instancanalinija end(Long inlId, String email) {
55 Vozac vozac = vozacService.findByEmail(email);
56 Instancanalinija instancanalinija = this.findById(inlId);
57 instancanalinija.setInlDatumEnd(Timestamp.valueOf(LocalDateTime.now()));
58 return instancaNaLinijaRepository.save(instancanalinija);
59 }
60
61 @Override
62 public List<Instancanalinija> findAllActive() {
63 return instancaNaLinijaRepository.findAllByInlDatumEndIsNull();
64 }
65
66 @Override
67 public List<Instancanalinija> findByPnlId(Long pnlId) {
68 Postojkanalinija postojkanalinija = postojkaNaLinijaService.findById(pnlId);
69 Linija linijaByLiId = postojkanalinija.getLinijaByLiId();
70 return instancaNaLinijaRepository.findAllByLinijaByLiIdAndInlDatumEndIsNull(linijaByLiId);
71 }
72}
Note: See TracBrowser for help on using the repository browser.