main
Line | |
---|
1 | package mk.ukim.finki.eglas.services.Impl;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.eglas.model.ElectoralUnit;
|
---|
4 | import mk.ukim.finki.eglas.repository.ElectoralUnitRepository;
|
---|
5 | import mk.ukim.finki.eglas.services.ElectoralUnitService;
|
---|
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 ElectoralUnitServiceImpl implements ElectoralUnitService {
|
---|
13 | @Autowired
|
---|
14 | ElectoralUnitRepository electoralUnitRepository;
|
---|
15 | @Override
|
---|
16 | public List<ElectoralUnit> findAll() {
|
---|
17 | return electoralUnitRepository.findAll();
|
---|
18 | }
|
---|
19 |
|
---|
20 | @Override
|
---|
21 | public ElectoralUnit findById(Long id) {
|
---|
22 | return electoralUnitRepository.findById(id).orElseThrow(() -> new RuntimeException("Electoral unit not found"));
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | public ElectoralUnit update(Long id, String name, Integer numDeputies) {
|
---|
27 | ElectoralUnit electoralUnit = new ElectoralUnit();
|
---|
28 | if(id != null)
|
---|
29 | {
|
---|
30 | electoralUnit = findById(id);
|
---|
31 | }
|
---|
32 | electoralUnit.setName(name);
|
---|
33 | electoralUnit.setNumDeputies(numDeputies);
|
---|
34 | return electoralUnitRepository.save(electoralUnit);
|
---|
35 | }
|
---|
36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.