1 | package mk.ukim.finki.eglas.services.Impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.eglas.model.Candidate;
|
---|
4 | import mk.ukim.finki.eglas.model.Citizen;
|
---|
5 | import mk.ukim.finki.eglas.repository.CandidateRepository;
|
---|
6 | import mk.ukim.finki.eglas.services.CandidateService;
|
---|
7 | import mk.ukim.finki.eglas.services.CitizenService;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | @Service
|
---|
13 | public class CandidateServiceImpl implements CandidateService {
|
---|
14 |
|
---|
15 | private final CandidateRepository repository;
|
---|
16 | private final CitizenService citizenService;
|
---|
17 |
|
---|
18 | CandidateServiceImpl(CandidateRepository repository, CitizenService citizenService){
|
---|
19 | this.repository = repository;
|
---|
20 | this.citizenService = citizenService;
|
---|
21 | }
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public Candidate findById(Long id) {
|
---|
25 | return repository.findById(id).orElseThrow(() -> new RuntimeException("No candidate found"));
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public List<Candidate> findAll() {
|
---|
30 | return repository.findAll();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public Candidate update(Long id) {
|
---|
35 | Citizen citizen = citizenService.findById(id);
|
---|
36 | Candidate candidate = new Candidate();
|
---|
37 | candidate.setId(id);
|
---|
38 | // candidate.setName(citizen.getName());
|
---|
39 | // candidate.setSurname(citizen.getSurname());
|
---|
40 | // candidate.setAddress(citizen.getAddress());
|
---|
41 | // candidate.setIdNum(citizen.getIdNum());
|
---|
42 | // candidate.setDocument(citizen.getDocument());
|
---|
43 | // candidate.setDateOfBirth(citizen.getDateOfBirth());
|
---|
44 | repository.insertCandidate(id);
|
---|
45 | return candidate;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void delete(Long id) {
|
---|
50 | Candidate candidate = (Candidate) citizenService.findById(id);
|
---|
51 | repository.delete(candidate); ;
|
---|
52 | }
|
---|
53 | }
|
---|