da3d190216
LST-60 (3.3). Closes the modular-monolith migration. src/Entity was already
empty; this removes the last legacy residue.
- Doctrine: drop the legacy "App" mapping (empty src/Entity). resolve_target_
entities already targets modules only.
- MCP User tools (Reference/) -> Core/Infrastructure/Mcp/Tool; MCP Serializer
-> Shared/Infrastructure/Mcp (33 usages repointed).
- Controllers (mark-all-read, notification unread-count, regenerate-api-token,
user-avatar) -> Core/Infrastructure/Controller. TokenEncryptor -> Shared/
Infrastructure/Service (11 usages). AppVersion resource+provider -> Shared.
ContractType enum -> Core/Domain/Enum.
- src/{Entity,State,Controller,Service,Enum,ApiResource} now empty; routes,
MCP tool names and public API unchanged.
180 tests green, mapping valid, no route regression, cs-fixer clean.
Note: final Malio visual harmonisation (subjective) left to the PO.
100 lines
3.6 KiB
PHP
100 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Module\TimeTracking\Infrastructure\Mcp\Tool;
|
|
|
|
use App\Module\ProjectManagement\Domain\Repository\ProjectRepositoryInterface;
|
|
use App\Module\ProjectManagement\Domain\Repository\TaskRepositoryInterface;
|
|
use App\Module\ProjectManagement\Domain\Repository\TaskTagRepositoryInterface;
|
|
use App\Module\TimeTracking\Domain\Repository\TimeEntryRepositoryInterface;
|
|
use App\Shared\Infrastructure\Mcp\Serializer;
|
|
use DateTimeImmutable;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use InvalidArgumentException;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
|
|
use function sprintf;
|
|
|
|
#[McpTool(name: 'update-time-entry', description: 'Update a time entry. Use to stop an active timer by providing stoppedAt, or to correct start time. userId is not updatable.')]
|
|
class UpdateTimeEntryTool
|
|
{
|
|
public function __construct(
|
|
private readonly TimeEntryRepositoryInterface $timeEntryRepository,
|
|
private readonly ProjectRepositoryInterface $projectRepository,
|
|
private readonly TaskRepositoryInterface $taskRepository,
|
|
private readonly TaskTagRepositoryInterface $taskTagRepository,
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly Security $security,
|
|
) {}
|
|
|
|
/**
|
|
* @param int[] $tagIds IDs of the tags to attach
|
|
*/
|
|
public function __invoke(
|
|
int $id,
|
|
?string $title = null,
|
|
?string $startedAt = null,
|
|
?string $stoppedAt = null,
|
|
?int $projectId = null,
|
|
?int $taskId = null,
|
|
?array $tagIds = null,
|
|
?string $description = null,
|
|
): string {
|
|
if (!$this->security->isGranted('ROLE_USER')) {
|
|
throw new AccessDeniedException('Access denied: ROLE_USER required.');
|
|
}
|
|
|
|
$entry = $this->timeEntryRepository->findById($id);
|
|
|
|
if (null === $entry) {
|
|
throw new InvalidArgumentException(sprintf('TimeEntry with ID %d not found.', $id));
|
|
}
|
|
|
|
if (null !== $title) {
|
|
$entry->setTitle($title);
|
|
}
|
|
if (null !== $startedAt) {
|
|
$entry->setStartedAt(new DateTimeImmutable($startedAt));
|
|
}
|
|
if (null !== $stoppedAt) {
|
|
$entry->setStoppedAt(new DateTimeImmutable($stoppedAt));
|
|
}
|
|
if (null !== $description) {
|
|
$entry->setDescription($description);
|
|
}
|
|
if (null !== $projectId) {
|
|
$project = $this->projectRepository->findById($projectId);
|
|
if (null === $project) {
|
|
throw new InvalidArgumentException(sprintf('Project with ID %d not found.', $projectId));
|
|
}
|
|
$entry->setProject($project);
|
|
}
|
|
if (null !== $taskId) {
|
|
$task = $this->taskRepository->findById($taskId);
|
|
if (null === $task) {
|
|
throw new InvalidArgumentException(sprintf('Task with ID %d not found.', $taskId));
|
|
}
|
|
$entry->setTask($task);
|
|
}
|
|
if (null !== $tagIds) {
|
|
foreach ($entry->getTags()->toArray() as $existingTag) {
|
|
$entry->removeTag($existingTag);
|
|
}
|
|
foreach ($tagIds as $tagId) {
|
|
$tag = $this->taskTagRepository->findById($tagId);
|
|
if (null === $tag) {
|
|
throw new InvalidArgumentException(sprintf('TaskTag with ID %d not found.', $tagId));
|
|
}
|
|
$entry->addTag($tag);
|
|
}
|
|
}
|
|
|
|
$this->entityManager->flush();
|
|
|
|
return json_encode(Serializer::timeEntry($entry));
|
|
}
|
|
}
|