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