source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/service/impl/KontrolaServiceImpl.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.1 KB
Line 
1package mk.ukim.finki.busngo.service.impl;
2
3import mk.ukim.finki.busngo.model.entities.Instancanalinija;
4import mk.ukim.finki.busngo.model.entities.Kondukter;
5import mk.ukim.finki.busngo.model.entities.Kontroli;
6import mk.ukim.finki.busngo.repository.KontrolaRepository;
7import mk.ukim.finki.busngo.service.InstancaNaLinijaService;
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
16@Service
17public 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}
Note: See TracBrowser for help on using the repository browser.