feat: add update status endpoint

This commit is contained in:
2025-04-16 16:06:19 +01:00
parent c2e621859e
commit 646655bc50
4 changed files with 72 additions and 3 deletions

View File

@@ -261,4 +261,35 @@ class TaskController
return $errorResponse;
}
}
public function updateStatus(ServerRequestInterface $request, ResponseInterface $response, $id): ResponseInterface
{
try
{
$task = $this->repository->readById($id);
$newCode = $request->getParsedBody()['payload']['status_id'];
if (is_null(TaskStatus::tryFrom($newCode)))
{
$this->builder->setError()->setErrorCode(400)->setErrorMessage('Invalid task status, must be between 1 to 4 (started, in progress, blocked, completed).');
$response->getBody()->write($this->builder->build());
return $response->withStatus(400);
}
$task->setStatusId(TaskStatus::from($newCode));
$this->repository->updateSelective($task, ['status_id']);
return $response->withStatus(204);
} catch (TaskNotFoundException $e)
{
$this->builder->setError()->setErrorCode(404)->setErrorMessage($e->getMessage());
$response->getBody()->write($this->builder->build());
return $response->withStatus(404);
}
}
}