source: src/main/java/mk/ukim/finki/eglas/services/Impl/CandidatesElectionRealizationServiceImpl.java

main
Last change on this file was ac151d1, checked in by David <darsov2@…>, 4 months ago

initial

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import mk.ukim.finki.eglas.model.CandidatesElectionRealization;
4import mk.ukim.finki.eglas.model.Citizen;
5import mk.ukim.finki.eglas.model.ElectionRealization;
6import mk.ukim.finki.eglas.repository.CandidatesElectionRealizationRepository;
7import mk.ukim.finki.eglas.services.CandidatesElectionRealizationService;
8import mk.ukim.finki.eglas.services.CitizenService;
9import mk.ukim.finki.eglas.services.ElectionRealizationService;
10import org.springframework.beans.factory.annotation.Autowired;
11import org.springframework.stereotype.Service;
12
13import java.util.List;
14
15@Service
16public class CandidatesElectionRealizationServiceImpl implements CandidatesElectionRealizationService {
17
18 private final CandidatesElectionRealizationRepository repository;
19 private final ElectionRealizationService electionRealizationService;
20 @Autowired
21 private CitizenService citizenService;
22
23 CandidatesElectionRealizationServiceImpl(CandidatesElectionRealizationRepository repository,
24 ElectionRealizationService electionRealizationService){
25 this.repository = repository;
26 this.electionRealizationService = electionRealizationService;
27 }
28
29 @Override
30 public CandidatesElectionRealization findById(Long id){
31 return repository.findById(id).orElseThrow(() -> new RuntimeException("No candidate election realization found"));
32 }
33
34 @Override
35 public List<CandidatesElectionRealization> findAll(){
36 return repository.findAll();
37 }
38 @Override
39 public CandidatesElectionRealization update(Long id){
40 CandidatesElectionRealization candidate = (CandidatesElectionRealization) electionRealizationService.findById(id);
41 return repository.save(candidate);
42 }
43 @Override
44 public void delete(Long id){
45 repository.delete(findById(id));
46 }
47
48 @Override
49 public List<CandidatesElectionRealization> findAvailable(Long citizenId) {
50 Citizen citizen = citizenService.findById(citizenId);
51 return repository.availableElections(citizen, citizen.getAddress().getMunicipality());
52 }
53}
Note: See TracBrowser for help on using the repository browser.