source: src/main/java/com/project/beautycenter/service/impl/TerminiServiceImpl.java

Last change on this file was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[850b344]1package com.project.beautycenter.service.impl;
2
3import com.project.beautycenter.model.Termini;
4import com.project.beautycenter.model.Vraboteni;
5import com.project.beautycenter.model.exceptions.InvalidTerminIdException;
6import com.project.beautycenter.repository.TerminiRepository;
7import com.project.beautycenter.repository.VraboteniRepository;
8import com.project.beautycenter.service.TerminiService;
9import org.springframework.stereotype.Service;
10
11import java.time.Instant;
12import java.util.List;
13
14@Service
15public class TerminiServiceImpl implements TerminiService {
16
17 private final TerminiRepository terminiRepository;
18 private final VraboteniRepository vraboteniRepository;
19
20 public TerminiServiceImpl(TerminiRepository terminiRepository, VraboteniRepository vraboteniRepository) {
21 this.terminiRepository = terminiRepository;
22 this.vraboteniRepository = vraboteniRepository;
23 }
24
25 @Override
26 public List<Termini> findAll() {
27 return this.terminiRepository.findAll();
28 }
29
30 @Override
31 public Termini findbyId(Integer id) {
32 return this.terminiRepository.findById(id).orElseThrow(NullPointerException::new);
33 }
34
35 public Termini create(Instant pocetok, Integer vremetraenje, Integer vrabotenId) {
36 Vraboteni vraboten = this.vraboteniRepository.getById(vrabotenId);
37 Termini termin = new Termini(pocetok, vremetraenje, vraboten);
38 return this.terminiRepository.save(termin);
39 }
40
41 @Override
42 public Termini update(Integer id, Instant pocetok, Integer vremetraenje, Integer vrabotenId) {
43 Termini termini = this.terminiRepository.findById(id).orElseThrow(InvalidTerminIdException::new);
44 Vraboteni vraboten = this.vraboteniRepository.getById(vrabotenId);
45 termini.setPocetok(pocetok);
46 termini.setVremetraenje(vremetraenje);
47 termini.setVraboteni(vraboten);
48 return this.terminiRepository.save(termini);
49 }
50
51 @Override
52 public Termini delete(Integer id) {
53 Termini termini = this.terminiRepository.findById(id).orElseThrow(InvalidTerminIdException::new);
54 this.terminiRepository.delete(termini);
55 return termini;
56 }
57
58 @Override
59 public List<Termini> listAllNotReserved() {
60 return this.terminiRepository.findAllByRezervacijasNull();
61 }
62
63}
Note: See TracBrowser for help on using the repository browser.