1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-09 22:56:46 +02:00

feat(rest-api): fix entries rest api next round #435

This commit is contained in:
Awilum
2020-07-29 23:47:52 +03:00
parent 26e9ffac55
commit 1022e4568e

View File

@@ -62,16 +62,18 @@ $app->get('/api/entries', function (Request $request, Response $response) use ($
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
}
// Fetch entries collection
if ($filter !== null) {
$response_data['data'] = collect_filter($flextype['entries']->fetch($id, true), $filter);
if ($filter === null) {
$response_data['data'] = $flextype['entries']->fetchSingle($id);
} else {
$response_data['data'] = collect_filter($flextype['entries']->fetchCollection($id), $filter);
}
// Fetch single entry
$response_data['data'] = $flextype['entries']->fetch($id);
// Set response code
$response_code = count($response_data['data']) > 0 ? 200 : 404;
if (is_array($response_data['data'])) {
$response_code = count($response_data['data']) > 0 ? 200 : 404;
} else {
$response_code = $response_data['data'] > 0 ? 200 : 404;
}
// Update calls counter
Filesystem::write($entries_token_file_path, $flextype['yaml']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));