Changes between Version 10 and Version 11 of AdvancedApplicationDevelopment


Ignore:
Timestamp:
06/20/24 16:31:17 (2 weeks ago)
Author:
211012
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedApplicationDevelopment

    v10 v11  
    418418    }
    419419}}}
     420== Пријавува учество на кандидатски листи
     421Администраторот со пристап до адресата /candidatesLists добива приказ на листа со постоечки кандидатски листи и можност за креирање на нова кандидатска листа со избор на општина, реализација и изборна единица. Потоа следи одбирање на кандидатите при што бројот е лимитиран на 20, според изборниот законик во Македонија. Креирањето на кандидатската листа е исто така имплементирано во вид на трансакција, односно методот е анотиран со @Transactional.
     422{{{#!java
     423    @Override
     424    @Transactional
     425    public CandidatesList update(Long id, String description, Long partyId, Long candidatesListElectionRealizationId, Long municipalityId, Long electoralUnitId, List<Long> candidatesInList) {
     426        if(candidatesInList.size() != 20)
     427        {
     428            throw new RuntimeException("Candidates list must have 20 candidates!");
     429        }
     430       
     431        CandidatesList list;
     432
     433        ElectoralUnit electoralUnit = electoralUnitId != null ? electoralUnitService.findById(electoralUnitId) : null;
     434        Municipality municipality = municipalityId != null ? municipalityService.findById(municipalityId) : null;
     435        CandidatesListElectionRealization candidatesListElectionRealization = candidatesListElectionRealizationService.findById(candidatesListElectionRealizationId);
     436        Party party = partyService.findById(partyId);
     437
     438        if (id != null) {
     439            list = findById(id);
     440            list.getCandidates().clear();
     441            repository.save(list);
     442        } else {
     443            throw new IllegalArgumentException("Id must be provided for update operation.");
     444        }
     445
     446        candidatesInList.stream()
     447                .filter(Objects::nonNull)
     448                .map(candidateService::findById)
     449                .forEach(x -> list.candidates.add(x));
     450        list.setDescription(description);
     451        list.setParty(party);
     452        list.setMunicipality(municipality);
     453        list.setElectoralUnit(electoralUnit);
     454        list.setCandidatesListElectionRealization(candidatesListElectionRealization);
     455        return repository.save(list);
     456    }
     457}}}