From 44cfa25ecad64240bce575e17b163fae4b9c289c Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 13 Mar 2026 11:22:43 +0100 Subject: [PATCH] feat(composant) : add ComposantPieceSlotController for slot quantity PATCH Co-Authored-By: Claude Opus 4.6 --- config/reference.php | 25 ++++------ .../ComposantPieceSlotController.php | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 src/Controller/ComposantPieceSlotController.php diff --git a/config/reference.php b/config/reference.php index 36f4935..200e125 100644 --- a/config/reference.php +++ b/config/reference.php @@ -1,5 +1,7 @@ , + * } * @psalm-type ConfigType = array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, @@ -1618,19 +1626,6 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * nelmio_cors?: NelmioCorsConfig, * api_platform?: ApiPlatformConfig, * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, - * "when@dev"?: array{ - * imports?: ImportsConfig, - * parameters?: ParametersConfig, - * services?: ServicesConfig, - * framework?: FrameworkConfig, - * twig?: TwigConfig, - * security?: SecurityConfig, - * doctrine?: DoctrineConfig, - * doctrine_migrations?: DoctrineMigrationsConfig, - * nelmio_cors?: NelmioCorsConfig, - * api_platform?: ApiPlatformConfig, - * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, - * }, * "when@prod"?: array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, @@ -1656,6 +1651,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * nelmio_cors?: NelmioCorsConfig, * api_platform?: ApiPlatformConfig, * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, + * dama_doctrine_test?: DamaDoctrineTestConfig, * }, * ..., * "when@prod"?: array, * "when@test"?: array, * ... diff --git a/src/Controller/ComposantPieceSlotController.php b/src/Controller/ComposantPieceSlotController.php new file mode 100644 index 0000000..87dd12b --- /dev/null +++ b/src/Controller/ComposantPieceSlotController.php @@ -0,0 +1,48 @@ +denyAccessUnlessGranted('ROLE_GESTIONNAIRE'); + + $slot = $this->entityManager->find(ComposantPieceSlot::class, $id); + if (!$slot) { + return $this->json(['success' => false, 'error' => 'Slot not found.'], 404); + } + + $payload = json_decode($request->getContent(), true); + if (!is_array($payload)) { + return $this->json(['success' => false, 'error' => 'Invalid JSON payload.'], 400); + } + + if (array_key_exists('quantity', $payload)) { + $slot->setQuantity(max(1, (int) $payload['quantity'])); + } + + $this->entityManager->flush(); + + return $this->json([ + 'success' => true, + 'id' => $slot->getId(), + 'quantity' => $slot->getQuantity(), + ]); + } +}