feat: implement global pricing model, optional equipment contribution, and bulk save for dotations
This commit is contained in:
@@ -3,10 +3,14 @@ package com.astalange.web.controller;
|
||||
import com.astalange.core.entity.Dotation;
|
||||
import com.astalange.core.repository.DotationRepository;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
public class DotationController {
|
||||
|
||||
@@ -22,17 +26,61 @@ public class DotationController {
|
||||
@RequestParam Long adherentId,
|
||||
@RequestParam(required = false, defaultValue = "") String taille,
|
||||
@RequestParam(required = false, defaultValue = "") String flocage,
|
||||
@RequestParam(required = false) Boolean fourni) {
|
||||
@RequestParam(required = false, defaultValue = "") String numero,
|
||||
@RequestParam(required = false) Boolean fourni,
|
||||
@RequestParam(required = false) Boolean choisi) {
|
||||
|
||||
Dotation dotation = dotationRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid Dotation ID: " + id));
|
||||
|
||||
dotation.setTaille(taille);
|
||||
dotation.setFlocage(flocage);
|
||||
dotation.setNumero(numero);
|
||||
dotation.setFourni(fourni != null && fourni);
|
||||
|
||||
if (dotation.getEquipement().getObligatoire()) {
|
||||
dotation.setChoisi(true);
|
||||
} else {
|
||||
dotation.setChoisi(choisi != null && choisi);
|
||||
}
|
||||
|
||||
dotationRepository.save(dotation);
|
||||
|
||||
return "redirect:/adherents/" + adherentId + "/edit";
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@PostMapping("/dotations/bulk")
|
||||
public String bulkUpdateDotations(
|
||||
@RequestParam Long adherentId,
|
||||
@RequestParam("dotationIds") List<Long> dotationIds,
|
||||
HttpServletRequest request) {
|
||||
|
||||
for (Long id : dotationIds) {
|
||||
Dotation dotation = dotationRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid Dotation ID: " + id));
|
||||
|
||||
String taille = request.getParameter("taille_" + id);
|
||||
String numero = request.getParameter("numero_" + id);
|
||||
String flocage = request.getParameter("flocage_" + id);
|
||||
String choisiParam = request.getParameter("choisi_" + id);
|
||||
String fourniParam = request.getParameter("fourni_" + id);
|
||||
|
||||
if (taille != null) dotation.setTaille(taille);
|
||||
if (numero != null) dotation.setNumero(numero);
|
||||
if (flocage != null) dotation.setFlocage(flocage);
|
||||
|
||||
if (dotation.getEquipement().getObligatoire()) {
|
||||
dotation.setChoisi(true);
|
||||
} else {
|
||||
dotation.setChoisi(choisiParam != null);
|
||||
}
|
||||
|
||||
dotation.setFourni(fourniParam != null);
|
||||
|
||||
dotationRepository.save(dotation);
|
||||
}
|
||||
|
||||
return "redirect:/adherents/" + adherentId + "/edit";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user