Skip to content

Commit

Permalink
Merge pull request #209 from deanblackborough/v2.17.1
Browse files Browse the repository at this point in the history
v2.17.1
  • Loading branch information
deanblackborough authored Nov 28, 2020
2 parents 84755d5 + 25ec803 commit f46a642
Show file tree
Hide file tree
Showing 107 changed files with 1,666 additions and 749 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [v2.17.1] - 2020-11-28
### Changed
- We have added the `X-Last-Updated` header to the `resource-types`, `resources`, `categories`, `subcategories`, `items` and `resource items` collection routes.
- We have added the `X-Last-Updated` header to additional summary routes; the header was missing, and we are going to use it.
- We have increased the coverage of our request test suite.
- We have relocated our `Transformer` classes; we have moved them out of the `Models` namespace.

### Fixed
- We have updated the way we calculated the value for `X-Last-Updated`. We are using the max of the `created at` and `updated at`, not just looking at the `created at` time.

## [v2.17.0] - 2020-11-22
### Added
- We have added a `complete` parameter for the `game` item-type; when the parameter is included and set to true, only complete games will be returned in collections and summaries.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CategoryManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Request\BodyValidation;
Use App\Response\Cache;
use App\Models\Category;
use App\Models\Transformers\Category as CategoryTransformer;
use App\Transformers\Category as CategoryTransformer;
use App\Request\Validate\Category as CategoryValidator;
use App\Response\Responses;
use Exception;
Expand Down
22 changes: 16 additions & 6 deletions app/Http/Controllers/CategoryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Response\Header\Headers;
use App\Response\Pagination as UtilityPagination;
use App\Models\Category;
use App\Models\Transformers\Category as CategoryTransformer;
use App\Transformers\Category as CategoryTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;

Expand Down Expand Up @@ -77,6 +77,11 @@ public function index($resource_type_id): JsonResponse
$sort_parameters
);

$last_updated = null;
if (count($categories) && array_key_exists('last_updated', $categories[0])) {
$last_updated = $categories[0]['last_updated'];
}

$collection = array_map(
static function ($category) {
return (new CategoryTransformer($category))->asArray();
Expand All @@ -85,11 +90,16 @@ static function ($category) {
);

$headers = new Headers();
$headers->collection($pagination_parameters, count($categories), $total)->
addCacheControl($cache_control->visibility(), $cache_control->ttl())->
addETag($collection)->
addSearch(Parameter\Search::xHeader())->
addSort(Parameter\Sort::xHeader());
$headers
->collection($pagination_parameters, count($categories), $total)
->addCacheControl($cache_control->visibility(), $cache_control->ttl())
->addETag($collection)
->addSearch(Parameter\Search::xHeader())
->addSort(Parameter\Sort::xHeader());

if ($last_updated !== null) {
$headers->addLastUpdated($last_updated);
}

$cache_collection->create($total, $collection, $pagination_parameters, $headers->headers());
$cache_control->putByKey(request()->getRequestUri(), $cache_collection->content());
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CurrencyView.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Response\Header\Headers;
use App\Request\Parameter;
use App\Response\Pagination as UtilityPagination;
use App\Models\Transformers\Currency as CurrencyTransformer;
use App\Transformers\Currency as CurrencyTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemCategoryManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\ItemType\Entity;
use App\Jobs\ClearCache;
use App\Models\ItemCategory;
use App\Models\Transformers\ItemCategory as ItemCategoryTransformer;
use App\Transformers\ItemCategory as ItemCategoryTransformer;
use App\Request\Validate\ItemCategory as ItemCategoryValidator;
use App\Response\Cache;
use Exception;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemCategoryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\ItemType\Entity;
use App\Models\ItemCategory;
use App\Models\Transformers\ItemCategory as ItemCategoryTransformer;
use App\Transformers\ItemCategory as ItemCategoryTransformer;
use App\Option\ItemCategoryCollection;
use App\Option\ItemCategoryItem;
use App\Response\Cache;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemPartialTransferManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Jobs\ClearCache;
use App\Models\ItemPartialTransfer;
use App\Models\Transformers\ItemPartialTransfer as ItemPartialTransferTransformer;
use App\Transformers\ItemPartialTransfer as ItemPartialTransferTransformer;
use App\Response\Cache;
use App\Request\Validate\ItemPartialTransfer as ItemPartialTransferValidator;
use App\Response\Responses;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemPartialTransferView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\ItemType\Entity;
use App\Models\ItemPartialTransfer;
use App\Models\Transformers\ItemPartialTransfer as ItemPartialTransferTransformer;
use App\Transformers\ItemPartialTransfer as ItemPartialTransferTransformer;
use App\Option\ItemPartialTransferCollection;
use App\Option\ItemPartialTransferItem;
use App\Option\ItemPartialTransferTransfer;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemSubcategoryManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Jobs\ClearCache;
use App\Models\ItemCategory;
use App\Models\ItemSubcategory;
use App\Models\Transformers\ItemSubcategory as ItemSubcategoryTransformer;
use App\Transformers\ItemSubcategory as ItemSubcategoryTransformer;
use App\Request\Validate\ItemSubcategory as ItemSubcategoryValidator;
use App\Response\Cache;
use Exception;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemSubcategoryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\ItemType\Entity;
use App\Models\ItemCategory;
use App\Models\ItemSubcategory;
use App\Models\Transformers\ItemSubcategory as ItemSubcategoryTransformer;
use App\Transformers\ItemSubcategory as ItemSubcategoryTransformer;
use App\Option\ItemSubcategoryCollection;
use App\Option\ItemSubcategoryItem;
use App\Response\Cache;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemSubtypeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Request\Route;
use App\Response\Header\Headers;
use App\Response\Pagination as UtilityPagination;
use App\Models\Transformers\ItemSubtype as ItemSubtypeTransformer;
use App\Transformers\ItemSubtype as ItemSubtypeTransformer;
use App\Response\Responses;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemTransferView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers;

use App\Models\ItemTransfer;
use App\Models\Transformers\ItemTransfer as ItemTransferTransformer;
use App\Transformers\ItemTransfer as ItemTransferTransformer;
use App\Option\ItemTransferCollection;
use App\Option\ItemTransferItem;
use App\Option\ItemTransferTransfer;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemTypeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Request\Parameter;
use App\Request\Route;
use App\Response\Pagination as UtilityPagination;
use App\Models\Transformers\ItemType as ItemTypeTransformer;
use App\Transformers\ItemType as ItemTypeTransformer;
use App\Response\Responses;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PermittedUserView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers;

use App\Models\PermittedUser;
use App\Models\Transformers\PermittedUser as PermittedUserTransformer;
use App\Transformers\PermittedUser as PermittedUserTransformer;
use App\Option\PermittedUserCollection;
use App\Response\Cache;
use App\Request\Parameter;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/QueueView.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Request\Parameter;
use App\Request\Route;
use App\Response\Pagination as UtilityPagination;
use App\Models\Transformers\Queue as QueueTransformer;
use App\Transformers\Queue as QueueTransformer;
use Illuminate\Http\JsonResponse;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RequestView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Option\ErrorLog;
use App\Models\RequestErrorLog;
use App\Models\Transformers\RequestErrorLog as RequestErrorLogTransformer;
use App\Transformers\RequestErrorLog as RequestErrorLogTransformer;
use App\Response\Pagination as UtilityPagination;
use Illuminate\Http\JsonResponse;

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ResourceManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Models\ResourceType;
use App\Response\Cache;
use App\Models\Resource;
use App\Models\Transformers\Resource as ResourceTransformer;
use App\Transformers\Resource as ResourceTransformer;
use App\Request\Validate\Resource as ResourceValidator;
use App\Response\Responses;
use Exception;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ResourceTypeManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Models\ResourceTypeItemType;
use App\Response\Cache;
use App\Models\ResourceType;
use App\Models\Transformers\ResourceType as ResourceTypeTransformer;
use App\Transformers\ResourceType as ResourceTypeTransformer;
use App\Request\Validate\ResourceType as ResourceTypeValidator;
use Exception;
use Illuminate\Database\QueryException;
Expand Down
11 changes: 10 additions & 1 deletion app/Http/Controllers/ResourceTypeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Request\Parameter;
use App\Response\Pagination as UtilityPagination;
use App\Models\ResourceType;
use App\Models\Transformers\ResourceType as ResourceTypeTransformer;
use App\Transformers\ResourceType as ResourceTypeTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;

Expand Down Expand Up @@ -64,6 +64,11 @@ public function index(): JsonResponse
$sort_parameters
);

$last_updated = null;
if (count($resource_types) && array_key_exists('last_updated', $resource_types[0])) {
$last_updated = $resource_types[0]['last_updated'];
}

$collection = array_map(
static function ($resource_type) {
return (new ResourceTypeTransformer($resource_type))->asArray();
Expand All @@ -79,6 +84,10 @@ static function ($resource_type) {
->addSearch(Parameter\Search::xHeader())
->addSort(Parameter\Sort::xHeader());

if ($last_updated !== null) {
$headers->addLastUpdated($last_updated);
}

$cache_collection->create($total, $collection, $pagination_parameters, $headers->headers());
$cache_control->putByKey(request()->getRequestUri(), $cache_collection->content());
}
Expand Down
22 changes: 16 additions & 6 deletions app/Http/Controllers/ResourceView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use App\Response\Header\Headers;
use App\Response\Pagination as UtilityPagination;
use App\Models\Resource;
use App\Models\Transformers\Resource as ResourceTransformer;
use App\Transformers\Resource as ResourceTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;

Expand Down Expand Up @@ -79,6 +79,11 @@ public function index(string $resource_type_id): JsonResponse
$sort_parameters
);

$last_updated = null;
if (count($resources) && array_key_exists('last_updated', $resources[0])) {
$last_updated = $resources[0]['last_updated'];
}

$collection = array_map(
static function ($resource) {
return (new ResourceTransformer($resource))->asArray();
Expand All @@ -87,11 +92,16 @@ static function ($resource) {
);

$headers = new Headers();
$headers->collection($pagination_parameters, count($resources), $total)->
addCacheControl($cache_control->visibility(), $cache_control->ttl())->
addETag($collection)->
addSearch(Parameter\Search::xHeader())->
addSort(Parameter\Sort::xHeader());
$headers
->collection($pagination_parameters, count($resources), $total)
->addCacheControl($cache_control->visibility(), $cache_control->ttl())
->addETag($collection)
->addSearch(Parameter\Search::xHeader())
->addSort(Parameter\Sort::xHeader());

if ($last_updated !== null) {
$headers->addLastUpdated($last_updated);
}

$cache_collection->create($total, $collection, $pagination_parameters, $headers->headers());
$cache_control->putByKey(request()->getRequestUri(), $cache_collection->content());
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SubcategoryManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Jobs\ClearCache;
use App\Response\Cache;
use App\Models\Subcategory;
use App\Models\Transformers\Subcategory as SubcategoryTransformer;
use App\Transformers\Subcategory as SubcategoryTransformer;
use App\Request\Validate\Subcategory as SubcategoryValidator;
use App\Response\Responses;
use Exception;
Expand Down
22 changes: 16 additions & 6 deletions app/Http/Controllers/SubcategoryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Response\Header\Headers;
use App\Response\Pagination as UtilityPagination;
use App\Models\Subcategory;
use App\Models\Transformers\Subcategory as SubcategoryTransformer;
use App\Transformers\Subcategory as SubcategoryTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;

Expand Down Expand Up @@ -71,6 +71,11 @@ public function index($resource_type_id, $category_id): JsonResponse
$sort_parameters
);

$last_updated = null;
if (count($subcategories) && array_key_exists('last_updated', $subcategories[0])) {
$last_updated = $subcategories[0]['last_updated'];
}

$collection = array_map(
static function ($subcategory) {
return (new SubcategoryTransformer($subcategory))->asArray();
Expand All @@ -79,11 +84,16 @@ static function ($subcategory) {
);

$headers = new Headers();
$headers->collection($pagination_parameters, count($subcategories), $total)->
addCacheControl($cache_control->visibility(), $cache_control->ttl())->
addETag($collection)->
addSearch(Parameter\Search::xHeader())->
addSort(Parameter\Sort::xHeader());
$headers
->collection($pagination_parameters, count($subcategories), $total)
->addCacheControl($cache_control->visibility(), $cache_control->ttl())
->addETag($collection)
->addSearch(Parameter\Search::xHeader())
->addSort(Parameter\Sort::xHeader());

if ($last_updated !== null) {
$headers->addLastUpdated($last_updated);
}

$cache_collection->create($total, $collection, $pagination_parameters, $headers->headers());
$cache_control->putByKey(request()->getRequestUri(), $cache_collection->content());
Expand Down
23 changes: 19 additions & 4 deletions app/Http/Controllers/Summary/CategoryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,29 @@ public function index($resource_type_id): JsonResponse
$search_parameters
);

$total = 0;
$last_updated = null;
if (count($summary) === 1 && array_key_exists('total', $summary[0])) {
$total = (int) $summary[0]['total'];

if (array_key_exists('last_updated', $summary[0])) {
$last_updated = $summary[0]['last_updated'];
}
}

$collection = [
'categories' => $summary
'categories' => $total
];

$headers = new Headers();
$headers->addCacheControl($cache_control->visibility(), $cache_control->ttl())->
addETag($collection)->
addSearch(Parameter\Search::xHeader());
$headers
->addCacheControl($cache_control->visibility(), $cache_control->ttl())
->addETag($collection)
->addSearch(Parameter\Search::xHeader());

if ($last_updated !== null) {
$headers->addLastUpdated($last_updated);
}

$cache_summary->create($collection, $headers->headers());
$cache_control->putByKey(request()->getRequestUri(), $cache_summary->content());
Expand Down
23 changes: 19 additions & 4 deletions app/Http/Controllers/Summary/ResourceTypeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,29 @@ public function index(): JsonResponse
$search_parameters
);

$total = 0;
$last_updated = null;
if (count($summary) === 1 && array_key_exists('total', $summary[0])) {
$total = (int) $summary[0]['total'];

if (array_key_exists('last_updated', $summary[0])) {
$last_updated = $summary[0]['last_updated'];
}
}

$collection = [
'resource_types' => $summary
'resource_types' => $total
];

$headers = new Headers();
$headers->addCacheControl($cache_control->visibility(), $cache_control->ttl())->
addETag($collection)->
addSearch(Parameter\Search::xHeader());
$headers
->addCacheControl($cache_control->visibility(), $cache_control->ttl())
->addETag($collection)
->addSearch(Parameter\Search::xHeader());

if ($last_updated !== null) {
$headers->addLastUpdated($last_updated);
}

$cache_summary->create($collection, $headers->headers());
$cache_control->putByKey(request()->getRequestUri(), $cache_summary->content());
Expand Down
Loading

0 comments on commit f46a642

Please sign in to comment.