source: src/main/java/mk/ukim/finki/eglas/services/Impl/CandidateServiceImpl.java

main
Last change on this file was ac151d1, checked in by David <darsov2@…>, 4 months ago

initial

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import mk.ukim.finki.eglas.model.Candidate;
4import mk.ukim.finki.eglas.model.Citizen;
5import mk.ukim.finki.eglas.repository.CandidateRepository;
6import mk.ukim.finki.eglas.services.CandidateService;
7import mk.ukim.finki.eglas.services.CitizenService;
8import org.springframework.stereotype.Service;
9
10import java.util.List;
11
12@Service
13public 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}
Note: See TracBrowser for help on using the repository browser.