Skip to content

Commit

Permalink
Merge pull request #90 from biglotteryfund/add-data-endpoint
Browse files Browse the repository at this point in the history
Add an endpoint for a single Data page
  • Loading branch information
mattandrews authored Sep 10, 2018
2 parents 5595f6f + 9c80eeb commit cff6ea5
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions config/element-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,47 @@ function getStatRegions($locale)
];
}

/**
* API Endpoint: Data single
*/
function getDataPage($locale)
{
normaliseCacheHeaders();

return [
'serializer' => 'jsonApi',
'elementType' => Entry::class,
'criteria' => [
'site' => $locale,
'section' => 'data',
'status' => EntryHelpers::getVersionStatuses()
],
'one' => true,
'transformer' => function (Entry $entry) use ($locale) {
list('entry' => $entry, 'status' => $status) = EntryHelpers::getDraftOrVersionOfEntry($entry);
$stats = [];
foreach ($entry->stats as $s) {
$stats[] = [
'title' => $s->statTitle,
'value' => $s->statValue,
'showNumberBeforeTitle' => $s->showNumberBeforeTitle,
'suffix' => $s->suffix ?? null,
'prefix' => $s->prefix ?? null
];
}

$data['stats'] = $stats;

return [
'id' => $entry->id,
'title' => $entry->title,
'url' => $entry->url,
'stats' => $stats
];
},
];
}

function getMerchandise($locale)
{
normaliseCacheHeaders();
Expand Down Expand Up @@ -917,8 +958,9 @@ function getMerchandise($locale)
'api/v1/<locale:en|cy>/blog/tags/<tag:{slug}>' => getBlogpostsByTag,
'api/v1/<locale:en|cy>/blog/<categorySlug:{slug}>' => getBlogpostsByCategory,
'api/v1/<locale:en|cy>/blog/<categorySlug:{slug}>/<subCategorySlug:{slug}>' => getBlogpostsByCategory,
'api/v1/<locale:en|cy>/stat-blocks/' => getStatBlocks,
'api/v1/<locale:en|cy>/stat-regions/' => getStatRegions,
'api/v1/<locale:en|cy>/stat-blocks' => getStatBlocks,
'api/v1/<locale:en|cy>/stat-regions' => getStatRegions,
'api/v1/<locale:en|cy>/data' => getDataPage,
'api/v1/<locale:en|cy>/aliases' => getAliases,
'api/v1/<locale:en|cy>/merchandise' => getMerchandise,
'api/v1/list-routes' => getRoutes,
Expand Down

0 comments on commit cff6ea5

Please sign in to comment.