[e5fefbd] | 1 | package com.example.medweb.service.impl;
|
---|
| 2 |
|
---|
| 3 | import com.example.medweb.model.Termin;
|
---|
| 4 | import com.example.medweb.model.TerminId;
|
---|
| 5 | import com.example.medweb.model.exceptions.TerminNotValidException;
|
---|
| 6 | import com.example.medweb.repository.TerminRepository;
|
---|
| 7 | import com.example.medweb.repository.TerminRepositoryCustom;
|
---|
| 8 | import com.example.medweb.service.TerminService;
|
---|
| 9 | import org.springframework.beans.factory.annotation.Qualifier;
|
---|
| 10 | import org.springframework.stereotype.Service;
|
---|
| 11 |
|
---|
| 12 | import java.time.ZonedDateTime;
|
---|
| 13 | import java.util.List;
|
---|
| 14 | import java.util.Optional;
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | @Service
|
---|
| 18 | public 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 | }
|
---|