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 | |
---|
1 | package mk.ukim.finki.eglas.services.Impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.eglas.model.VoteIdentificationCode;
|
---|
4 | import mk.ukim.finki.eglas.repository.VoteIdentificationCodeRepository;
|
---|
5 | import mk.ukim.finki.eglas.services.VoteIdentificationCodeService;
|
---|
6 | import org.springframework.stereotype.Service;
|
---|
7 |
|
---|
8 | import java.time.LocalDateTime;
|
---|
9 | import java.util.UUID;
|
---|
10 |
|
---|
11 | @Service
|
---|
12 | public 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.