1 | package mk.ukim.finki.eglas.services.Impl;
|
---|
2 |
|
---|
3 | import jakarta.transaction.Transactional;
|
---|
4 | import mk.ukim.finki.eglas.model.*;
|
---|
5 | import mk.ukim.finki.eglas.repository.CandidacyVoteRepository;
|
---|
6 | import mk.ukim.finki.eglas.services.*;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 |
|
---|
9 | import java.time.LocalDateTime;
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.UUID;
|
---|
12 |
|
---|
13 | @Service
|
---|
14 | public 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 | }
|
---|