source: src/main/java/mk/ukim/finki/eglas/services/Impl/ElectionServiceImpl.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.2 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import mk.ukim.finki.eglas.model.Election;
4import mk.ukim.finki.eglas.repository.ElectionRepository;
5import mk.ukim.finki.eglas.services.ElectionService;
6import org.springframework.beans.factory.annotation.Autowired;
7import org.springframework.stereotype.Service;
8
9import java.util.List;
10
11@Service
12public class ElectionServiceImpl implements ElectionService {
13 @Autowired
14 ElectionRepository electionRepository;
15
16 @Override
17 public List<Election> findAll() {
18 return electionRepository.findAll();
19 }
20
21 @Override
22 public Election findById(Long id) {
23 return electionRepository.findById(id).orElseThrow(() -> new RuntimeException("Election not found"));
24 }
25
26 @Override
27 public Election update(Long id, String name) {
28 Election election = new Election();
29 if(id != null)
30 {
31 election = findById(id);
32 }
33 election.setName(name);
34 return electionRepository.save(election);
35 }
36
37 @Override
38 public Election delete(Long id) {
39 Election election = findById(id);
40 electionRepository.delete(election);
41 return election;
42 }
43}
Note: See TracBrowser for help on using the repository browser.