source: src/main/java/com/example/medweb/service/impl/TerminServiceImpl.java

Last change on this file was e5fefbd, checked in by Anita Terziska <63020646+Nit4e@…>, 2 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[e5fefbd]1package com.example.medweb.service.impl;
2
3import com.example.medweb.model.Termin;
4import com.example.medweb.model.TerminId;
5import com.example.medweb.model.exceptions.TerminNotValidException;
6import com.example.medweb.repository.TerminRepository;
7import com.example.medweb.repository.TerminRepositoryCustom;
8import com.example.medweb.service.TerminService;
9import org.springframework.beans.factory.annotation.Qualifier;
10import org.springframework.stereotype.Service;
11
12import java.time.ZonedDateTime;
13import java.util.List;
14import java.util.Optional;
15
16
17@Service
18public class TerminServiceImpl implements TerminService {
19
20 @Qualifier("main")
21 private final TerminRepository terminRepository;
22 @Qualifier(value = "custom")
23 private final TerminRepositoryCustom terminRepositoryCustom;
24
25 public TerminServiceImpl(TerminRepository terminRepository, TerminRepositoryCustom terminRepositoryCustom) {
26 this.terminRepository = terminRepository;
27 this.terminRepositoryCustom = terminRepositoryCustom;
28 }
29
30 @Override
31 public Optional<Termin> findTerminById(TerminId terminId) {
32
33 return this.terminRepository.findById(terminId);
34 }
35
36 @Override
37 public List<Termin> findTerminByTermin_id(Integer termin_id) {
38
39 return this.terminRepositoryCustom.findAllByTerminId(termin_id);
40 }
41
42 @Override
43 public Termin findOneTerminByTerminId(Integer termin_id) {
44
45 return this.terminRepositoryCustom.findByTerminId(termin_id);
46 }
47
48 @Override
49 public void save(Termin termin) {
50 if (termin.getVreme().isBefore(ZonedDateTime.now())) {
51 throw new TerminNotValidException();
52 }
53 this.terminRepository.save(termin);
54 }
55
56 @Override
57 public void deleteTermin(Termin termin) {
58
59 this.terminRepository.delete(termin);
60 }
61
62 @Override
63 public List<Termin> findOnlyFutureAndFree(ZonedDateTime now) {
64 return this.terminRepository.findFutureAndFree(now);
65 }
66
67 @Override
68 public List<Termin> findOnlyFutureAndFreeAndByDoktor(ZonedDateTime now, Integer doktor_id) {
69 return this.terminRepository.findFutureAndFreeAndByDoktor(now, doktor_id);
70 }
71}
Note: See TracBrowser for help on using the repository browser.