source: src/main/java/mk/ukim/finki/eglas/services/Impl/ElectoralUnitServiceImpl.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.ElectoralUnit;
4import mk.ukim.finki.eglas.repository.ElectoralUnitRepository;
5import mk.ukim.finki.eglas.services.ElectoralUnitService;
6import org.springframework.beans.factory.annotation.Autowired;
7import org.springframework.stereotype.Service;
8
9import java.util.List;
10
11@Service
12public 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.