source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/service/impl/KaznaServiceImpl.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: 1.5 KB
Line 
1package mk.ukim.finki.busngo.service.impl;
2
3import mk.ukim.finki.busngo.model.entities.Kazna;
4import mk.ukim.finki.busngo.model.entities.Kontroli;
5import mk.ukim.finki.busngo.repository.KaznaRepository;
6import mk.ukim.finki.busngo.service.KaznaService;
7import mk.ukim.finki.busngo.service.KontrolaService;
8import org.springframework.stereotype.Service;
9
10import java.sql.Timestamp;
11import java.time.LocalDateTime;
12import java.util.List;
13
14@Service
15public class KaznaServiceImpl implements KaznaService {
16 private final KaznaRepository kaznaRepository;
17 private final KontrolaService kontrolaService;
18
19 public KaznaServiceImpl(KaznaRepository kaznaRepository, KontrolaService kontrolaService) {
20 this.kaznaRepository = kaznaRepository;
21 this.kontrolaService = kontrolaService;
22 }
23
24 @Override
25 public List<Kazna> findAll() {
26 return kaznaRepository.findAll();
27 }
28
29 @Override
30 public List<Kazna> findAllByKontrolaId(Long kontrolaId) {
31 Kontroli kontroli = kontrolaService.findById(kontrolaId);
32 return kaznaRepository.findAllByKontroliByKontrolaId(kontroli);
33 }
34
35 @Override
36 public Kazna pay(Long kaznaId) {
37 Kazna kazna = this.findById(kaznaId);
38 kazna.setKzPlateno(true);
39 kazna.setKzDatumPlateno(Timestamp.valueOf(LocalDateTime.now()));
40 return kaznaRepository.save(kazna);
41 }
42
43 @Override
44 public Kazna findById(Long id) {
45 return kaznaRepository.findById(id).orElseThrow(RuntimeException::new);
46 }
47}
Note: See TracBrowser for help on using the repository browser.