feat(composant) : add ComposantPieceSlotController for slot quantity PATCH
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
// This file is auto-generated and is for apps only. Bundles SHOULD NOT rely on its content.
|
// This file is auto-generated and is for apps only. Bundles SHOULD NOT rely on its content.
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||||
@@ -1385,7 +1387,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||||||
* mercure?: bool|array{
|
* mercure?: bool|array{
|
||||||
* enabled?: bool|Param, // Default: false
|
* enabled?: bool|Param, // Default: false
|
||||||
* hub_url?: scalar|null|Param, // The URL sent in the Link HTTP header. If not set, will default to the URL for MercureBundle's default hub. // Default: null
|
* hub_url?: scalar|null|Param, // The URL sent in the Link HTTP header. If not set, will default to the URL for MercureBundle's default hub. // Default: null
|
||||||
* include_type?: bool|Param, // Always include @type in updates (including delete ones). // Default: false
|
* include_type?: bool|Param, // Always include @var in updates (including delete ones). // Default: false
|
||||||
* },
|
* },
|
||||||
* messenger?: bool|array{
|
* messenger?: bool|array{
|
||||||
* enabled?: bool|Param, // Default: false
|
* enabled?: bool|Param, // Default: false
|
||||||
@@ -1606,6 +1608,12 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||||||
* cache?: scalar|null|Param, // Storage to track blocked tokens // Default: "cache.app"
|
* cache?: scalar|null|Param, // Storage to track blocked tokens // Default: "cache.app"
|
||||||
* },
|
* },
|
||||||
* }
|
* }
|
||||||
|
* @psalm-type DamaDoctrineTestConfig = array{
|
||||||
|
* enable_static_connection?: mixed, // Default: true
|
||||||
|
* enable_static_meta_data_cache?: bool|Param, // Default: true
|
||||||
|
* enable_static_query_cache?: bool|Param, // Default: true
|
||||||
|
* connection_keys?: list<mixed>,
|
||||||
|
* }
|
||||||
* @psalm-type ConfigType = array{
|
* @psalm-type ConfigType = array{
|
||||||
* imports?: ImportsConfig,
|
* imports?: ImportsConfig,
|
||||||
* parameters?: ParametersConfig,
|
* parameters?: ParametersConfig,
|
||||||
@@ -1618,19 +1626,6 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||||||
* nelmio_cors?: NelmioCorsConfig,
|
* nelmio_cors?: NelmioCorsConfig,
|
||||||
* api_platform?: ApiPlatformConfig,
|
* api_platform?: ApiPlatformConfig,
|
||||||
* lexik_jwt_authentication?: LexikJwtAuthenticationConfig,
|
* 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{
|
* "when@prod"?: array{
|
||||||
* imports?: ImportsConfig,
|
* imports?: ImportsConfig,
|
||||||
* parameters?: ParametersConfig,
|
* parameters?: ParametersConfig,
|
||||||
@@ -1656,6 +1651,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||||||
* nelmio_cors?: NelmioCorsConfig,
|
* nelmio_cors?: NelmioCorsConfig,
|
||||||
* api_platform?: ApiPlatformConfig,
|
* api_platform?: ApiPlatformConfig,
|
||||||
* lexik_jwt_authentication?: LexikJwtAuthenticationConfig,
|
* lexik_jwt_authentication?: LexikJwtAuthenticationConfig,
|
||||||
|
* dama_doctrine_test?: DamaDoctrineTestConfig,
|
||||||
* },
|
* },
|
||||||
* ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias
|
* ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias
|
||||||
* imports?: ImportsConfig,
|
* imports?: ImportsConfig,
|
||||||
@@ -1736,7 +1732,6 @@ namespace Symfony\Component\Routing\Loader\Configurator;
|
|||||||
* deprecated?: array{package:string, version:string, message?:string},
|
* deprecated?: array{package:string, version:string, message?:string},
|
||||||
* }
|
* }
|
||||||
* @psalm-type RoutesConfig = array{
|
* @psalm-type RoutesConfig = array{
|
||||||
* "when@dev"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
|
|
||||||
* "when@prod"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
|
* "when@prod"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
|
||||||
* "when@test"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
|
* "when@test"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
|
||||||
* ...<string, RouteConfig|ImportConfig|AliasConfig>
|
* ...<string, RouteConfig|ImportConfig|AliasConfig>
|
||||||
|
|||||||
48
src/Controller/ComposantPieceSlotController.php
Normal file
48
src/Controller/ComposantPieceSlotController.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\ComposantPieceSlot;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
#[Route('/api/composant-piece-slots')]
|
||||||
|
class ComposantPieceSlotController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('/{id}', name: 'composant_piece_slot_patch', methods: ['PATCH'])]
|
||||||
|
public function patch(string $id, Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$this->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(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user