source: src/main/java/mk/ukim/finki/eglas/services/Impl/ElectionRealizationServiceImpl.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: 3.8 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import jakarta.transaction.Transactional;
4import mk.ukim.finki.eglas.model.Election;
5import mk.ukim.finki.eglas.model.ElectionRealization;
6import mk.ukim.finki.eglas.repository.CandidatesElectionRealizationRepository;
7import mk.ukim.finki.eglas.repository.CandidatesListElectionRealizationRepository;
8import mk.ukim.finki.eglas.repository.ElectionRealizationRepository;
9import mk.ukim.finki.eglas.services.CitizenService;
10import mk.ukim.finki.eglas.services.ElectionRealizationService;
11import mk.ukim.finki.eglas.services.ElectionService;
12import mk.ukim.finki.eglas.services.VoteIdentificationCodeService;
13import org.springframework.stereotype.Service;
14
15import java.time.LocalDate;
16import java.util.List;
17
18@Service
19public class ElectionRealizationServiceImpl implements ElectionRealizationService {
20 private final ElectionRealizationRepository electionRealizationRepository;
21 private final CandidatesListElectionRealizationRepository candidatesListElectionRealizationRepository;
22 private final CandidatesElectionRealizationRepository candidatesElectionRealizationRepository;
23 private final ElectionService electionService;
24 private final VoteIdentificationCodeService voteIdentificationCodeService;
25 private final CitizenService citizenService;
26
27 public ElectionRealizationServiceImpl(ElectionRealizationRepository electionRealizationRepository, CandidatesListElectionRealizationRepository candidatesListElectionRealizationRepository, CandidatesElectionRealizationRepository candidatesElectionRealizationRepository, ElectionService electionService, VoteIdentificationCodeService voteIdentificationCodeService, CitizenService citizenService) {
28 this.electionRealizationRepository = electionRealizationRepository;
29 this.candidatesListElectionRealizationRepository = candidatesListElectionRealizationRepository;
30 this.candidatesElectionRealizationRepository = candidatesElectionRealizationRepository;
31 this.electionService = electionService;
32 this.voteIdentificationCodeService = voteIdentificationCodeService;
33 this.citizenService = citizenService;
34 }
35
36 @Override
37 public List<ElectionRealization> findAll() {
38 return electionRealizationRepository.findAll();
39 }
40
41 @Override
42 public ElectionRealization findById(Long id) {
43 return electionRealizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Election Realization not found"));
44 }
45
46 @Override
47 @Transactional
48 public ElectionRealization update(Long id, LocalDate date, String name, Long electionId, String candidacyRealization, String candidatesListRealization) {
49 Election election = electionService.findById(electionId);
50 ElectionRealization electionRealization = new ElectionRealization();
51 if(id != null)
52 {
53 electionRealization = findById(id);
54 }
55 electionRealization.setElection(election);
56 electionRealization.setName(name);
57 electionRealization.setDate(date);
58 electionRealization = electionRealizationRepository.save(electionRealization);
59 if(candidacyRealization != null)
60 {
61 candidatesElectionRealizationRepository.insertCandidacyElections(electionRealization.getId());
62 }
63 if(candidatesListRealization != null)
64 {
65 candidatesListElectionRealizationRepository.insertCandidateListElections(electionRealization.getId());
66 }
67
68 voteIdentificationCodeService.generateCodes(citizenService.availableVoters(), date.atTime(23, 59, 59));
69
70 return electionRealization;
71 }
72
73 @Override
74 public ElectionRealization delete(Long id) {
75 ElectionRealization electionRealization = findById(id);
76 electionRealizationRepository.delete(electionRealization);
77 return electionRealization;
78 }
79}
Note: See TracBrowser for help on using the repository browser.