[ac151d1] | 1 | package mk.ukim.finki.eglas.services.Impl;
|
---|
| 2 |
|
---|
| 3 | import mk.ukim.finki.eglas.model.*;
|
---|
| 4 | import mk.ukim.finki.eglas.repository.ObjectionRepository;
|
---|
| 5 | import mk.ukim.finki.eglas.repository.PartyRepository;
|
---|
| 6 | import mk.ukim.finki.eglas.services.*;
|
---|
| 7 | import org.springframework.stereotype.Service;
|
---|
| 8 |
|
---|
| 9 | import java.util.List;
|
---|
| 10 | // Jovan
|
---|
| 11 |
|
---|
| 12 | @Service
|
---|
| 13 | public class ObjectionServiceImpl implements ObjectionService {
|
---|
| 14 | private final ObjectionRepository objectionRepository;
|
---|
| 15 | private final PartyService partyService;
|
---|
| 16 | private final ElectionRealizationService electionRealizationService;
|
---|
| 17 | private final AddressService addressService;
|
---|
| 18 |
|
---|
| 19 | ObjectionServiceImpl(ObjectionRepository objectionRepository, PartyService partyService, ElectionRealizationService electionRealizationService, AddressService addressService){
|
---|
| 20 | this.objectionRepository = objectionRepository;
|
---|
| 21 | this.partyService = partyService;
|
---|
| 22 | this.electionRealizationService = electionRealizationService;
|
---|
| 23 | this.addressService = addressService;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | @Override
|
---|
| 27 | public List<Objection> findAll() {
|
---|
| 28 | return objectionRepository.findAll();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
| 32 | public Objection findById(Long id) {
|
---|
| 33 | return objectionRepository.findById(id).orElseThrow(() -> new RuntimeException("Objection not found"));
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | @Override
|
---|
| 37 | public Objection update(Long id, Long electionRealizationId, Long pollingStationId, String description) {
|
---|
| 38 | ElectionRealization electionRealization = electionRealizationService.findById(electionRealizationId);
|
---|
| 39 | PollingStation pollingStation = addressService.findPollingStationById(pollingStationId);
|
---|
| 40 | Objection objection = new Objection();
|
---|
| 41 | if(id != null)
|
---|
| 42 | {
|
---|
| 43 | objection = findById(id);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | objection.setDescription(description);
|
---|
| 47 | objection.setElectionRealization(electionRealization);
|
---|
| 48 | objection.setPollingStation(pollingStation);
|
---|
| 49 | return objectionRepository.save(objection);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | @Override
|
---|
| 53 | public Objection delete(Long id) {
|
---|
| 54 | Objection objection = findById(id);
|
---|
| 55 | objectionRepository.delete(objection);
|
---|
| 56 | return objection;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | @Override
|
---|
| 60 | public Objection accept(Long id) {
|
---|
| 61 | Objection objection = findById(id);
|
---|
| 62 | objection.setStatus(2);
|
---|
| 63 | return objectionRepository.save(objection);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | @Override
|
---|
| 67 | public Objection reject(Long id) {
|
---|
| 68 | Objection objection = findById(id);
|
---|
| 69 | objection.setStatus(3);
|
---|
| 70 | return objectionRepository.save(objection);
|
---|
| 71 | }
|
---|
| 72 | }
|
---|