feat(custom-fields) : support link-based upsert in CustomFieldValueController
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,8 @@ use App\Entity\CustomFieldValue;
|
|||||||
use App\Repository\ComposantRepository;
|
use App\Repository\ComposantRepository;
|
||||||
use App\Repository\CustomFieldRepository;
|
use App\Repository\CustomFieldRepository;
|
||||||
use App\Repository\CustomFieldValueRepository;
|
use App\Repository\CustomFieldValueRepository;
|
||||||
|
use App\Repository\MachineComponentLinkRepository;
|
||||||
|
use App\Repository\MachinePieceLinkRepository;
|
||||||
use App\Repository\MachineRepository;
|
use App\Repository\MachineRepository;
|
||||||
use App\Repository\PieceRepository;
|
use App\Repository\PieceRepository;
|
||||||
use App\Repository\ProductRepository;
|
use App\Repository\ProductRepository;
|
||||||
@@ -29,6 +31,8 @@ class CustomFieldValueController extends AbstractController
|
|||||||
private readonly ComposantRepository $composantRepository,
|
private readonly ComposantRepository $composantRepository,
|
||||||
private readonly PieceRepository $pieceRepository,
|
private readonly PieceRepository $pieceRepository,
|
||||||
private readonly ProductRepository $productRepository,
|
private readonly ProductRepository $productRepository,
|
||||||
|
private readonly MachineComponentLinkRepository $machineComponentLinkRepository,
|
||||||
|
private readonly MachinePieceLinkRepository $machinePieceLinkRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('', name: 'custom_field_values_create', methods: ['POST'])]
|
#[Route('', name: 'custom_field_values_create', methods: ['POST'])]
|
||||||
@@ -214,7 +218,7 @@ class CustomFieldValueController extends AbstractController
|
|||||||
$entityId = isset($payload['entityId']) ? trim((string) $payload['entityId']) : '';
|
$entityId = isset($payload['entityId']) ? trim((string) $payload['entityId']) : '';
|
||||||
|
|
||||||
if ('' === $entityType || '' === $entityId) {
|
if ('' === $entityType || '' === $entityId) {
|
||||||
foreach (['machine', 'composant', 'piece', 'product'] as $candidate) {
|
foreach (['machine', 'composant', 'piece', 'product', 'machineComponentLink', 'machinePieceLink'] as $candidate) {
|
||||||
$key = $candidate.'Id';
|
$key = $candidate.'Id';
|
||||||
if (!isset($payload[$key])) {
|
if (!isset($payload[$key])) {
|
||||||
continue;
|
continue;
|
||||||
@@ -226,16 +230,20 @@ class CustomFieldValueController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$entityType = strtolower($entityType);
|
||||||
|
|
||||||
if ('' === $entityType || '' === $entityId) {
|
if ('' === $entityType || '' === $entityId) {
|
||||||
return $this->json(['success' => false, 'error' => 'Entity target is missing.'], 400);
|
return $this->json(['success' => false, 'error' => 'Entity target is missing.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
return match ($entityType) {
|
return match ($entityType) {
|
||||||
'machine' => $this->resolveEntity('machine', $entityId, $this->machineRepository),
|
'machine' => $this->resolveEntity('machine', $entityId, $this->machineRepository),
|
||||||
'composant' => $this->resolveEntity('composant', $entityId, $this->composantRepository),
|
'composant' => $this->resolveEntity('composant', $entityId, $this->composantRepository),
|
||||||
'piece' => $this->resolveEntity('piece', $entityId, $this->pieceRepository),
|
'piece' => $this->resolveEntity('piece', $entityId, $this->pieceRepository),
|
||||||
'product' => $this->resolveEntity('product', $entityId, $this->productRepository),
|
'product' => $this->resolveEntity('product', $entityId, $this->productRepository),
|
||||||
default => $this->json(['success' => false, 'error' => 'Unsupported entity type.'], 400),
|
'machinecomponentlink' => $this->resolveEntity('machineComponentLink', $entityId, $this->machineComponentLinkRepository),
|
||||||
|
'machinepiecelink' => $this->resolveEntity('machinePieceLink', $entityId, $this->machinePieceLinkRepository),
|
||||||
|
default => $this->json(['success' => false, 'error' => 'Unsupported entity type.'], 400),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,6 +278,18 @@ class CustomFieldValueController extends AbstractController
|
|||||||
case 'product':
|
case 'product':
|
||||||
$value->setProduct($entity);
|
$value->setProduct($entity);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'machineComponentLink':
|
||||||
|
$value->setMachineComponentLink($entity);
|
||||||
|
$value->setComposant($entity->getComposant());
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'machinePieceLink':
|
||||||
|
$value->setMachinePieceLink($entity);
|
||||||
|
$value->setPiece($entity->getPiece());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user