source: src/main/java/mk/finki/ukim/mk/vehiclerent/service/impl/VoziloServiceImpl.java@ 3965aed

Last change on this file since 3965aed was 3965aed, checked in by lepaSi <86915414+lepaSi@…>, 9 months ago

Init

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package mk.finki.ukim.mk.vehiclerent.service.impl;
2
3import mk.finki.ukim.mk.vehiclerent.generated_model.VozilaEntity;
4import mk.finki.ukim.mk.vehiclerent.model.exceptions.InvalidVoziloIdException;
5import mk.finki.ukim.mk.vehiclerent.repository.VozilaRepository;
6import mk.finki.ukim.mk.vehiclerent.service.VoziloService;
7import org.springframework.stereotype.Service;
8
9import java.math.BigInteger;
10import java.util.List;
11
12@Service
13public class VoziloServiceImpl implements VoziloService {
14 private final VozilaRepository vozilaRepository;
15
16 public VoziloServiceImpl(VozilaRepository vozilaRepository) {
17 this.vozilaRepository = vozilaRepository;
18 }
19
20 @Override
21 public VozilaEntity findById(int id) {
22 return this.vozilaRepository.findById(id).orElseThrow(InvalidVoziloIdException::new);
23 }
24
25 @Override
26 public List<VozilaEntity> listAll() {
27 return this.vozilaRepository.findAll();
28 }
29
30 @Override
31 public VozilaEntity create(Integer idkat, String model, String marka, String regtab, BigInteger cenavozi) {
32 VozilaEntity vozilo = new VozilaEntity(idkat,model,marka,regtab,cenavozi);
33 return this.vozilaRepository.save(vozilo);
34 }
35
36 @Override
37 public VozilaEntity update(int id,Integer idkat, String model, String marka, String regtab, BigInteger cenavozi) {
38 VozilaEntity vozilo = this.vozilaRepository.findById(id).orElseThrow(InvalidVoziloIdException::new);
39
40
41 vozilo.setIdkat(idkat);
42 vozilo.setModel(model);
43 vozilo.setMarka(marka);
44 vozilo.setRegtab(regtab);
45 vozilo.setCenavozi(cenavozi);
46 return this.vozilaRepository.save(vozilo);
47 }
48
49 @Override
50 public VozilaEntity delete(int id) {
51 VozilaEntity vozilo = this.findById(id);
52 this.vozilaRepository.delete(vozilo);
53 return vozilo;
54 }
55}
Note: See TracBrowser for help on using the repository browser.