source: src/main/java/mk/ukim/finki/eglas/services/Impl/VoteServiceImpl.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.7 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import jakarta.transaction.Transactional;
4import mk.ukim.finki.eglas.model.*;
5import mk.ukim.finki.eglas.repository.CandidacyVoteRepository;
6import mk.ukim.finki.eglas.repository.VoteRepository;
7import mk.ukim.finki.eglas.services.*;
8import org.springframework.stereotype.Service;
9
10import java.time.LocalDateTime;
11import java.util.UUID;
12
13@Service
14public class VoteServiceImpl implements VoteService {
15
16 private final VoteRepository voteRepository;
17 private final TurnoutService turnoutService;
18 private final CandidacyVoteRepository candidacyVoteRepository;
19 private final AddressService addressService;
20 private final VoteIdentificationCodeService voteIdentificationCodeService;
21 private final ElectionRealizationService electionRealizationService;
22 private final CandidacyService candidacyService;
23 private final CitizenService citizenService;
24
25 public VoteServiceImpl(VoteRepository voteRepository, CandidacyVoteService candidacyVoteService, TurnoutService turnoutService, AddressService addressService, CandidatesElectionRealizationService candidatesElectionRealizationService, CandidacyVoteRepository candidacyVoteRepository, VoteIdentificationCodeService voteIdentificationCodeService, ElectionRealizationService electionRealizationService, CandidacyService candidacyService, CitizenService citizenService) {
26 this.voteRepository = voteRepository;
27 this.turnoutService = turnoutService;
28 this.addressService = addressService;
29 this.candidacyVoteRepository = candidacyVoteRepository;
30 this.voteIdentificationCodeService = voteIdentificationCodeService;
31 this.electionRealizationService = electionRealizationService;
32 this.candidacyService = candidacyService;
33 this.citizenService = citizenService;
34 }
35
36 @Override
37 public Vote vote(UUID voteIdentificationCodeId, Long pollingStationId, Long realizationId) {
38 PollingStation pollingStation = addressService.findPollingStationById(pollingStationId);
39 VoteIdentificationCode voteIdentificationCode = voteIdentificationCodeService.findById(voteIdentificationCodeId);
40 ElectionRealization electionRealization = electionRealizationService.findById(realizationId);
41
42 Vote vote = new Vote();
43 vote.setVoteTimestamp(LocalDateTime.now());
44 vote.setPollingStation(pollingStation);
45 vote.setVoteIdentificationCode(voteIdentificationCode);
46 vote.setElectionRealization(electionRealization);
47
48 return voteRepository.save(vote);
49 }
50
51 @Override
52 @Transactional
53 public CandidacyVote voteForCandidate(Long citizenId, UUID voteIdentificationCodeId, Long realizationId, Long id){
54
55 Candidacy candidacy = candidacyService.findById(id);
56 VoteIdentificationCode voteIdentificationCode = voteIdentificationCodeService.findById(voteIdentificationCodeId);
57 ElectionRealization electionRealization = electionRealizationService.findById(realizationId);
58 Citizen citizen = citizenService.findById(citizenId);
59 PollingStation pollingStation = citizen.getAddress().getPollingStation();
60 CandidacyVote candidacyVote = new CandidacyVote();
61 candidacyVote.setVoteTimestamp(LocalDateTime.now());
62 candidacyVote.setVoteIdentificationCode(voteIdentificationCode);
63 candidacyVote.setElectionRealization(electionRealization);
64 candidacyVote.setPollingStation(pollingStation);
65 candidacyVote.pollingStation = pollingStation;
66 candidacyVote.setCandidacy(candidacy);
67
68 turnoutService.update(null, LocalDateTime.now(), citizenId, realizationId, pollingStation);
69
70 return candidacyVoteRepository.save(candidacyVote);
71 }
72}
Note: See TracBrowser for help on using the repository browser.