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