Skip to content

Commit

Permalink
Merge pull request #186 from deanblackborough/v2.11.2
Browse files Browse the repository at this point in the history
v2.11.2
  • Loading branch information
deanblackborough authored Jun 16, 2020
2 parents edeb5db + 2f4daf4 commit 7e2e152
Show file tree
Hide file tree
Showing 29 changed files with 320 additions and 97 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

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

## [2.11.1] - 2020-06-16
## [v2.11.2] - 2020-06-17
### Changed
- We have split calls to clear public and private cache keys.
- We only clear public cache keys when modifying a public resource type.
- We have updated the web.config; the web.config file was referring to PHP7.3.
- Added removed class type hints now that we are running PHP7.4.

## [v2.11.1] - 2020-06-16
### Added
- We have added an application cache for collections; we include the ETag header however we are not yet returning a 304.

Expand Down
32 changes: 27 additions & 5 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
class CategoryController extends Controller
{
protected $allow_entire_collection = true;
protected bool $allow_entire_collection = true;

/**
* Return the categories collection
Expand Down Expand Up @@ -281,7 +281,15 @@ public function create($resource_type_id): JsonResponse
]);
$category->save();

$cache_control->clearMatchingKeys([$cache_key->categories($resource_type_id)]);
$cache_control->clearPrivateCacheKeys([
$cache_key->categories($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->categories($resource_type_id)
]);
}
} catch (Exception $e) {
\App\Response\Responses::failedToSaveModelForCreate();
}
Expand Down Expand Up @@ -317,7 +325,15 @@ public function delete(

try {
(new Category())->find($category_id)->delete();
$cache_control->clearMatchingKeys([$cache_key->categories($resource_type_id)]);
$cache_control->clearPrivateCacheKeys([
$cache_key->categories($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->categories($resource_type_id)
]);
}

\App\Response\Responses::successNoContent();
} catch (QueryException $e) {
Expand Down Expand Up @@ -375,12 +391,18 @@ public function update($resource_type_id, $category_id): JsonResponse
try {
$category->save();

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
// We need to clear categories, resource type items
// and items dur to includes so simpler to clear the entire
// and items due to includes so simpler to clear the entire
// resource type
$cache_key->resourceType($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->resourceType($resource_type_id)
]);
}
} catch (Exception $e) {
\App\Response\Responses::failedToSaveModelForUpdate();
}
Expand Down
23 changes: 9 additions & 14 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@

namespace App\Http\Controllers;

use App\Models\ResourceType;
use App\Models\ResourceTypeAccess;
use App\Utilities\Hash;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
/**
* @var Hash
*/
protected $hash;
protected Hash $hash;

/**
* @var boolean Include public content
*/
protected $include_public;
protected bool $include_public;

/**
* @var array Permitted resource types
*/
protected $permitted_resource_types = [];
protected array $permitted_resource_types = [];

protected array $public_resource_types = [];

/**
* @var integer|null
*/
protected $user_id = null;
protected ?int $user_id = null;

/**
* @var bool Allow the entire collection to be returned ignoring pagination
*/
protected $allow_entire_collection = false;
protected bool $allow_entire_collection = false;

public function __construct()
{
Expand All @@ -50,6 +44,7 @@ protected function setHelperProperties()
if (auth()->guard('api')->check() === true && auth('api')->user() !== null) {
$this->user_id = auth('api')->user()->id;
$this->permitted_resource_types = (new ResourceTypeAccess())->permittedResourceTypes($this->user_id);
$this->public_resource_types = (new ResourceType())->publicResourceTypes();
}

$this->include_public = true;
Expand Down
18 changes: 16 additions & 2 deletions app/Http/Controllers/ItemCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,17 @@ public function create(
]);
$item_category->save();

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);
}
} catch (Exception $e) {
\App\Response\Responses::failedToSaveModelForCreate();
}
Expand Down Expand Up @@ -367,11 +374,18 @@ public function delete(
try {
(new ItemCategory())->find($item_category_id)->delete();

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);
}

\App\Response\Responses::successNoContent();
} catch (QueryException $e) {
\App\Response\Responses::foreignKeyConstraintError();
Expand Down
27 changes: 24 additions & 3 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,18 @@ public function create(

$item_type = $item_interface->create((int) $item->id);

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->resourceTypeItems($resource_type_id),
$cache_key->items($resource_type_id, $resource_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->resourceTypeItems($resource_type_id),
$cache_key->items($resource_type_id, $resource_id)
]);
}

} catch (Exception $e) {
\App\Response\Responses::failedToSaveModelForCreate();
}
Expand Down Expand Up @@ -420,10 +427,17 @@ public function update(
$item_interface->update(request()->all(), $item_type);
}

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->resourceTypeItems($resource_type_id),
$cache_key->items($resource_type_id, $resource_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->resourceTypeItems($resource_type_id),
$cache_key->items($resource_type_id, $resource_id)
]);
}
} catch (Exception $e) {
\App\Response\Responses::failedToSaveModelForUpdate();
}
Expand Down Expand Up @@ -477,11 +491,18 @@ public function delete(
$item_type->delete();
$item->delete();

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->resourceTypeItems($resource_type_id),
$cache_key->items($resource_type_id, $resource_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->resourceTypeItems($resource_type_id),
$cache_key->items($resource_type_id, $resource_id)
]);
}

\App\Response\Responses::successNoContent();
} catch (QueryException $e) {
\App\Response\Responses::foreignKeyConstraintError();
Expand Down
21 changes: 19 additions & 2 deletions app/Http/Controllers/ItemPartialTransferController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,16 @@ public function delete(

if ($partial_transfer !== null) {
$partial_transfer->delete();
$cache_control->clearMatchingKeys([$cache_key->partialTransfers($resource_type_id)]);

$cache_control->clearPrivateCacheKeys([
$cache_key->partialTransfers($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->partialTransfers($resource_type_id)
]);
}

return \App\Response\Responses::successNoContent();
}
Expand Down Expand Up @@ -219,7 +228,15 @@ public function transfer(
]);
$partial_transfer->save();

$cache_control->clearMatchingKeys([$cache_key->partialTransfers($resource_type_id)]);
$cache_control->clearPrivateCacheKeys([
$cache_key->partialTransfers($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->partialTransfers($resource_type_id)
]);
}
} catch (QueryException $e) {
return \App\Response\Responses::foreignKeyConstraintError();
} catch (Exception $e) {
Expand Down
18 changes: 16 additions & 2 deletions app/Http/Controllers/ItemSubcategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,17 @@ public function create(
]);
$item_sub_category->save();

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);
}
} catch (Exception $e) {
\App\Response\Responses::failedToSaveModelForCreate();
}
Expand Down Expand Up @@ -416,11 +423,18 @@ public function delete(
try {
(new ItemSubcategory())->find($item_subcategory_id)->delete();

$cache_control->clearMatchingKeys([
$cache_control->clearPrivateCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->items($resource_type_id, $resource_id),
$cache_key->resourceTypeItems($resource_type_id)
]);
}

\App\Response\Responses::successNoContent();
} catch (QueryException $e) {
\App\Response\Responses::foreignKeyConstraintError();
Expand Down
10 changes: 9 additions & 1 deletion app/Http/Controllers/ItemTransferController.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,15 @@ public function transfer(
]);
$item_transfer->save();

$cache_control->clearMatchingKeys([$cache_key->transfers($resource_type_id)]);
$cache_control->clearPrivateCacheKeys([
$cache_key->transfers($resource_type_id)
]);

if (in_array($resource_type_id, $this->public_resource_types, true)) {
$cache_control->clearPublicCacheKeys([
$cache_key->transfers($resource_type_id)
]);
}
} catch (QueryException $e) {
return \App\Response\Responses::foreignKeyConstraintError();
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ItemTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class ItemTypeController extends Controller
{
protected $allow_entire_collection = true;
protected bool $allow_entire_collection = true;

/**
* Return all the item types
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PermittedUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class PermittedUserController extends Controller
{
protected $allow_entire_collection = true;
protected bool $allow_entire_collection = true;

/**
* Return all the permitted users for the given resource type
Expand Down
Loading

0 comments on commit 7e2e152

Please sign in to comment.