source: src/main/java/mk/ukim/finki/eglas/services/Impl/CandidacyVoteServiceImpl.java@ ac151d1

main
Last change on this file since ac151d1 was ac151d1, checked in by David <darsov2@…>, 11 days ago

initial

  • Property mode set to 100644
File size: 2.8 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.services.*;
7import org.springframework.stereotype.Service;
8
9import java.time.LocalDateTime;
10import java.util.List;
11import java.util.UUID;
12
13@Service
14public class CandidacyVoteServiceImpl implements CandidacyVoteService {
15
16 private final CandidacyVoteRepository repository;
17 private final TurnoutService turnoutService;
18 private final CandidacyService candidacyService;
19 private final CitizenService citizenService;
20 private final CandidatesElectionRealizationService candidatesElectionRealizationService;
21 private final VoteIdentificationCodeService voteIdentificationCodeService;
22
23 public CandidacyVoteServiceImpl(CandidacyVoteRepository repository, TurnoutService turnoutService, CandidacyService candidacyService, CitizenService citizenService, CandidatesElectionRealizationService candidatesElectionRealizationService, VoteIdentificationCodeService voteIdentificationCodeService) {
24 this.repository = repository;
25 this.turnoutService = turnoutService;
26 this.candidacyService = candidacyService;
27 this.citizenService = citizenService;
28 this.candidatesElectionRealizationService = candidatesElectionRealizationService;
29 this.voteIdentificationCodeService = voteIdentificationCodeService;
30 }
31
32 public List<CandidacyVote> findAll() {
33 return repository.findAll();
34 }
35 public CandidacyVote findById(Long id){
36
37 return repository.findById(id).orElseThrow(() -> new RuntimeException("no candidacy vote found"));
38 }
39 public CandidacyVote update(Long voteId, Long candidacyId){
40// CandidacyVote cand = (CandidacyVote) voteService.findById(voteId);
41// cand.setCandidacy(candidacyService.findById(candidacyId));
42// return repository.save(cand);
43 return null;
44 }
45
46 @Override
47 @Transactional
48 public void voteForCandidate(Long citizenId, Long realizationId, UUID voteId, Long id){
49 Citizen citizen = citizenService.findById(citizenId);
50 PollingStation pollingStation = citizen.getAddress().getPollingStation();
51 VoteIdentificationCode voteIdentificationCode = voteIdentificationCodeService.findById(voteId);
52
53// turnoutService.update(null, LocalDateTime.now(), citizenId, realizationId);
54
55 Vote vote = new Vote();
56 vote.setVoteTimestamp(LocalDateTime.now());
57 vote.setPollingStation(pollingStation);
58 vote.setVoteIdentificationCode(voteIdentificationCode);
59// repository.voteForCandidate(voteId, id);
60 }
61
62 public CandidacyVote delete(Long id){
63 CandidacyVote cv = findById(id);
64 repository.delete(cv);
65 return cv;
66 }
67}
Note: See TracBrowser for help on using the repository browser.