requireRole($this->security, 'ROLE_GESTIONNAIRE'); $piece = $this->pieces->find($pieceId); if (!$piece) { $this->mcpError('not_found', "Piece not found: {$pieceId}"); } if (null !== $name) { $piece->setName($name); } if (null !== $reference) { $piece->setReference($reference); } if (null !== $description) { $piece->setDescription($description); } if (null !== $prix) { $piece->setPrix($prix); } if (null !== $modelTypeId) { if ('' === $modelTypeId) { $piece->setTypePiece(null); } else { $modelType = $this->modelTypes->find($modelTypeId); if (!$modelType) { $this->mcpError('not_found', "ModelType not found: {$modelTypeId}"); } $piece->setTypePiece($modelType); } } if (null !== $constructeurIds) { foreach ($piece->getConstructeurs()->toArray() as $existing) { $piece->removeConstructeur($existing); } foreach ($constructeurIds as $cId) { $c = $this->constructeurs->find($cId); if (!$c) { $this->mcpError('not_found', "Constructeur not found: {$cId}"); } $piece->addConstructeur($c); } } $this->em->flush(); return $this->jsonResponse(['id' => $piece->getId(), 'name' => $piece->getName()]); } }