main
Line | |
---|
1 | package mk.ukim.finki.eglas.services.Impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.eglas.model.Election;
|
---|
4 | import mk.ukim.finki.eglas.repository.ElectionRepository;
|
---|
5 | import mk.ukim.finki.eglas.services.ElectionService;
|
---|
6 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 |
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | @Service
|
---|
12 | public 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.