feat(mcp) : add CRUD tools for Sites, Constructeurs, Products
- 5 tools each: list, get, create, update, delete - McpToolHelper extracted to AbstractApiTestCase for reuse - DashboardStatsToolTest simplified to use base helpers - 22 MCP tests pass Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
55
src/Mcp/Tool/Constructeur/UpdateConstructeurTool.php
Normal file
55
src/Mcp/Tool/Constructeur/UpdateConstructeurTool.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Constructeur;
|
||||
|
||||
use App\Mcp\Tool\McpToolHelper;
|
||||
use App\Repository\ConstructeurRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
#[McpTool(
|
||||
name: 'update_constructeur',
|
||||
description: 'Update an existing constructeur. Only provided fields are changed. Requires ROLE_GESTIONNAIRE.',
|
||||
)]
|
||||
class UpdateConstructeurTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
public function __construct(
|
||||
private readonly ConstructeurRepository $constructeurs,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly Security $security,
|
||||
) {}
|
||||
|
||||
public function __invoke(
|
||||
string $constructeurId,
|
||||
?string $name = null,
|
||||
?string $email = null,
|
||||
?string $phone = null,
|
||||
): array {
|
||||
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
|
||||
|
||||
$constructeur = $this->constructeurs->find($constructeurId);
|
||||
|
||||
if (!$constructeur) {
|
||||
$this->mcpError('not_found', "Constructeur not found: {$constructeurId}");
|
||||
}
|
||||
|
||||
if (null !== $name) {
|
||||
$constructeur->setName($name);
|
||||
}
|
||||
if (null !== $email) {
|
||||
$constructeur->setEmail($email);
|
||||
}
|
||||
if (null !== $phone) {
|
||||
$constructeur->setPhone($phone);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $this->jsonResponse(['id' => $constructeur->getId(), 'name' => $constructeur->getName()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user