1 | package com.example.baza.service.impl;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.example.baza.model.Chlen2;
|
---|
5 | import com.example.baza.model.Kazna;
|
---|
6 | import com.example.baza.model.Pozajmica;
|
---|
7 | import com.example.baza.model.exception.InvalidKaznaIdException;
|
---|
8 | import com.example.baza.repository.KaznaRepository;
|
---|
9 | import com.example.baza.service.KaznaService;
|
---|
10 | import org.springframework.stereotype.Service;
|
---|
11 |
|
---|
12 | import java.time.LocalDate;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | @Service
|
---|
16 | public class KaznaServiceImpl implements KaznaService {
|
---|
17 | private final KaznaRepository kaznaRepository;
|
---|
18 |
|
---|
19 | public KaznaServiceImpl(KaznaRepository kaznaRepository) {
|
---|
20 | this.kaznaRepository = kaznaRepository;
|
---|
21 | }
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public Kazna findById(Integer id) {
|
---|
25 | return this.kaznaRepository.findById(id).orElseThrow(InvalidKaznaIdException::new);
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public List<Kazna> listAll() {
|
---|
30 | return this.kaznaRepository.findAll();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public Kazna create(LocalDate datum, Double cenaVoDenari, Pozajmica pozajmica, Chlen2 chlen) {
|
---|
35 | return this.kaznaRepository.save(new Kazna(datum,cenaVoDenari,pozajmica,chlen));
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public Kazna deleteId(Integer id) {
|
---|
40 | Kazna kazna=this.findById(id);
|
---|
41 | this.kaznaRepository.deleteById(id);
|
---|
42 | return kazna;
|
---|
43 | }
|
---|
44 | }
|
---|