feat(sync) : add slot selection controllers, custom field sync, and position fallbacks

- Add selectedPieceId support to ComposantPieceSlotController
- Create ComposantProductSlotController and ComposantSubcomponentSlotController
- Add updateCustomFields() to SkeletonStructureService for managing CustomField entities
- Fix position/orderIndex fallback to array index in all 3 sync strategies
- Fix type comparison in ProductSyncStrategy for dual format support
- Update CLAUDE.md with new entities, controllers, and fixtures documentation
- Update frontend submodule with interactive slot selectors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-13 16:40:44 +01:00
parent 4072abf7ba
commit b2aff0e414
11 changed files with 1380 additions and 28 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\ComposantPieceSlot;
use App\Entity\Piece;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -37,12 +38,22 @@ class ComposantPieceSlotController extends AbstractController
$slot->setQuantity(max(1, (int) $payload['quantity']));
}
if (array_key_exists('selectedPieceId', $payload)) {
if (null === $payload['selectedPieceId']) {
$slot->setSelectedPiece(null);
} else {
$piece = $this->entityManager->find(Piece::class, $payload['selectedPieceId']);
$slot->setSelectedPiece($piece);
}
}
$this->entityManager->flush();
return $this->json([
'success' => true,
'id' => $slot->getId(),
'quantity' => $slot->getQuantity(),
'success' => true,
'id' => $slot->getId(),
'quantity' => $slot->getQuantity(),
'selectedPieceId' => $slot->getSelectedPiece()?->getId(),
]);
}
}

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\ComposantProductSlot;
use App\Entity\Product;
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-product-slots')]
class ComposantProductSlotController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
) {}
#[Route('/{id}', name: 'composant_product_slot_patch', methods: ['PATCH'])]
public function patch(string $id, Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_GESTIONNAIRE');
$slot = $this->entityManager->find(ComposantProductSlot::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('selectedProductId', $payload)) {
if (null === $payload['selectedProductId']) {
$slot->setSelectedProduct(null);
} else {
$product = $this->entityManager->find(Product::class, $payload['selectedProductId']);
$slot->setSelectedProduct($product);
}
}
$this->entityManager->flush();
return $this->json([
'success' => true,
'id' => $slot->getId(),
'selectedProductId' => $slot->getSelectedProduct()?->getId(),
]);
}
}

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\Composant;
use App\Entity\ComposantSubcomponentSlot;
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-subcomponent-slots')]
class ComposantSubcomponentSlotController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
) {}
#[Route('/{id}', name: 'composant_subcomponent_slot_patch', methods: ['PATCH'])]
public function patch(string $id, Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_GESTIONNAIRE');
$slot = $this->entityManager->find(ComposantSubcomponentSlot::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('selectedComposantId', $payload)) {
if (null === $payload['selectedComposantId']) {
$slot->setSelectedComposant(null);
} else {
$composant = $this->entityManager->find(Composant::class, $payload['selectedComposantId']);
$slot->setSelectedComposant($composant);
}
}
$this->entityManager->flush();
return $this->json([
'success' => true,
'id' => $slot->getId(),
'selectedComposantId' => $slot->getSelectedComposant()?->getId(),
]);
}
}