pieces->find($pieceId); if (!$piece) { $this->mcpError('not_found', "Piece not found: {$pieceId}"); } $constructeurs = []; foreach ($piece->getConstructeurs() as $c) { $constructeurs[] = [ 'id' => $c->getId(), 'name' => $c->getName(), ]; } $typePiece = null; if ($piece->getTypePiece()) { $typePiece = [ 'id' => $piece->getTypePiece()->getId(), 'name' => $piece->getTypePiece()->getName(), ]; } return $this->jsonResponse([ 'id' => $piece->getId(), 'name' => $piece->getName(), 'reference' => $piece->getReference(), 'description' => $piece->getDescription(), 'prix' => $piece->getPrix(), 'typePiece' => $typePiece, 'constructeurs' => $constructeurs, 'createdAt' => $piece->getCreatedAt()->format('Y-m-d H:i:s'), 'updatedAt' => $piece->getUpdatedAt()->format('Y-m-d H:i:s'), ]); } }