source: src/main/java/com/example/baza/service/impl/KaznaServiceImpl.java

Last change on this file was ed20c2c, checked in by HumaSejdini <humasejdini12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package com.example.baza.service.impl;
2
3
4import com.example.baza.model.Chlen2;
5import com.example.baza.model.Kazna;
6import com.example.baza.model.Pozajmica;
7import com.example.baza.model.exception.InvalidKaznaIdException;
8import com.example.baza.repository.KaznaRepository;
9import com.example.baza.service.KaznaService;
10import org.springframework.stereotype.Service;
11
12import java.time.LocalDate;
13import java.util.List;
14
15@Service
16public 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}
Note: See TracBrowser for help on using the repository browser.