1 | package mk.ukim.finki.busngo.service.impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.busngo.model.entities.Kazna;
|
---|
4 | import mk.ukim.finki.busngo.model.entities.Kontroli;
|
---|
5 | import mk.ukim.finki.busngo.repository.KaznaRepository;
|
---|
6 | import mk.ukim.finki.busngo.service.KaznaService;
|
---|
7 | import mk.ukim.finki.busngo.service.KontrolaService;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | import java.sql.Timestamp;
|
---|
11 | import java.time.LocalDateTime;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | @Service
|
---|
15 | public 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 | }
|
---|