feat: add update status endpoint
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user