All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
115 lines
5.3 KiB
Java
115 lines
5.3 KiB
Java
package io.gmss.fiscad.implementations.decoupage;
|
|
|
|
import io.gmss.fiscad.entities.decoupage.Secteur;
|
|
import io.gmss.fiscad.entities.decoupage.SecteurDecoupage;
|
|
import io.gmss.fiscad.exceptions.BadRequestException;
|
|
import io.gmss.fiscad.exceptions.NotFoundException;
|
|
import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService;
|
|
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
|
|
import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb;
|
|
import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb;
|
|
import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur;
|
|
import io.gmss.fiscad.persistence.repositories.decoupage.SecteurDecoupageRepository;
|
|
import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository;
|
|
import io.gmss.fiscad.service.EntityFromPayLoadService;
|
|
import lombok.AllArgsConstructor;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
@AllArgsConstructor
|
|
@Service
|
|
public class SecteurDecoupageServiceImpl implements SecteurDecoupageService {
|
|
private final SecteurDecoupageRepository secteurDecoupageRepository;
|
|
private final SecteurService secteurService;
|
|
private final ParcelleRepository parcelleRepository;
|
|
private final EntityFromPayLoadService entityFromPayLoadService;
|
|
|
|
|
|
|
|
@Override
|
|
public SecteurDecoupagePaylaodWeb createSecteurDecoupage(SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb) throws BadRequestException {
|
|
if (secteurDecoupagePaylaodWeb.getId() != null) {
|
|
throw new BadRequestException("Impossible de créer un nouveau secteur découpage ayant un id non null.");
|
|
}
|
|
SecteurDecoupage secteurDecoupage = entityFromPayLoadService.getSecteurDecoupageFromPayLoadWeb(secteurDecoupagePaylaodWeb);
|
|
secteurDecoupage = secteurDecoupageRepository.save(secteurDecoupage);
|
|
return secteurDecoupageRepository.findSecteurDecoupageToDtoById(secteurDecoupage.getId()).orElse(null);
|
|
}
|
|
|
|
@Override
|
|
public SecteurDecoupagePaylaodWeb updateSecteurDecoupage(Long id, SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb) throws NotFoundException {
|
|
if (secteurDecoupagePaylaodWeb.getId() == null) {
|
|
throw new BadRequestException("Impossible de mettre à jour un nouveau secteur découpage ayant un id null.");
|
|
}
|
|
if (!secteurDecoupageRepository.existsById(secteurDecoupagePaylaodWeb.getId())) {
|
|
throw new NotFoundException("Impossible de trouver le secteur découpage spécifié.");
|
|
}
|
|
|
|
SecteurDecoupage secteurDecoupage = entityFromPayLoadService.getSecteurDecoupageFromPayLoadWeb(secteurDecoupagePaylaodWeb);
|
|
secteurDecoupage = secteurDecoupageRepository.save(secteurDecoupage);
|
|
return secteurDecoupageRepository.findSecteurDecoupageToDtoById(secteurDecoupage.getId()).orElse(null);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void deleteSecteurDecoupage(Long id) throws NotFoundException {
|
|
Optional<SecteurDecoupage> secteurDecoupageOptional = secteurDecoupageRepository.findById(id);
|
|
if (secteurDecoupageOptional.isPresent()) {
|
|
secteurDecoupageRepository.deleteById(secteurDecoupageOptional.get().getId());
|
|
} else {
|
|
throw new NotFoundException("Impossible de trouver le secteur découpage spécifié.");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Page<SecteurDecoupagePaylaodWeb> getSecteurDecoupageList(Pageable pageable) {
|
|
return secteurDecoupageRepository.findAllSecteurDecoupageToDtoPageable(pageable);
|
|
}
|
|
|
|
@Override
|
|
public List<SecteurDecoupagePaylaodWeb> getSecteurDecoupageList() {
|
|
return secteurDecoupageRepository.findAllSecteurDecoupageToDto();
|
|
}
|
|
|
|
@Override
|
|
public Page<SecteurDecoupagePaylaodWeb> getSecteurDecoupageListBySecteurId(Long secteurId, Pageable pageable) {
|
|
return secteurDecoupageRepository.findAllSecteurDecoupageBySecteurToDtoPageable(secteurId,pageable);
|
|
}
|
|
|
|
@Override
|
|
public List<SecteurDecoupagePaylaodWeb> getSecteurDecoupageListBySecteurId(Long sectionId) {
|
|
return secteurDecoupageRepository.findAllSecteurDecoupageBySecteurToDto(sectionId);
|
|
}
|
|
|
|
@Override
|
|
public Optional<SecteurDecoupagePaylaodWeb> getSecteurDecoupageByIdToDto(Long id) {
|
|
return secteurDecoupageRepository.findSecteurDecoupageToDtoById(id);
|
|
}
|
|
|
|
|
|
@Override
|
|
public Optional<SecteurDecoupage> getSecteurDecoupageById(Long id) {
|
|
return secteurDecoupageRepository.findById(id);
|
|
}
|
|
|
|
@Override
|
|
public List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageUnSecteur(Long secteurId) {
|
|
return parcelleRepository.findStatsBySecteurs(List.of(secteurId));
|
|
}
|
|
|
|
@Override
|
|
public List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageByUserId(Long userId) {
|
|
List<ParcelleStatsProjectionUnSecteur> parcelleStatsProjectionUnSecteurs = new ArrayList<>();
|
|
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
|
|
List<Long> secteurIds = secteurs.stream()
|
|
.map(Secteur::getId)
|
|
.toList();
|
|
parcelleStatsProjectionUnSecteurs = parcelleRepository.findStatsBySecteurs(secteurIds);
|
|
|
|
return parcelleStatsProjectionUnSecteurs ;
|
|
}
|
|
} |