source: src/main/java/mk/ukim/finki/eglas/services/Impl/VoteIdentificationCodeServiceImpl.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: 1.5 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import mk.ukim.finki.eglas.model.VoteIdentificationCode;
4import mk.ukim.finki.eglas.repository.VoteIdentificationCodeRepository;
5import mk.ukim.finki.eglas.services.VoteIdentificationCodeService;
6import org.springframework.stereotype.Service;
7
8import java.time.LocalDateTime;
9import java.util.UUID;
10
11@Service
12public class VoteIdentificationCodeServiceImpl implements VoteIdentificationCodeService {
13
14 private final VoteIdentificationCodeRepository voteIdentificationCodeRepository;
15
16 public VoteIdentificationCodeServiceImpl(VoteIdentificationCodeRepository voteIdentificationCodeRepository) {
17 this.voteIdentificationCodeRepository = voteIdentificationCodeRepository;
18 }
19
20 @Override
21 public void generateCodes(int n, LocalDateTime validUntil) {
22 for(int i = 0; i < n; i++)
23 {
24 VoteIdentificationCode voteIdentificationCode = new VoteIdentificationCode(validUntil);
25 voteIdentificationCodeRepository.save(voteIdentificationCode);
26 }
27 }
28
29 @Override
30 public VoteIdentificationCode findRandomIdentificationCode() {
31 return voteIdentificationCodeRepository.findRandomVoteIdentificationCode()
32 .orElseThrow(() -> new RuntimeException("No voting identification code available!"));
33 }
34
35 @Override
36 public VoteIdentificationCode findById(UUID id) {
37 return voteIdentificationCodeRepository.findById(id)
38 .orElseThrow(() -> new RuntimeException("Vote Identification Code not found!"));
39 }
40}
Note: See TracBrowser for help on using the repository browser.