try to follow to HATEOAS.

This commit is contained in:
abdulmohsen
2024-03-05 19:17:52 +03:00
parent e30819a950
commit d7d62b622f
9 changed files with 183 additions and 55 deletions

View File

@@ -19,12 +19,22 @@ final class View
return api_error('No id was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
}
$apiUrl = $request->getUri()->withHost('')->withPort(0)->withScheme('');
$task = TasksCommand::getTasks($id);
if (empty($task)) {
return api_error('Task not found.', HTTP_STATUS::HTTP_NOT_FOUND);
}
return api_response(Index::formatTask($task), HTTP_STATUS::HTTP_OK);
$response = [
...Index::formatTask($task),
'links' => [
'self' => (string)$apiUrl,
'list' => (string)$apiUrl->withPath(parseConfigValue(Index::URL)),
],
];
return api_response($response, HTTP_STATUS::HTTP_OK);
}
}