From 7620025bdf7183c77be09cd2d2828e41df539463 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Tue, 14 Jun 2022 12:06:12 +0100 Subject: [PATCH 01/32] Remove echo - Remove an echo from a test --- tests/Feature/Http/Controllers/CategoryManageTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Feature/Http/Controllers/CategoryManageTest.php b/tests/Feature/Http/Controllers/CategoryManageTest.php index c0045368..0dd43a0a 100644 --- a/tests/Feature/Http/Controllers/CategoryManageTest.php +++ b/tests/Feature/Http/Controllers/CategoryManageTest.php @@ -226,8 +226,6 @@ public function update_category_fails_non_unique_name(): void ] ); - echo $response->content(); - $response->assertStatus(422); } From 24d23683e0cee959932ffed6a1029386b4cbcdfa Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Tue, 14 Jun 2022 12:14:14 +0100 Subject: [PATCH 02/32] Rename Tests - Rename the tests folder and correct the namespaces --- {tests => Tests}/CreatesApplication.php | 0 .../Feature/Http/Controllers/AuthenticationTest.php | 0 .../Feature/Http/Controllers/CategoryManageTest.php | 0 .../Feature/Http/Controllers/PermittedUserManageTest.php | 0 .../Feature/Http/Controllers/ResourceManageTest.php | 0 .../Feature/Http/Controllers/ResourceTypeManageTest.php | 0 {tests => Tests}/TestCase.php | 0 {tests => Tests}/View/Http/Controllers/AuthenticationTest.php | 0 .../View/Http/Controllers/PermittedUserViewTest.php | 0 {tests => Tests}/View/Http/Controllers/ResourceTypeViewTest.php | 0 composer.json | 2 +- 11 files changed, 1 insertion(+), 1 deletion(-) rename {tests => Tests}/CreatesApplication.php (100%) rename {tests => Tests}/Feature/Http/Controllers/AuthenticationTest.php (100%) rename {tests => Tests}/Feature/Http/Controllers/CategoryManageTest.php (100%) rename {tests => Tests}/Feature/Http/Controllers/PermittedUserManageTest.php (100%) rename {tests => Tests}/Feature/Http/Controllers/ResourceManageTest.php (100%) rename {tests => Tests}/Feature/Http/Controllers/ResourceTypeManageTest.php (100%) rename {tests => Tests}/TestCase.php (100%) rename {tests => Tests}/View/Http/Controllers/AuthenticationTest.php (100%) rename {tests => Tests}/View/Http/Controllers/PermittedUserViewTest.php (100%) rename {tests => Tests}/View/Http/Controllers/ResourceTypeViewTest.php (100%) diff --git a/tests/CreatesApplication.php b/Tests/CreatesApplication.php similarity index 100% rename from tests/CreatesApplication.php rename to Tests/CreatesApplication.php diff --git a/tests/Feature/Http/Controllers/AuthenticationTest.php b/Tests/Feature/Http/Controllers/AuthenticationTest.php similarity index 100% rename from tests/Feature/Http/Controllers/AuthenticationTest.php rename to Tests/Feature/Http/Controllers/AuthenticationTest.php diff --git a/tests/Feature/Http/Controllers/CategoryManageTest.php b/Tests/Feature/Http/Controllers/CategoryManageTest.php similarity index 100% rename from tests/Feature/Http/Controllers/CategoryManageTest.php rename to Tests/Feature/Http/Controllers/CategoryManageTest.php diff --git a/tests/Feature/Http/Controllers/PermittedUserManageTest.php b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php similarity index 100% rename from tests/Feature/Http/Controllers/PermittedUserManageTest.php rename to Tests/Feature/Http/Controllers/PermittedUserManageTest.php diff --git a/tests/Feature/Http/Controllers/ResourceManageTest.php b/Tests/Feature/Http/Controllers/ResourceManageTest.php similarity index 100% rename from tests/Feature/Http/Controllers/ResourceManageTest.php rename to Tests/Feature/Http/Controllers/ResourceManageTest.php diff --git a/tests/Feature/Http/Controllers/ResourceTypeManageTest.php b/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php similarity index 100% rename from tests/Feature/Http/Controllers/ResourceTypeManageTest.php rename to Tests/Feature/Http/Controllers/ResourceTypeManageTest.php diff --git a/tests/TestCase.php b/Tests/TestCase.php similarity index 100% rename from tests/TestCase.php rename to Tests/TestCase.php diff --git a/tests/View/Http/Controllers/AuthenticationTest.php b/Tests/View/Http/Controllers/AuthenticationTest.php similarity index 100% rename from tests/View/Http/Controllers/AuthenticationTest.php rename to Tests/View/Http/Controllers/AuthenticationTest.php diff --git a/tests/View/Http/Controllers/PermittedUserViewTest.php b/Tests/View/Http/Controllers/PermittedUserViewTest.php similarity index 100% rename from tests/View/Http/Controllers/PermittedUserViewTest.php rename to Tests/View/Http/Controllers/PermittedUserViewTest.php diff --git a/tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php similarity index 100% rename from tests/View/Http/Controllers/ResourceTypeViewTest.php rename to Tests/View/Http/Controllers/ResourceTypeViewTest.php diff --git a/composer.json b/composer.json index fa95c44e..e533b0d8 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\": "tests/" + "Tests\\": "Tests/" } }, "extra": { From 9d2f94d959a960fe26f05293759187c149491a26 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Tue, 14 Jun 2022 12:54:20 +0100 Subject: [PATCH 03/32] Subcategory tests - Check for invalid decodes in middleware - Started subcategory tests. - Named routes --- .../Controllers/SubcategoryManagerTest.php | 46 +++++++++++++++++++ Tests/TestCase.php | 14 ++++++ app/Http/Middleware/ConvertGetParameters.php | 3 +- .../Middleware/ConvertRouteParameters.php | 12 ++++- routes/api/private-routes.php | 13 +++--- 5 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 Tests/Feature/Http/Controllers/SubcategoryManagerTest.php diff --git a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php new file mode 100644 index 00000000..032cecba --- /dev/null +++ b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php @@ -0,0 +1,46 @@ +actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $this->faker->text(200), + ] + ); + + $response->assertStatus(422); + } + + /** @test */ + public function create_subcategory_forbidden_when_category_id_invalid(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + + $response = $this->postSubcategory( + $resource_type_id, + 'wwwwwwwwww', + [ + 'name' => $this->faker->text(200), + ] + ); + + $response->assertStatus(403); + } +} diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 16aa13a4..a906c278 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -239,6 +239,20 @@ protected function postResourceType(array $payload): TestResponse return $this->post(route('resource-type.create'), $payload); } + protected function postSubcategory(string $resource_type_id, string $category_id, array $payload): TestResponse + { + return $this->post( + route( + 'subcategory.create', + [ + 'resource_type_id' => $resource_type_id, + 'category_id' => $category_id + ] + ), + $payload + ); + } + protected function setUp(): void { parent::setUp(); diff --git a/app/Http/Middleware/ConvertGetParameters.php b/app/Http/Middleware/ConvertGetParameters.php index 74b27ecd..608830fc 100644 --- a/app/Http/Middleware/ConvertGetParameters.php +++ b/app/Http/Middleware/ConvertGetParameters.php @@ -3,6 +3,7 @@ namespace App\Http\Middleware; use App\HttpRequest\Hash; +use App\HttpResponse\Responses; use Closure; use Illuminate\Http\Request; @@ -37,7 +38,7 @@ public function handle($request, Closure $next) $param_value = $request->query($param); if ($param_value !== null) { $id = $hash->decode($param, $param_value); - is_int($id) ? $value = $id : $value = null; + ($id !== false && is_int($id)) ? $value = $id : $value = null; $request->request->add([$param => $value]); } } diff --git a/app/Http/Middleware/ConvertRouteParameters.php b/app/Http/Middleware/ConvertRouteParameters.php index bb83e6d7..8ccf7cb2 100644 --- a/app/Http/Middleware/ConvertRouteParameters.php +++ b/app/Http/Middleware/ConvertRouteParameters.php @@ -49,8 +49,16 @@ public function handle($request, Closure $next) $param_value = $request->route($param); if ($param_value !== null) { $id = $hash->decode($route_params[$param], $param_value); - is_int($id) ? $value = $id : Responses::notFoundOrNotAccessible($route_params[$param]); - $request->route()->setParameter($param, $value); + + if ($id === false) { + return Responses::notFoundOrNotAccessible($route_params[$param]); + } + + if (is_int($id) === false) { + return Responses::notFoundOrNotAccessible($route_params[$param]); + } + + $request->route()->setParameter($param, $id); } } diff --git a/routes/api/private-routes.php b/routes/api/private-routes.php index 02f2b484..e895cc7c 100644 --- a/routes/api/private-routes.php +++ b/routes/api/private-routes.php @@ -4,6 +4,7 @@ use App\Http\Controllers\PermittedUserManage; use App\Http\Controllers\ResourceManage; use App\Http\Controllers\ResourceTypeManage; +use App\Http\Controllers\SubcategoryManage; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Route; @@ -33,8 +34,8 @@ static function () { Route::post( 'resource-types/{resource_type_id}/categories/{category_id}/subcategories', - 'SubcategoryManage@create' - ); + [SubcategoryManage::class, 'create'] + )->name('subcategory.create'); Route::post( 'resource-types/{resource_type_id}/permitted-users', @@ -88,8 +89,8 @@ static function () { Route::delete( 'resource-types/{resource_type_id}/categories/{category_id}/subcategories/{subcategory_id}', - 'SubcategoryManage@delete' - ); + [SubcategoryManage::class, 'delete'] + )->name('subcategory.delete'); Route::delete( 'resource-types/{resource_type_id}/partial-transfers/{item_partial_transfer_id}', @@ -128,8 +129,8 @@ static function () { Route::patch( 'resource-types/{resource_type_id}/categories/{category_id}/subcategories/{subcategory_id}', - 'SubcategoryManage@update' - ); + [SubcategoryManage::class, 'update'] + )->name('subcategory.update'); Route::patch( 'resource-types/{resource_type_id}/resources/{resource_id}', From 88327d32d239204a63c88015252614fb0b9785e1 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Tue, 14 Jun 2022 14:51:13 +0100 Subject: [PATCH 04/32] Subcategory tests - Added subcategory tests. - Correct vars in category tests --- README.md | 4 +- .../Http/Controllers/CategoryManageTest.php | 14 +- .../Controllers/SubcategoryManagerTest.php | 241 ++++++++++++++++++ Tests/TestCase.php | 53 ++++ composer.lock | 2 +- 5 files changed, 304 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 15b2ee48..2abde3d1 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,7 @@ our local test suite is as complete as the Postman request tests. | ResourceManage (Actions) | Complete (14 Tests) | | ResourceTypeManage (Actions) | Complete (14 Tests) | | ResourceTypeView (Responses) | In Progress (3 Tests) | -| SubcategoryManage (Actions) | Not started | +| SubcategoryManage (Actions) | Complete (12 Tests) | | ToolManage (Actions) | Not started | | Summaries (Responses) | Not started | -| Total | In Progress (84 Tests) | +| Total | In Progress (96 Tests) | diff --git a/Tests/Feature/Http/Controllers/CategoryManageTest.php b/Tests/Feature/Http/Controllers/CategoryManageTest.php index 0dd43a0a..b634684e 100644 --- a/Tests/Feature/Http/Controllers/CategoryManageTest.php +++ b/Tests/Feature/Http/Controllers/CategoryManageTest.php @@ -156,11 +156,11 @@ public function update_category_fails_extra_fields_in_payload(): void $this->actingAs(User::find(1)); $resource_type_id = $this->createAndReturnResourceTypeId(); - $resource_id = $this->createAndReturnCategoryId($resource_type_id); + $category_id = $this->createAndReturnCategoryId($resource_type_id); $response = $this->patchCategory( $resource_type_id, - $resource_id, + $category_id, [ 'extra' => $this->faker->text(100) ] @@ -170,16 +170,16 @@ public function update_category_fails_extra_fields_in_payload(): void } /** @test */ - public function update_category_fails_non_payload(): void + public function update_category_fails_no_payload(): void { $this->actingAs(User::find(1)); $resource_type_id = $this->createAndReturnResourceTypeId(); - $resource_id = $this->createAndReturnCategoryId($resource_type_id); + $category_id = $this->createAndReturnCategoryId($resource_type_id); $response = $this->patchCategory( $resource_type_id, - $resource_id, + $category_id, [] ); @@ -235,11 +235,11 @@ public function update_category_success(): void $this->actingAs(User::find(1)); $resource_type_id = $this->createAndReturnResourceTypeId(); - $resource_id = $this->createAndReturnCategoryId($resource_type_id); + $category_id = $this->createAndReturnCategoryId($resource_type_id); $response = $this->patchCategory( $resource_type_id, - $resource_id, + $category_id, [ 'name' => $this->faker->text(25) ] diff --git a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php index 032cecba..6f79d8a2 100644 --- a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php +++ b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php @@ -27,6 +27,56 @@ public function create_subcategory_fails_no_description_in_payload(): void } /** @test */ + public function create_subcategory_fails_no_payload(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [] + ); + + $response->assertStatus(422); + } + + /** @test */ + public function create_subcategory_fails_non_unique_name(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $name = $this->faker->text(); + + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $name, + 'description' => $this->faker->text() + ] + ); + + $response->assertStatus(201); + + // Create another with the same name + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $name, + 'description' => $this->faker->text() + ] + ); + + $response->assertStatus(422); + } + + /** @test */ public function create_subcategory_forbidden_when_category_id_invalid(): void { $this->actingAs(User::find(1)); @@ -43,4 +93,195 @@ public function create_subcategory_forbidden_when_category_id_invalid(): void $response->assertStatus(403); } + + /** @test */ + public function create_subcategory_success(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $this->faker->text(), + 'description' => $this->faker->text() + ] + ); + + $response->assertStatus(201); + } + + /** @test */ + public function delete_subcategory_success(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $subcategory_id = $this->createAndReturnSubcategoryId($resource_type_id, $category_id); + + $response = $this->deleteSubcategory( + $resource_type_id, + $category_id, + $subcategory_id + ); + + $response->assertStatus(204); + } + + /** @test */ + public function update_subcategory_fails_extra_fields_in_payload(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $subcategory_id = $this->createAndReturnSubcategoryId($resource_type_id, $category_id); + + $response = $this->patchSubcategory( + $resource_type_id, + $category_id, + $subcategory_id, + [ + 'extra_field' => $this->faker->text(100) + ] + ); + + $response->assertStatus(400); + } + + /** @test */ + public function update_subcategory_fails_no_payload(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $subcategory_id = $this->createAndReturnSubcategoryId($resource_type_id, $category_id); + + $response = $this->patchSubcategory( + $resource_type_id, + $category_id, + $subcategory_id, + [] + ); + + $response->assertStatus(400); + } + + /** @test */ + public function update_subcategory_fails_non_unique_name(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + + // Create first subcategory + $name = $this->faker->text(200); + + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $name, + 'description' => $this->faker->text(200) + ] + ); + + $response->assertStatus(201); + + // Create second subcategory + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $this->faker->text(200), + 'description' => $this->faker->text(200) + ] + ); + + $response->assertStatus(201); + + $subcategory_id = $response->json('id'); + + // Attempt to set name of second subcategory to first name + $response = $this->patchSubcategory( + $resource_type_id, + $category_id, + $subcategory_id, + [ + 'name' => $name + ] + ); + + $response->assertStatus(422); + } + + /** @test */ + public function update_subcategory_description_success(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $subcategory_id = $this->createAndReturnSubcategoryId($resource_type_id, $category_id); + + $response = $this->patchSubcategory( + $resource_type_id, + $category_id, + $subcategory_id, + [ + 'description' => $this->faker->text(25) + ] + ); + + $response->assertStatus(204); + } + + /** @test */ + public function update_subcategory_name_success(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $subcategory_id = $this->createAndReturnSubcategoryId($resource_type_id, $category_id); + + $response = $this->patchSubcategory( + $resource_type_id, + $category_id, + $subcategory_id, + [ + 'name' => $this->faker->text(25) + ] + ); + + $response->assertStatus(204); + } + + /** @test */ + public function update_subcategory_success(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAndReturnResourceTypeId(); + $category_id = $this->createAndReturnCategoryId($resource_type_id); + $subcategory_id = $this->createAndReturnSubcategoryId($resource_type_id, $category_id); + + $response = $this->patchSubcategory( + $resource_type_id, + $category_id, + $subcategory_id, + [ + 'name' => $this->faker->text(25), + 'description' => $this->faker->text(25) + ] + ); + + $response->assertStatus(204); + } } diff --git a/Tests/TestCase.php b/Tests/TestCase.php index a906c278..212bcc86 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -101,6 +101,24 @@ protected function createAndReturnResourceTypeId(): string $this->fail('Unable to create the resource type'); } + protected function createAndReturnSubcategoryId(string $resource_type_id, string $category_id): string + { + $response = $this->postSubcategory( + $resource_type_id, + $category_id, + [ + 'name' => $this->faker->text(200), + 'description' => $this->faker->text(200), + ] + ); + + if ($response->assertStatus(201)) { + return $response->json('id'); + } + + $this->fail('Unable to create the subcategory'); + } + protected function deleteCategory(string $resource_type_id, $category_id): TestResponse { return $this->delete( @@ -129,6 +147,21 @@ protected function deleteResourceType(string $resource_type_id): TestResponse ); } + protected function deleteSubcategory(string $resource_type_id, $category_id, $subcategory_id): TestResponse + { + return $this->delete( + route( + 'subcategory.delete', + [ + 'resource_type_id' => $resource_type_id, + 'category_id' => $category_id, + 'subcategory_id' => $subcategory_id + ] + ), + [] + ); + } + protected function getARandomUser() { return User::query()->where('id', '!=', 1)->inRandomOrder()->first(); @@ -195,6 +228,26 @@ protected function patchResourceType(string $resource_type_id, array $payload): ); } + protected function patchSubcategory( + string $resource_type_id, + string $category_id, + string $subcategory_id, + array $payload + ): TestResponse + { + return $this->patch( + route( + 'subcategory.update', + [ + 'resource_type_id' => $resource_type_id, + 'category_id' => $category_id, + 'subcategory_id' => $subcategory_id + ] + ), + $payload + ); + } + protected function optionsCreatePassword(array $parameters = []): TestResponse { return $this->optionsRoute('auth.create-password.options', $parameters); diff --git a/composer.lock b/composer.lock index b9adf567..65cfa5f9 100644 --- a/composer.lock +++ b/composer.lock @@ -8740,5 +8740,5 @@ "ext-json": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.1.0" } From 068b3bb98b5cbc695ad660276edaea3b12123c8a Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Wed, 15 Jun 2022 09:29:45 +0100 Subject: [PATCH 05/32] Item type tests - Working on tests for item types --- Tests/TestCase.php | 27 ++- .../Http/Controllers/ItemTypeViewTest.php | 158 ++++++++++++++++++ .../Http/Controllers/ResourceTypeViewTest.php | 2 +- public/api/schema/item-type.json | 20 +-- routes/api/public-routes.php | 4 +- 5 files changed, 192 insertions(+), 19 deletions(-) create mode 100644 Tests/View/Http/Controllers/ItemTypeViewTest.php diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 212bcc86..16eb1204 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -18,14 +18,19 @@ abstract class TestCase extends BaseTestCase protected string $test_user_email = 'test-account-email@email.com'; protected string $test_user_password = 'test-account-secret-password'; - protected function assertJsonIsPermittedUser($content): void + protected function assertJsonIsCategory($content): void { - $this->assertJsonMatchesSchema($content, 'api/schema/permitted-user.json'); + $this->assertJsonMatchesSchema($content, 'api/schema/category.json'); } - protected function assertJsonIsCategory($content): void + protected function assertJsonIsItemType($content): void { - $this->assertJsonMatchesSchema($content, 'api/schema/category.json'); + $this->assertJsonMatchesSchema($content, 'api/schema/item-type.json'); + } + + protected function assertJsonIsPermittedUser($content): void + { + $this->assertJsonMatchesSchema($content, 'api/schema/permitted-user.json'); } protected function assertJsonIsResource($content): void @@ -167,9 +172,14 @@ protected function getARandomUser() return User::query()->where('id', '!=', 1)->inRandomOrder()->first(); } - protected function getRoute(string $route, array $parameters = []): TestResponse + protected function getItemType(array $parameters = []): TestResponse { - return $this->get(route($route, $parameters)); + return $this->getRoute('item-type.show', $parameters); + } + + protected function getItemTypes(array $parameters = []): TestResponse + { + return $this->getRoute('item-type.list', $parameters); } protected function getPermittedUser(array $parameters = []): TestResponse @@ -192,6 +202,11 @@ protected function getResourceTypes(array $parameters = []): TestResponse return $this->getRoute('resource-type.list', $parameters); } + protected function getRoute(string $route, array $parameters = []): TestResponse + { + return $this->get(route($route, $parameters)); + } + protected function patchCategory(string $resource_type_id, string $category_id, array $payload): TestResponse { return $this->patch( diff --git a/Tests/View/Http/Controllers/ItemTypeViewTest.php b/Tests/View/Http/Controllers/ItemTypeViewTest.php new file mode 100644 index 00000000..1d0e8045 --- /dev/null +++ b/Tests/View/Http/Controllers/ItemTypeViewTest.php @@ -0,0 +1,158 @@ +actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(); + $response->assertStatus(200); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsItemType($json); + } + } + + /** @test */ + public function collection_pagination(): void + { + $this->actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(['offset'=>1, 'limit'=> 2]); + + $response->assertStatus(200); + $response->assertHeader('X-Offset', 1); + $response->assertHeader('X-Limit', 2); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsItemType($json); + } + } + + /** @test */ + /*public function collection_search_description(): void + { + $this->actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(['search'=>'description:track']); + + $response->assertStatus(200); + $response->assertHeader('X-Search', 'description:track'); + $response->assertHeader('X-Count', 3); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsItemType($json); + } + }*/ + + /** @test */ + public function collection_search_name(): void + { + $this->actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(['search'=>'name:simple']); + + $response->assertStatus(200); + $response->assertHeader('X-Search', 'name:simple'); + $response->assertHeader('X-Count', 2); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsItemType($json); + } + } + + /** @test */ + public function collection_search_name_no_results(): void + { + $this->actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(['search'=>'name:xxxxxxxxx']); + + $response->assertStatus(200); + $response->assertHeader('X-Search', 'name:xxxxxxxxx'); + $response->assertHeader('X-Count', 0); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsItemType($json); + } + } + + /** @test */ + /*public function collection_sort_name(): void + { + $this->actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(['sort'=>'name:asc', 'limit' => 1]); + + $response->assertStatus(200); + $response->assertHeader('X-Sort', 'name:asc'); + $response->assertHeader('X-Count', 1); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsItemType($json); + } + + $this->assertEquals('allocated-expense', $response->json()[0]['name']); + + }*/ + + /** @test */ + /*public function show(): void + { + $this->actingAs(User::find($this->getARandomUser()->id)); + + $response = $this->getItemTypes(['offset'=>0, 'limit'=> 1]); + $response->assertStatus(200); + + $item_type_id = $response->json()[0]['id']; + + $response = $this->getItemType(['item_type_id'=> $item_type_id]); + $response->assertStatus(200); + + $this->assertJsonIsItemType($response->content()); + }*/ +} diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index aeed0597..22adffce 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -50,7 +50,7 @@ public function collection_pagination(): void } /** @test */ - public function item(): void + public function show(): void { $this->actingAs(User::find(1)); diff --git a/public/api/schema/item-type.json b/public/api/schema/item-type.json index 50adc08f..1a0b7254 100644 --- a/public/api/schema/item-type.json +++ b/public/api/schema/item-type.json @@ -18,14 +18,14 @@ }, "created": { "type": "string" - }, - "required": [ - "id", - "name", - "friendly_name", - "description", - "example", - "created" - ] - } + } + }, + "required": [ + "id", + "name", + "friendly_name", + "description", + "example", + "created" + ] } diff --git a/routes/api/public-routes.php b/routes/api/public-routes.php index 31d5c2c8..620cab21 100644 --- a/routes/api/public-routes.php +++ b/routes/api/public-routes.php @@ -59,8 +59,8 @@ static function () { Route::get( 'item-types', - 'ItemTypeView@index' - ); + [\App\Http\Controllers\ItemTypeView::class, 'index'] + )->name('item-type.list'); Route::options( 'item-types', From e269dfc461f4b20d06a6f7ab7717552b086131ee Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Wed, 15 Jun 2022 12:20:01 +0100 Subject: [PATCH 06/32] Test methods - Update test method names --- .../Http/Controllers/AuthenticationTest.php | 68 +++++++++---------- .../Http/Controllers/CategoryManageTest.php | 22 +++--- .../Controllers/PermittedUserManageTest.php | 8 +-- .../Http/Controllers/ResourceManageTest.php | 28 ++++---- .../Controllers/ResourceTypeManageTest.php | 28 ++++---- .../Controllers/SubcategoryManagerTest.php | 24 +++---- .../Http/Controllers/ItemTypeViewTest.php | 20 +++--- .../Controllers/PermittedUserViewTest.php | 4 +- .../Http/Controllers/ResourceTypeViewTest.php | 6 +- 9 files changed, 103 insertions(+), 105 deletions(-) diff --git a/Tests/Feature/Http/Controllers/AuthenticationTest.php b/Tests/Feature/Http/Controllers/AuthenticationTest.php index cde2bd98..3ae1b711 100644 --- a/Tests/Feature/Http/Controllers/AuthenticationTest.php +++ b/Tests/Feature/Http/Controllers/AuthenticationTest.php @@ -8,7 +8,7 @@ class AuthenticationTest extends TestCase { /** @test */ - public function check_success(): void + public function checkSuccess(): void { $this->actingAs(User::find(1)); @@ -16,13 +16,13 @@ public function check_success(): void } /** @test */ - public function check_false(): void + public function checkFalse(): void { $this->get('v2/auth/check')->assertExactJson(['auth'=>false]); } /** @test */ - public function create_new_password_errors_with_invalid_email(): void + public function createNewPasswordErrorsWithInvalidEmail(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -72,7 +72,7 @@ public function create_new_password_errors_with_invalid_email(): void } /** @test */ - public function create_new_password_errors_with_invalid_token(): void + public function createNewPasswordErrorsWithInvalidToken(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -108,8 +108,6 @@ public function create_new_password_errors_with_invalid_token(): void $response->assertStatus(201); - $token = $response->json('uris.create-new-password.parameters.token'); - $response = $this->post( route('auth.create-new-password', ['email' => $email, 'token' => $this->faker->uuid]), [ @@ -122,7 +120,7 @@ public function create_new_password_errors_with_invalid_token(): void } /** @test */ - public function create_new_password_errors_with_invalid_token_and_email(): void + public function createNewPasswordErrorsWithInvalidTokenAndEmail(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -172,7 +170,7 @@ public function create_new_password_errors_with_invalid_token_and_email(): void } /** @test */ - public function create_new_password_errors_with_no_payload(): void + public function createNewPasswordErrorsWithNoPayload(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -219,7 +217,7 @@ public function create_new_password_errors_with_no_payload(): void } /** @test */ - public function create_new_password_success(): void + public function createNewPasswordSuccess(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -269,7 +267,7 @@ public function create_new_password_success(): void } /** @test */ - public function create_password_errors_with_invalid_email(): void + public function createPasswordErrorsWithInvalidEmail(): void { $response = $this->post( route('auth.register'), @@ -295,7 +293,7 @@ public function create_password_errors_with_invalid_email(): void } /** @test */ - public function create_password_errors_with_invalid_token(): void + public function createPasswordErrorsWithInvalidToken(): void { $email = $this->faker->email; @@ -321,7 +319,7 @@ public function create_password_errors_with_invalid_token(): void } /** @test */ - public function create_password_errors_with_invalid_token_and_email(): void + public function createPasswordErrorsWithInvalidTokenAndEmail(): void { $response = $this->post( route('auth.create-password', ['email' => $this->faker->email, 'token' => $this->faker->uuid]), @@ -332,7 +330,7 @@ public function create_password_errors_with_invalid_token_and_email(): void } /** @test */ - public function create_password_fails_with_no_payload(): void + public function createPasswordFailsWithNoPayload(): void { $email = $this->faker->email; @@ -358,7 +356,7 @@ public function create_password_fails_with_no_payload(): void } /** @test */ - public function create_password_fails_with_invalid_payload(): void + public function createPasswordFailsWithInvalidPayload(): void { $email = $this->faker->email; @@ -386,7 +384,7 @@ public function create_password_fails_with_invalid_payload(): void } /** @test */ - public function create_password_success(): void + public function createPasswordSuccess(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -415,7 +413,7 @@ public function create_password_success(): void } /** @test */ - public function forgot_password_errors_with_bad_email(): void + public function forgotPasswordErrorsWithBadEmail(): void { $response = $this->post( route('auth.forgot-password'), @@ -428,7 +426,7 @@ public function forgot_password_errors_with_bad_email(): void } /** @test */ - public function forgot_password_errors_with_no_payload(): void + public function forgotPasswordErrorsWithNoPayload(): void { $response = $this->post( route('auth.forgot-password'), @@ -477,7 +475,7 @@ public function forgot_password_success(): void } /** @test */ - public function login_errors_with_bad_email(): void + public function loginErrorsWithBadEmail(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -516,7 +514,7 @@ public function login_errors_with_bad_email(): void } /** @test */ - public function login_errors_with_bad_password(): void + public function loginErrorsWithBadPassword(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -555,7 +553,7 @@ public function login_errors_with_bad_password(): void } /** @test */ - public function login_success(): void + public function loginSuccess(): void { $email = $this->faker->email; $password = $this->faker->password(12); @@ -594,7 +592,7 @@ public function login_success(): void } /** @test */ - public function login_errors_with_no_email(): void + public function loginErrorsWithNoEmail(): void { $response = $this->post( route('auth.login'), @@ -607,7 +605,7 @@ public function login_errors_with_no_email(): void } /** @test */ - public function login_errors_with_no_name(): void + public function loginErrorsWithNoName(): void { $response = $this->post( route('auth.login'), @@ -620,7 +618,7 @@ public function login_errors_with_no_name(): void } /** @test */ - public function login_errors_with_no_payload(): void + public function loginErrorsWithNoPayload(): void { $response = $this->post( route('auth.login'), @@ -632,7 +630,7 @@ public function login_errors_with_no_payload(): void } /** @test */ - public function registration_errors_with_bad_email(): void + public function registrationErrorsWithBadEmail(): void { $response = $this->post( route('auth.register'), @@ -646,7 +644,7 @@ public function registration_errors_with_bad_email(): void } /** @test */ - public function registration_errors_with_no_email(): void + public function registrationErrorsWithNoEmail(): void { $response = $this->post( route('auth.register'), @@ -659,7 +657,7 @@ public function registration_errors_with_no_email(): void } /** @test */ - public function registration_errors_with_no_name(): void + public function registrationErrorsWithNoName(): void { $response = $this->post( route('auth.register'), @@ -672,7 +670,7 @@ public function registration_errors_with_no_name(): void } /** @test */ - public function registration_errors_with_no_payload(): void + public function registrationErrorsWithNoPayload(): void { $response = $this->post( route('auth.register'), @@ -683,7 +681,7 @@ public function registration_errors_with_no_payload(): void } /** @test */ - public function registration_success(): void + public function registrationSuccess(): void { $response = $this->post( route('auth.register'), @@ -697,7 +695,7 @@ public function registration_success(): void } /** @test */ - public function update_password_fails_mismatched_passwords(): void + public function updatePasswordFailsMismatchedPasswords(): void { $this->actingAs(User::find(1)); @@ -713,7 +711,7 @@ public function update_password_fails_mismatched_passwords(): void } /** @test */ - public function update_password_fails_no_payload(): void + public function updatePasswordFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -727,7 +725,7 @@ public function update_password_fails_no_payload(): void } /** @test */ - public function update_password_success(): void + public function updatePasswordSuccess(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -745,7 +743,7 @@ public function update_password_success(): void } /** @test */ - public function update_profile_fails_bad_email(): void + public function updateProfileFailsBadEmail(): void { $this->actingAs(User::find(1)); @@ -760,7 +758,7 @@ public function update_profile_fails_bad_email(): void } /** @test */ - public function update_profile_fails_no_payload(): void + public function updateProfileFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -773,7 +771,7 @@ public function update_profile_fails_no_payload(): void } /** @test */ - public function update_profile_success(): void + public function updateProfileSuccess(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -788,7 +786,7 @@ public function update_profile_success(): void } /** @test */ - public function user_success(): void + public function userSuccess(): void { $this->actingAs(User::find(1)); diff --git a/Tests/Feature/Http/Controllers/CategoryManageTest.php b/Tests/Feature/Http/Controllers/CategoryManageTest.php index b634684e..df270ab5 100644 --- a/Tests/Feature/Http/Controllers/CategoryManageTest.php +++ b/Tests/Feature/Http/Controllers/CategoryManageTest.php @@ -10,7 +10,7 @@ class CategoryManageTest extends TestCase { /** @test */ - public function create_category_fails_no_description_in_payload(): void + public function createCategoryFailsNoDescriptionInPayload(): void { $this->actingAs(User::find(1)); @@ -27,7 +27,7 @@ public function create_category_fails_no_description_in_payload(): void } /** @test */ - public function create_category_fails_no_name_in_payload(): void + public function createCategoryFailsNoNameInPayload(): void { $this->actingAs(User::find(1)); @@ -44,7 +44,7 @@ public function create_category_fails_no_name_in_payload(): void } /** @test */ - public function create_category_fails_no_permission_to_resource_type(): void + public function createCategoryFailsNoPermissionToResourceType(): void { $this->actingAs(User::find($this->getARandomUser()->id)); // Random user @@ -73,7 +73,7 @@ public function create_category_fails_no_permission_to_resource_type(): void } /** @test */ - public function create_category_fails_no_payload(): void + public function createCategoryFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -88,7 +88,7 @@ public function create_category_fails_no_payload(): void } /** @test */ - public function create_category_fails_non_unique_name(): void + public function createCategoryFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -119,7 +119,7 @@ public function create_category_fails_non_unique_name(): void } /** @test */ - public function create_category_success(): void + public function createCategorySuccess(): void { $this->actingAs(User::find(1)); @@ -138,7 +138,7 @@ public function create_category_success(): void } /** @test */ - public function delete_category_success(): void + public function deleteCategorySuccess(): void { $this->actingAs(User::find(1)); @@ -151,7 +151,7 @@ public function delete_category_success(): void } /** @test */ - public function update_category_fails_extra_fields_in_payload(): void + public function updateCategoryFailsExtraFieldsInPayload(): void { $this->actingAs(User::find(1)); @@ -170,7 +170,7 @@ public function update_category_fails_extra_fields_in_payload(): void } /** @test */ - public function update_category_fails_no_payload(): void + public function updateCategoryFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -187,7 +187,7 @@ public function update_category_fails_no_payload(): void } /** @test */ - public function update_category_fails_non_unique_name(): void + public function updateCategoryFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -230,7 +230,7 @@ public function update_category_fails_non_unique_name(): void } /** @test */ - public function update_category_success(): void + public function updateCategorySuccess(): void { $this->actingAs(User::find(1)); diff --git a/Tests/Feature/Http/Controllers/PermittedUserManageTest.php b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php index 9c4f855c..6f80e36e 100644 --- a/Tests/Feature/Http/Controllers/PermittedUserManageTest.php +++ b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php @@ -8,7 +8,7 @@ class PermittedUserManageTest extends TestCase { /** @test */ - public function create_permitted_user_fails_no_payload(): void + public function createPermittedUserFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -23,7 +23,7 @@ public function create_permitted_user_fails_no_payload(): void } /** @test */ - public function create_permitted_user_fails_user_does_not_exist(): void + public function createPermittedUserFailsUserDoesNotExist(): void { $this->actingAs(User::find(1)); @@ -40,7 +40,7 @@ public function create_permitted_user_fails_user_does_not_exist(): void } /** @test */ - public function create_permitted_user_success(): void + public function createPermittedUserSuccess(): void { $this->actingAs(User::find(1)); @@ -58,7 +58,7 @@ public function create_permitted_user_success(): void } /** @test */ - public function delete_permitted_user_success(): void + public function deletePermittedUserSuccess(): void { $this->actingAs(User::find(1)); diff --git a/Tests/Feature/Http/Controllers/ResourceManageTest.php b/Tests/Feature/Http/Controllers/ResourceManageTest.php index 98bb5cd3..8ba56282 100644 --- a/Tests/Feature/Http/Controllers/ResourceManageTest.php +++ b/Tests/Feature/Http/Controllers/ResourceManageTest.php @@ -10,7 +10,7 @@ class ResourceManageTest extends TestCase { /** @test */ - public function create_resource_fails_data_field_not_valid_json(): void + public function createResourceFailsDataFieldNotValidJson(): void { $this->actingAs(User::find(1)); @@ -30,7 +30,7 @@ public function create_resource_fails_data_field_not_valid_json(): void } /** @test */ - public function create_resource_fails_item_subtype_invalid(): void + public function createResourceFailsItemSubtypeInvalid(): void { $this->actingAs(User::find(1)); @@ -50,7 +50,7 @@ public function create_resource_fails_item_subtype_invalid(): void } /** @test */ - public function create_resource_fails_no_description_in_payload(): void + public function createResourceFailsNoDescriptionInPayload(): void { $this->actingAs(User::find(1)); @@ -69,7 +69,7 @@ public function create_resource_fails_no_description_in_payload(): void } /** @test */ - public function create_resource_fails_no_name_in_payload(): void + public function createResourceFailsNoNameInPayload(): void { $this->actingAs(User::find(1)); @@ -88,7 +88,7 @@ public function create_resource_fails_no_name_in_payload(): void } /** @test */ - public function create_resource_fails_no_payload(): void + public function createResourceFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -103,7 +103,7 @@ public function create_resource_fails_no_payload(): void } /** @test */ - public function create_resource_fails_no_permission_to_resource_type(): void + public function createResourceFailsNoPermissionToResourceType(): void { $this->actingAs(User::find($this->getARandomUser()->id)); // Random user @@ -133,7 +133,7 @@ public function create_resource_fails_no_permission_to_resource_type(): void } /** @test */ - public function create_resource_fails_non_unique_name(): void + public function createResourceFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -166,7 +166,7 @@ public function create_resource_fails_non_unique_name(): void } /** @test */ - public function create_resource_success(): void + public function createResourceSuccess(): void { $this->actingAs(User::find(1)); @@ -186,7 +186,7 @@ public function create_resource_success(): void } /** @test */ - public function create_resource_success_include_data_field(): void + public function createResourceSuccessIncludeDataField(): void { $this->actingAs(User::find(1)); @@ -207,7 +207,7 @@ public function create_resource_success_include_data_field(): void } /** @test */ - public function delete_resource_success(): void + public function deleteResourceSuccess(): void { $this->actingAs(User::find(1)); @@ -220,7 +220,7 @@ public function delete_resource_success(): void } /** @test */ - public function update_resource_fails_extra_fields_in_payload(): void + public function updateResourceFailsExtraFieldsInPayload(): void { $this->actingAs(User::find(1)); @@ -239,7 +239,7 @@ public function update_resource_fails_extra_fields_in_payload(): void } /** @test */ - public function update_resource_fails_non_payload(): void + public function updateResourceFailsNonPayload(): void { $this->actingAs(User::find(1)); @@ -256,7 +256,7 @@ public function update_resource_fails_non_payload(): void } /** @test */ - public function update_resource_fails_non_unique_name(): void + public function updateResourceFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -301,7 +301,7 @@ public function update_resource_fails_non_unique_name(): void } /** @test */ - public function update_resource_success(): void + public function updateResourceSuccess(): void { $this->actingAs(User::find(1)); diff --git a/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php b/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php index 14e4b6c7..3b28d7c2 100644 --- a/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php +++ b/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php @@ -8,7 +8,7 @@ class ResourceTypeManageTest extends TestCase { /** @test */ - public function create_resource_type_fails_data_field_not_valid_json(): void + public function createResourceTypeFailsDataFieldNotValidJson(): void { $this->actingAs(User::find(1)); @@ -25,7 +25,7 @@ public function create_resource_type_fails_data_field_not_valid_json(): void } /** @test */ - public function create_resource_type_fails_item_type_invalid(): void + public function createResourceTypeFailsItemTypeInvalid(): void { $this->actingAs(User::find(1)); @@ -41,7 +41,7 @@ public function create_resource_type_fails_item_type_invalid(): void } /** @test */ - public function create_resource_type_fails_no_description_in_payload(): void + public function createResourceTypeFailsNoDescriptionInPayload(): void { $this->actingAs(User::find(1)); @@ -56,7 +56,7 @@ public function create_resource_type_fails_no_description_in_payload(): void } /** @test */ - public function create_resource_type_fails_no_name_in_payload(): void + public function createResourceTypeFailsNoNameInPayload(): void { $this->actingAs(User::find(1)); @@ -71,7 +71,7 @@ public function create_resource_type_fails_no_name_in_payload(): void } /** @test */ - public function create_resource_type_fails_no_payload(): void + public function createResourceTypeFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -83,7 +83,7 @@ public function create_resource_type_fails_no_payload(): void } /** @test */ - public function create_resource_type_fails_non_unique_name(): void + public function createResourceTypeFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -115,7 +115,7 @@ public function create_resource_type_fails_non_unique_name(): void } /** @test */ - public function create_resource_type_fails_not_signed_in(): void + public function createResourceTypeFailsNotSignedIn(): void { $response = $this->postResourceType( [] @@ -125,7 +125,7 @@ public function create_resource_type_fails_not_signed_in(): void } /** @test */ - public function create_resource_type_success(): void + public function createResourceTypeSuccess(): void { $this->actingAs(User::find(1)); @@ -143,7 +143,7 @@ public function create_resource_type_success(): void } /** @test */ - public function create_resource_type_success_include_data_field(): void + public function createResourceTypeSuccessIncludeDataField(): void { $this->actingAs(User::find(1)); @@ -162,7 +162,7 @@ public function create_resource_type_success_include_data_field(): void } /** @test */ - public function delete_resource_type_success(): void + public function deleteResourceTypeSuccess(): void { $this->actingAs(User::find(1)); @@ -186,7 +186,7 @@ public function delete_resource_type_success(): void } /** @test */ - public function update_resource_type_fails_extra_fields_in_payload(): void + public function updateResourceTypeFailsExtraFieldsInPayload(): void { $this->actingAs(User::find(1)); @@ -215,7 +215,7 @@ public function update_resource_type_fails_extra_fields_in_payload(): void } /** @test */ - public function update_resource_type_fails_no_payload(): void + public function updateResourceTypeFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -242,7 +242,7 @@ public function update_resource_type_fails_no_payload(): void } /** @test */ - public function update_resource_type_fails_non_unique_name(): void + public function updateResourceTypeFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -288,7 +288,7 @@ public function update_resource_type_fails_non_unique_name(): void } /** @test */ - public function update_resource_type_success(): void + public function updateResourceTypeSuccess(): void { $this->actingAs(User::find(1)); diff --git a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php index 6f79d8a2..44bc2698 100644 --- a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php +++ b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php @@ -8,7 +8,7 @@ class SubcategoryManagerTest extends TestCase { /** @test */ - public function create_subcategory_fails_no_description_in_payload(): void + public function createSubcategoryFailsNoDescriptionInPayload(): void { $this->actingAs(User::find(1)); @@ -27,7 +27,7 @@ public function create_subcategory_fails_no_description_in_payload(): void } /** @test */ - public function create_subcategory_fails_no_payload(): void + public function createSubcategoryFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -44,7 +44,7 @@ public function create_subcategory_fails_no_payload(): void } /** @test */ - public function create_subcategory_fails_non_unique_name(): void + public function createSubcategoryFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -77,7 +77,7 @@ public function create_subcategory_fails_non_unique_name(): void } /** @test */ - public function create_subcategory_forbidden_when_category_id_invalid(): void + public function createSubcategoryForbiddenWhenCategoryIdInvalid(): void { $this->actingAs(User::find(1)); @@ -95,7 +95,7 @@ public function create_subcategory_forbidden_when_category_id_invalid(): void } /** @test */ - public function create_subcategory_success(): void + public function createSubcategorySuccess(): void { $this->actingAs(User::find(1)); @@ -115,7 +115,7 @@ public function create_subcategory_success(): void } /** @test */ - public function delete_subcategory_success(): void + public function deleteSubcategorySuccess(): void { $this->actingAs(User::find(1)); @@ -133,7 +133,7 @@ public function delete_subcategory_success(): void } /** @test */ - public function update_subcategory_fails_extra_fields_in_payload(): void + public function updateSubcategoryFailsExtraFieldsInPayload(): void { $this->actingAs(User::find(1)); @@ -154,7 +154,7 @@ public function update_subcategory_fails_extra_fields_in_payload(): void } /** @test */ - public function update_subcategory_fails_no_payload(): void + public function updateSubcategoryFailsNoPayload(): void { $this->actingAs(User::find(1)); @@ -173,7 +173,7 @@ public function update_subcategory_fails_no_payload(): void } /** @test */ - public function update_subcategory_fails_non_unique_name(): void + public function updateSubcategoryFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -222,7 +222,7 @@ public function update_subcategory_fails_non_unique_name(): void } /** @test */ - public function update_subcategory_description_success(): void + public function updateSubcategoryDescriptionSuccess(): void { $this->actingAs(User::find(1)); @@ -243,7 +243,7 @@ public function update_subcategory_description_success(): void } /** @test */ - public function update_subcategory_name_success(): void + public function updateSubcategoryNameSuccess(): void { $this->actingAs(User::find(1)); @@ -264,7 +264,7 @@ public function update_subcategory_name_success(): void } /** @test */ - public function update_subcategory_success(): void + public function updateSubcategorySuccess(): void { $this->actingAs(User::find(1)); diff --git a/Tests/View/Http/Controllers/ItemTypeViewTest.php b/Tests/View/Http/Controllers/ItemTypeViewTest.php index 1d0e8045..411ec8a8 100644 --- a/Tests/View/Http/Controllers/ItemTypeViewTest.php +++ b/Tests/View/Http/Controllers/ItemTypeViewTest.php @@ -9,7 +9,7 @@ class ItemTypeViewTest extends TestCase { /** @test */ // Rename test methods, unique - public function collection(): void + public function itemTypeCollection(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -28,7 +28,7 @@ public function collection(): void } /** @test */ - public function collection_pagination(): void + public function itemTypeCollectionPagination(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -50,7 +50,7 @@ public function collection_pagination(): void } /** @test */ - /*public function collection_search_description(): void + public function itemTypeCollectionSearchDescription(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -69,10 +69,10 @@ public function collection_pagination(): void $this->assertJsonIsItemType($json); } - }*/ + } /** @test */ - public function collection_search_name(): void + public function itemTypeCollectionSearchName(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -94,7 +94,7 @@ public function collection_search_name(): void } /** @test */ - public function collection_search_name_no_results(): void + public function itemTypeCollectionSearchNameNoResults(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -116,7 +116,7 @@ public function collection_search_name_no_results(): void } /** @test */ - /*public function collection_sort_name(): void + public function itemTypeCollectionSortName(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -138,10 +138,10 @@ public function collection_search_name_no_results(): void $this->assertEquals('allocated-expense', $response->json()[0]['name']); - }*/ + } /** @test */ - /*public function show(): void + public function itemTypeShow(): void { $this->actingAs(User::find($this->getARandomUser()->id)); @@ -154,5 +154,5 @@ public function collection_search_name_no_results(): void $response->assertStatus(200); $this->assertJsonIsItemType($response->content()); - }*/ + } } diff --git a/Tests/View/Http/Controllers/PermittedUserViewTest.php b/Tests/View/Http/Controllers/PermittedUserViewTest.php index 128c00f3..c073fedc 100644 --- a/Tests/View/Http/Controllers/PermittedUserViewTest.php +++ b/Tests/View/Http/Controllers/PermittedUserViewTest.php @@ -8,7 +8,7 @@ class PermittedUserViewTest extends TestCase { /** @test */ - public function collection(): void + public function permittedUserCollection(): void { $this->actingAs(User::find(1)); @@ -33,7 +33,7 @@ public function collection(): void } /** @test */ - public function item(): void + public function permittedUserShow(): void { $this->actingAs(User::find(1)); diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index 22adffce..7992158c 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -8,7 +8,7 @@ class ResourceTypeViewTest extends TestCase { /** @test */ - public function collection(): void + public function resourceTypeCollection(): void { $this->actingAs(User::find(1)); @@ -28,7 +28,7 @@ public function collection(): void } /** @test */ - public function collection_pagination(): void + public function resourceTypeCollectionPagination(): void { $this->actingAs(User::find(1)); @@ -50,7 +50,7 @@ public function collection_pagination(): void } /** @test */ - public function show(): void + public function resourceTypeShow(): void { $this->actingAs(User::find(1)); From 416d560d7f3a61af87199abaf25e2f1ea87fb451 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Wed, 15 Jun 2022 13:00:49 +0100 Subject: [PATCH 07/32] Tests - Item type tests - Correct type when passed from config --- .../Http/Controllers/ItemTypeViewTest.php | 62 ++++++++++++++----- app/Cache/Control.php | 2 +- config/api/app/cache.php | 2 +- phpunit.xml | 10 +-- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/Tests/View/Http/Controllers/ItemTypeViewTest.php b/Tests/View/Http/Controllers/ItemTypeViewTest.php index 411ec8a8..d82ba427 100644 --- a/Tests/View/Http/Controllers/ItemTypeViewTest.php +++ b/Tests/View/Http/Controllers/ItemTypeViewTest.php @@ -5,13 +5,19 @@ use App\User; use Tests\TestCase; -class ItemTypeViewTest extends TestCase +/** + * @runTestsInSeparateProcesses + */ +final class ItemTypeViewTest extends TestCase { - /** @test */ - // Rename test methods, unique + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeCollection(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(); $response->assertStatus(200); @@ -27,10 +33,14 @@ public function itemTypeCollection(): void } } - /** @test */ + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeCollectionPagination(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(['offset'=>1, 'limit'=> 2]); @@ -49,10 +59,14 @@ public function itemTypeCollectionPagination(): void } } - /** @test */ + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeCollectionSearchDescription(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(['search'=>'description:track']); @@ -71,10 +85,14 @@ public function itemTypeCollectionSearchDescription(): void } } - /** @test */ + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeCollectionSearchName(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(['search'=>'name:simple']); @@ -93,10 +111,14 @@ public function itemTypeCollectionSearchName(): void } } - /** @test */ + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeCollectionSearchNameNoResults(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(['search'=>'name:xxxxxxxxx']); @@ -115,10 +137,14 @@ public function itemTypeCollectionSearchNameNoResults(): void } } - /** @test */ + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeCollectionSortName(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(['sort'=>'name:asc', 'limit' => 1]); @@ -140,10 +166,14 @@ public function itemTypeCollectionSortName(): void } - /** @test */ + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function itemTypeShow(): void { - $this->actingAs(User::find($this->getARandomUser()->id)); + $this->actingAs(User::find(1)); $response = $this->getItemTypes(['offset'=>0, 'limit'=> 1]); $response->assertStatus(200); diff --git a/app/Cache/Control.php b/app/Cache/Control.php index 8e8ee19b..2a3aa1b9 100644 --- a/app/Cache/Control.php +++ b/app/Cache/Control.php @@ -38,7 +38,7 @@ public function __construct(bool $permitted_user = false, int $user_id = null) $this->visibility = 'private'; } - $this->cacheable = Config::get('api.app.cache.enable'); + $this->cacheable = (bool) Config::get('api.app.cache.enable'); $this->laravel_cache_prefix = Config::get('cache.prefix'); } diff --git a/config/api/app/cache.php b/config/api/app/cache.php index 9e8412a3..84940eb2 100644 --- a/config/api/app/cache.php +++ b/config/api/app/cache.php @@ -3,7 +3,7 @@ declare(strict_types=1); return [ - 'enable' => env('APP_CACHE', true), + 'enable' => (bool) env('APP_CACHE', true), 'ttl' => 31536000, 'public_key_prefix' => '-p-' ]; diff --git a/phpunit.xml b/phpunit.xml index ffe1558f..2a90ae9e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,11 +5,11 @@ colors="true" > - - ./tests/Unit - - ./tests/Feature + ./Tests/Feature + + + ./Tests/View @@ -22,7 +22,7 @@ - + From 59a0422f556d5340cfcca0d9bc2a678aafa1ebf0 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Wed, 15 Jun 2022 13:25:04 +0100 Subject: [PATCH 08/32] Test tweaks --- Tests/Feature/Http/Controllers/AuthenticationTest.php | 2 +- Tests/Feature/Http/Controllers/CategoryManageTest.php | 2 +- Tests/Feature/Http/Controllers/PermittedUserManageTest.php | 2 +- Tests/Feature/Http/Controllers/ResourceManageTest.php | 2 +- Tests/Feature/Http/Controllers/ResourceTypeManageTest.php | 2 +- Tests/Feature/Http/Controllers/SubcategoryManagerTest.php | 2 +- Tests/View/Http/Controllers/AuthenticationTest.php | 2 +- Tests/View/Http/Controllers/PermittedUserViewTest.php | 2 +- Tests/View/Http/Controllers/ResourceTypeViewTest.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/Feature/Http/Controllers/AuthenticationTest.php b/Tests/Feature/Http/Controllers/AuthenticationTest.php index 3ae1b711..abc8771b 100644 --- a/Tests/Feature/Http/Controllers/AuthenticationTest.php +++ b/Tests/Feature/Http/Controllers/AuthenticationTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -class AuthenticationTest extends TestCase +final class AuthenticationTest extends TestCase { /** @test */ public function checkSuccess(): void diff --git a/Tests/Feature/Http/Controllers/CategoryManageTest.php b/Tests/Feature/Http/Controllers/CategoryManageTest.php index df270ab5..ba72cf51 100644 --- a/Tests/Feature/Http/Controllers/CategoryManageTest.php +++ b/Tests/Feature/Http/Controllers/CategoryManageTest.php @@ -7,7 +7,7 @@ use App\User; use Tests\TestCase; -class CategoryManageTest extends TestCase +final class CategoryManageTest extends TestCase { /** @test */ public function createCategoryFailsNoDescriptionInPayload(): void diff --git a/Tests/Feature/Http/Controllers/PermittedUserManageTest.php b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php index 6f80e36e..d06afb3c 100644 --- a/Tests/Feature/Http/Controllers/PermittedUserManageTest.php +++ b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -class PermittedUserManageTest extends TestCase +final class PermittedUserManageTest extends TestCase { /** @test */ public function createPermittedUserFailsNoPayload(): void diff --git a/Tests/Feature/Http/Controllers/ResourceManageTest.php b/Tests/Feature/Http/Controllers/ResourceManageTest.php index 8ba56282..188d9736 100644 --- a/Tests/Feature/Http/Controllers/ResourceManageTest.php +++ b/Tests/Feature/Http/Controllers/ResourceManageTest.php @@ -7,7 +7,7 @@ use App\User; use Tests\TestCase; -class ResourceManageTest extends TestCase +final class ResourceManageTest extends TestCase { /** @test */ public function createResourceFailsDataFieldNotValidJson(): void diff --git a/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php b/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php index 3b28d7c2..cf49daa0 100644 --- a/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php +++ b/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -class ResourceTypeManageTest extends TestCase +final class ResourceTypeManageTest extends TestCase { /** @test */ public function createResourceTypeFailsDataFieldNotValidJson(): void diff --git a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php index 44bc2698..ba81e5d5 100644 --- a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php +++ b/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -class SubcategoryManagerTest extends TestCase +final class SubcategoryManagerTest extends TestCase { /** @test */ public function createSubcategoryFailsNoDescriptionInPayload(): void diff --git a/Tests/View/Http/Controllers/AuthenticationTest.php b/Tests/View/Http/Controllers/AuthenticationTest.php index 177a59f1..bd8be5f9 100644 --- a/Tests/View/Http/Controllers/AuthenticationTest.php +++ b/Tests/View/Http/Controllers/AuthenticationTest.php @@ -4,7 +4,7 @@ use Tests\TestCase; -class AuthenticationTest extends TestCase +final class AuthenticationTest extends TestCase { /** @test */ public function optionsRequestForCreatePassword(): void diff --git a/Tests/View/Http/Controllers/PermittedUserViewTest.php b/Tests/View/Http/Controllers/PermittedUserViewTest.php index c073fedc..5bd4ce80 100644 --- a/Tests/View/Http/Controllers/PermittedUserViewTest.php +++ b/Tests/View/Http/Controllers/PermittedUserViewTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -class PermittedUserViewTest extends TestCase +final class PermittedUserViewTest extends TestCase { /** @test */ public function permittedUserCollection(): void diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index 7992158c..914b15b7 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -class ResourceTypeViewTest extends TestCase +final class ResourceTypeViewTest extends TestCase { /** @test */ public function resourceTypeCollection(): void From 99370fe5470a3a7be326ca0f690f8545366ac243 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Wed, 15 Jun 2022 13:31:48 +0100 Subject: [PATCH 09/32] Fix - Rename test - Remove dead line --- README.md | 41 ++++++++++--------- .../Http/Controllers/AuthenticationTest.php | 2 - ...agerTest.php => SubcategoryManageTest.php} | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) rename Tests/Feature/Http/Controllers/{SubcategoryManagerTest.php => SubcategoryManageTest.php} (99%) diff --git a/README.md b/README.md index 2abde3d1..252b0feb 100644 --- a/README.md +++ b/README.md @@ -260,23 +260,24 @@ You can see our progress in the table below. We are hoping to add tests in each not too concerned about missing anything as we still have all our tests in Postman, we won't disable our test monitor until our local test suite is as complete as the Postman request tests. -| Controller | Progress | -|:------------------------------------|:-----------------------| -| Authentication (Actions) | Complete (34 Tests) | -| Authentication (Responses) | In Progress (2 Tests) | -| CategoryManage (Actions) | Complete (11 Tests) | -| ItemCategoryManage (Actions) | Not started | -| ItemManage (Actions) | Not started | -| ItemPartialTransferManage (Actions) | Not started | -| ItemSubcategoryManage (Actions) | Not started | -| ItemTransferManage (Actions) | Not started | -| PermittedUserManage (Actions) | In Progress (4 Tests) | -| PermittedUserView (Responses) | In Progress (2 Tests) | -| RequestManage (Actions) | Not started | -| ResourceManage (Actions) | Complete (14 Tests) | -| ResourceTypeManage (Actions) | Complete (14 Tests) | -| ResourceTypeView (Responses) | In Progress (3 Tests) | -| SubcategoryManage (Actions) | Complete (12 Tests) | -| ToolManage (Actions) | Not started | -| Summaries (Responses) | Not started | -| Total | In Progress (96 Tests) | +| Controller | Progress | +|:------------------------------------|:------------------------| +| Authentication (Actions) | Complete (34 Tests) | +| Authentication (Responses) | In Progress (2 Tests) | +| CategoryManage (Actions) | Complete (11 Tests) | +| ItemCategoryManage (Actions) | Not started | +| ItemManage (Actions) | Not started | +| ItemPartialTransferManage (Actions) | Not started | +| ItemSubcategoryManage (Actions) | Not started | +| ItemTransferManage (Actions) | Not started | +| ItemTypeView (Responses) | Complete (7 tests) | +| PermittedUserManage (Actions) | In Progress (4 Tests) | +| PermittedUserView (Responses) | In Progress (2 Tests) | +| RequestManage (Actions) | Not started | +| ResourceManage (Actions) | Complete (14 Tests) | +| ResourceTypeManage (Actions) | Complete (14 Tests) | +| ResourceTypeView (Responses) | In Progress (3 Tests) | +| SubcategoryManage (Actions) | Complete (12 Tests) | +| ToolManage (Actions) | Not started | +| Summaries (Responses) | Not started | +| Total | In Progress (103 Tests) | diff --git a/Tests/Feature/Http/Controllers/AuthenticationTest.php b/Tests/Feature/Http/Controllers/AuthenticationTest.php index abc8771b..3c7c5ed1 100644 --- a/Tests/Feature/Http/Controllers/AuthenticationTest.php +++ b/Tests/Feature/Http/Controllers/AuthenticationTest.php @@ -156,8 +156,6 @@ public function createNewPasswordErrorsWithInvalidTokenAndEmail(): void $response->assertStatus(201); - $token = $response->json('uris.create-new-password.parameters.token'); - $response = $this->post( route('auth.create-new-password', ['email' => $this->faker->colorName, 'token' => $this->faker->colorName]), [ diff --git a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php b/Tests/Feature/Http/Controllers/SubcategoryManageTest.php similarity index 99% rename from Tests/Feature/Http/Controllers/SubcategoryManagerTest.php rename to Tests/Feature/Http/Controllers/SubcategoryManageTest.php index ba81e5d5..134645f6 100644 --- a/Tests/Feature/Http/Controllers/SubcategoryManagerTest.php +++ b/Tests/Feature/Http/Controllers/SubcategoryManageTest.php @@ -5,7 +5,7 @@ use App\User; use Tests\TestCase; -final class SubcategoryManagerTest extends TestCase +final class SubcategoryManageTest extends TestCase { /** @test */ public function createSubcategoryFailsNoDescriptionInPayload(): void From 9d961369d8898bc02ec4abf347de0044ec8e854e Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Thu, 16 Jun 2022 22:08:10 +0100 Subject: [PATCH 10/32] Unique email - Added a rule to stop non unique emails - Added test to ensure unique email validation works - Remove calls to write to log --- README.md | 4 +-- .../Http/Controllers/AuthenticationTest.php | 26 +++++++++++++++++++ app/Http/Controllers/Authentication.php | 12 ++++----- app/Http/Controllers/ResourceTypeManage.php | 1 - 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 252b0feb..5a6faa53 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ our local test suite is as complete as the Postman request tests. | Controller | Progress | |:------------------------------------|:------------------------| -| Authentication (Actions) | Complete (34 Tests) | +| Authentication (Actions) | Complete (35 Tests) | | Authentication (Responses) | In Progress (2 Tests) | | CategoryManage (Actions) | Complete (11 Tests) | | ItemCategoryManage (Actions) | Not started | @@ -280,4 +280,4 @@ our local test suite is as complete as the Postman request tests. | SubcategoryManage (Actions) | Complete (12 Tests) | | ToolManage (Actions) | Not started | | Summaries (Responses) | Not started | -| Total | In Progress (103 Tests) | +| Total | In Progress (104 Tests) | diff --git a/Tests/Feature/Http/Controllers/AuthenticationTest.php b/Tests/Feature/Http/Controllers/AuthenticationTest.php index 3c7c5ed1..009629d5 100644 --- a/Tests/Feature/Http/Controllers/AuthenticationTest.php +++ b/Tests/Feature/Http/Controllers/AuthenticationTest.php @@ -667,6 +667,32 @@ public function registrationErrorsWithNoName(): void $response->assertStatus(422); } + /** @test */ + public function registrationErrorsWithNonUniqueEmail(): void + { + $email = $this->faker->email; + + $response = $this->post( + route('auth.register'), + [ + 'email' => $email, + 'name' => $this->faker->name + ] + ); + + $response->assertStatus(201); + + $response = $this->post( + route('auth.register'), + [ + 'email' => $email, + 'name' => $this->faker->name + ] + ); + + $response->assertStatus(422); + } + /** @test */ public function registrationErrorsWithNoPayload(): void { diff --git a/app/Http/Controllers/Authentication.php b/app/Http/Controllers/Authentication.php index c8280d52..c4d174ef 100644 --- a/app/Http/Controllers/Authentication.php +++ b/app/Http/Controllers/Authentication.php @@ -23,6 +23,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; +use Illuminate\Validation\Rule; class Authentication extends \Illuminate\Routing\Controller { @@ -105,7 +106,6 @@ public function createPassword(Request $request): Http\JsonResponse return response()->json(['message' => trans('auth.unable-to-find-account')], 404); } catch (Exception $e) { - Log::error($e->getMessage()); return response()->json(['message' => trans('auth.unable-to-create-password')], 500); } } @@ -177,7 +177,6 @@ public function createNewPassword(Request $request): Http\JsonResponse return response()->json(['message' => trans('auth.unable-to-find-account')], 500); } catch (Exception $e) { - Log::error($e->getMessage()); return response()->json(['message' => trans('auth.unable-to-create-password')], 500); } } @@ -232,7 +231,6 @@ public function forgotPassword(Request $request): Http\JsonResponse $user->notify(new ForgotPassword($user, $create_token)); } } catch (Exception $e) { - Log::error($e->getMessage()); return response()->json(['error' => trans('auth.unable-process-forgot-password')], 500); } @@ -349,7 +347,11 @@ public function register(Request $request): Http\JsonResponse $request->all(), [ 'name' => 'required', - 'email' => 'required|email', + 'email' => [ + 'required', + 'email', + Rule::unique(User::class, 'email') + ] ] ); @@ -389,7 +391,6 @@ public function register(Request $request): Http\JsonResponse } } catch (Exception $e) { - Log::error($e->getMessage()); return response()->json(['error' => trans('auth.unable-to-create-account')], 500); } @@ -521,7 +522,6 @@ public function updateProfile(Request $request): Http\JsonResponse $user->save(); } catch (Exception $e) { - Log::error($e->getMessage()); return response()->json(['message' => trans('auth.unable-to-update-profile')], 401); } diff --git a/app/Http/Controllers/ResourceTypeManage.php b/app/Http/Controllers/ResourceTypeManage.php index a1575978..fc063a18 100644 --- a/app/Http/Controllers/ResourceTypeManage.php +++ b/app/Http/Controllers/ResourceTypeManage.php @@ -80,7 +80,6 @@ public function create(Request $request): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - Log::error($e->getMessage()); return \App\HttpResponse\Responses::failedToSaveModelForCreate($e); } From a24afd9765e79cac275a5692d9801cb3dc3cc62a Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Thu, 16 Jun 2022 22:10:43 +0100 Subject: [PATCH 11/32] Rename class - Rename the response class, remove the s --- app/Exceptions/Handler.php | 6 +- app/Http/Controllers/Authentication.php | 8 +- app/Http/Controllers/CategoryManage.php | 34 +++--- app/Http/Controllers/CategoryView.php | 10 +- app/Http/Controllers/CurrencyView.php | 6 +- app/Http/Controllers/ItemCategoryManage.php | 26 ++--- app/Http/Controllers/ItemCategoryView.php | 36 +++--- app/Http/Controllers/ItemManage.php | 106 +++++++++--------- .../Controllers/ItemPartialTransferManage.php | 28 ++--- .../Controllers/ItemPartialTransferView.php | 24 ++-- .../Controllers/ItemSubcategoryManage.php | 28 ++--- app/Http/Controllers/ItemSubcategoryView.php | 34 +++--- app/Http/Controllers/ItemSubtypeView.php | 12 +- app/Http/Controllers/ItemTransferManage.php | 18 +-- app/Http/Controllers/ItemTransferView.php | 26 ++--- app/Http/Controllers/ItemTypeView.php | 8 +- app/Http/Controllers/ItemView.php | 24 ++-- app/Http/Controllers/PermittedUserManage.php | 20 ++-- app/Http/Controllers/PermittedUserView.php | 12 +- app/Http/Controllers/QueueView.php | 6 +- app/Http/Controllers/RequestManage.php | 6 +- app/Http/Controllers/ResourceManage.php | 34 +++--- app/Http/Controllers/ResourceTypeItemView.php | 4 +- app/Http/Controllers/ResourceTypeManage.php | 32 +++--- app/Http/Controllers/ResourceTypeView.php | 4 +- app/Http/Controllers/ResourceView.php | 12 +- app/Http/Controllers/SubcategoryManage.php | 32 +++--- app/Http/Controllers/SubcategoryView.php | 10 +- app/Http/Controllers/Summary/CategoryView.php | 4 +- app/Http/Controllers/Summary/ItemView.php | 6 +- .../Summary/ResourceTypeItemView.php | 6 +- app/Http/Controllers/Summary/ResourceView.php | 4 +- .../Controllers/Summary/SubcategoryView.php | 4 +- app/Http/Controllers/ToolManage.php | 4 +- app/Http/Middleware/ConvertGetParameters.php | 2 +- .../Middleware/ConvertRouteParameters.php | 6 +- .../{Responses.php => Response.php} | 2 +- .../AllocatedExpense/AllowedValue.php | 6 +- .../AllocatedExpense/HttpResponse/Item.php | 4 +- app/ItemType/Game/HttpResponse/Item.php | 4 +- app/ItemType/SimpleExpense/AllowedValue.php | 6 +- .../SimpleExpense/HttpResponse/Item.php | 4 +- app/ItemType/SimpleItem/HttpResponse/Item.php | 4 +- app/Models/AllowedValue/Category.php | 2 +- app/Models/AllowedValue/Currency.php | 2 +- app/Models/AllowedValue/ItemSubtype.php | 2 +- app/Models/AllowedValue/ItemType.php | 2 +- app/Models/AllowedValue/Resource.php | 2 +- app/Models/AllowedValue/Subcategory.php | 2 +- 49 files changed, 342 insertions(+), 342 deletions(-) rename app/HttpResponse/{Responses.php => Response.php} (99%) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 11954f62..06dfabff 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -51,7 +51,7 @@ public function report(\Throwable $exception) public function render($request, \Throwable $exception) { if ($exception instanceof AuthenticationException) { - return \App\HttpResponse\Responses::authenticationRequired($exception); + return \App\HttpResponse\Response::authenticationRequired($exception); } $status_code = 500; @@ -63,10 +63,10 @@ public function render($request, \Throwable $exception) switch ($status_code) { case 404: - \App\HttpResponse\Responses::notFound(null, $exception); + \App\HttpResponse\Response::notFound(null, $exception); break; case 503: - \App\HttpResponse\Responses::maintenance(); + \App\HttpResponse\Response::maintenance(); break; case 500: if (App::environment() === 'local') { diff --git a/app/Http/Controllers/Authentication.php b/app/Http/Controllers/Authentication.php index c4d174ef..4f514dcf 100644 --- a/app/Http/Controllers/Authentication.php +++ b/app/Http/Controllers/Authentication.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Notifications\ForgotPassword; use App\Notifications\Registered; use App\HttpOptionResponse\Auth\Check; @@ -609,7 +609,7 @@ public function token($token_id): Http\JsonResponse return response()->json($tokens[$token_id]); } - return Responses::notFound(); + return Response::notFound(); } return response()->json(['message' => trans('auth.failed')], 401); @@ -634,10 +634,10 @@ public function deleteToken($token_id): Http\JsonResponse if (array_key_exists($token_id, $tokens)) { $user->tokens()->where('id', $token_id)->delete(); - return Responses::successNoContent(); + return Response::successNoContent(); } - return Responses::notFound(); + return Response::notFound(); } return response()->json(['message' => trans('auth.failed')], 401); diff --git a/app/Http/Controllers/CategoryManage.php b/app/Http/Controllers/CategoryManage.php index 79e219b6..97eb759f 100644 --- a/app/Http/Controllers/CategoryManage.php +++ b/app/Http/Controllers/CategoryManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Jobs\ClearCache; use App\Models\Category; use App\HttpRequest\BodyValidation; @@ -29,14 +29,14 @@ class CategoryManage extends Controller public function create($resource_type_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $validator = (new CategoryValidator)->create([ 'resource_type_id' => $resource_type_id ]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -58,7 +58,7 @@ public function create($resource_type_id): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -81,7 +81,7 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -94,7 +94,7 @@ public function delete( $category = (new Category())->find($category_id); if ($category === null) { - return Responses::notFound(trans('entities.category')); + return Response::notFound(trans('entities.category')); } try { @@ -102,11 +102,11 @@ public function delete( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.category'), $e); + return Response::notFound(trans('entities.category'), $e); } } @@ -121,17 +121,17 @@ public function delete( public function update($resource_type_id, $category_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } $category = (new Category())->instance($category_id); if ($category === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } if (count(request()->all()) === 0) { - return \App\HttpResponse\Responses::nothingToPatch(); + return \App\HttpResponse\Response::nothingToPatch(); } $validator = (new CategoryValidator)->update([ @@ -140,11 +140,11 @@ public function update($resource_type_id, $category_id): JsonResponse ]); if ($validator === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $invalid_fields = $this->checkForInvalidFields( @@ -155,7 +155,7 @@ public function update($resource_type_id, $category_id): JsonResponse ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } foreach (request()->all() as $key => $value) { @@ -176,9 +176,9 @@ public function update($resource_type_id, $category_id): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } } diff --git a/app/Http/Controllers/CategoryView.php b/app/Http/Controllers/CategoryView.php index b22cae1c..ff009e67 100644 --- a/app/Http/Controllers/CategoryView.php +++ b/app/Http/Controllers/CategoryView.php @@ -31,7 +31,7 @@ class CategoryView extends Controller public function index($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $cache_control = new \App\Cache\Control( @@ -116,7 +116,7 @@ static function ($category) { public function show($resource_type_id, $category_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $parameters = Parameter\Request::fetch(array_keys(Config::get('api.category.parameters-show'))); @@ -127,7 +127,7 @@ public function show($resource_type_id, $category_id): JsonResponse ); if ($category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.category')); + return \App\HttpResponse\Response::notFound(trans('entities.category')); } $subcategories = []; @@ -168,7 +168,7 @@ public function show($resource_type_id, $category_id): JsonResponse public function optionsIndex($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $response = new CategoryCollection($this->permissions((int) $resource_type_id)); @@ -187,7 +187,7 @@ public function optionsIndex($resource_type_id): JsonResponse public function optionsShow($resource_type_id, $category_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $response = new CategoryItem($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/CurrencyView.php b/app/Http/Controllers/CurrencyView.php index 2c9ca679..f559046a 100644 --- a/app/Http/Controllers/CurrencyView.php +++ b/app/Http/Controllers/CurrencyView.php @@ -90,13 +90,13 @@ static function($currency) { public function show(string $currency_id): JsonResponse { if ((new Permission())->currencyItemExists((int) $currency_id) === false) { - \App\HttpResponse\Responses::notFound(trans('entities.currency')); + \App\HttpResponse\Response::notFound(trans('entities.currency')); } $currency = (new Currency())->single($currency_id); if ($currency === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.currency')); + return \App\HttpResponse\Response::notFound(trans('entities.currency')); } $headers = new Header(); @@ -131,7 +131,7 @@ public function optionsIndex(): JsonResponse public function optionsShow(string $currency_id): JsonResponse { if ((new Permission())->currencyItemExists((int) $currency_id) === false) { - return \App\HttpResponse\Responses::notFound(trans('entities.currency')); + return \App\HttpResponse\Response::notFound(trans('entities.currency')); } $response = new CurrencyItem(['view'=> $this->user_id !== null]); diff --git a/app/Http/Controllers/ItemCategoryManage.php b/app/Http/Controllers/ItemCategoryManage.php index 184f75b4..e6145ea2 100644 --- a/app/Http/Controllers/ItemCategoryManage.php +++ b/app/Http/Controllers/ItemCategoryManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Jobs\ClearCache; use App\Models\ItemCategory; @@ -27,7 +27,7 @@ public function create( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -35,7 +35,7 @@ public function create( return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->createItemCategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, 1), 'game' => $this->createItemCategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, 5), - 'simple-item' => \App\HttpResponse\Responses::categoryAssignmentLimit(0), + 'simple-item' => \App\HttpResponse\Response::categoryAssignmentLimit(0), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -54,7 +54,7 @@ private function createItemCategory( ); if ($assigned >= $assignment_limit) { - return \App\HttpResponse\Responses::categoryAssignmentLimit($assignment_limit); + return \App\HttpResponse\Response::categoryAssignmentLimit($assignment_limit); } $decode = $this->hash->category()->decode(request()->input('category_id')); @@ -75,7 +75,7 @@ private function createItemCategory( ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors( + return \App\HttpResponse\Response::validationErrors( $validator, (new \App\Models\AllowedValue\Category())->allowedValues($resource_type_id) ); @@ -94,7 +94,7 @@ private function createItemCategory( $category_id = $this->hash->decode('category', request()->input('category_id')); if ($category_id === false) { - return \App\HttpResponse\Responses::unableToDecode(); + return \App\HttpResponse\Response::unableToDecode(); } $item_category = new ItemCategory([ @@ -106,7 +106,7 @@ private function createItemCategory( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return \App\HttpResponse\Responses::failedToSaveModelForCreate($e); + return \App\HttpResponse\Response::failedToSaveModelForCreate($e); } return response()->json( @@ -123,14 +123,14 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense', 'game' => $this->deleteItemCategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id), - 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -150,7 +150,7 @@ private function deleteItemCategory( ); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -167,11 +167,11 @@ private function deleteItemCategory( ClearCache::dispatch($cache_job_payload->payload()); - return \App\HttpResponse\Responses::successNoContent(); + return \App\HttpResponse\Response::successNoContent(); } catch (QueryException $e) { - return \App\HttpResponse\Responses::foreignKeyConstraintError($e); + return \App\HttpResponse\Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category'), $e); + return \App\HttpResponse\Response::notFound(trans('entities.item-category'), $e); } } } diff --git a/app/Http/Controllers/ItemCategoryView.php b/app/Http/Controllers/ItemCategoryView.php index 240b9cf6..8c5de2d7 100644 --- a/app/Http/Controllers/ItemCategoryView.php +++ b/app/Http/Controllers/ItemCategoryView.php @@ -9,7 +9,7 @@ use App\HttpOptionResponse\ItemCategory\SimpleExpense; use App\HttpOptionResponse\ItemCategory\SimpleExpenseCollection; use App\HttpResponse\Header; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Models\ItemCategory; use App\Transformer\ItemCategory as ItemCategoryTransformer; @@ -25,14 +25,14 @@ class ItemCategoryView extends Controller public function index(string $resource_type_id, string $resource_id, string $item_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'game', 'simple-expense' => $this->itemCategoryCollection((int) $resource_type_id, (int) $resource_id, (int) $item_id), - 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -87,18 +87,18 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } if ($item_category_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'game', 'simple-expense' => $this->itemCategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id), - 'simple-item' => Responses::notSupported(), + 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -118,7 +118,7 @@ private function itemCategory( ); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $headers = new Header(); @@ -134,7 +134,7 @@ private function itemCategory( public function optionsIndex(string $resource_type_id, string $resource_id, string $item_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); @@ -143,7 +143,7 @@ public function optionsIndex(string $resource_type_id, string $resource_id, stri 'allocated-expense' => $this->optionsAllocatedExpenseCollection((int) $resource_type_id), 'game' => $this->optionsGameCollection((int) $resource_type_id), 'simple-expense' => $this->optionsSimpleExpenseCollection((int) $resource_type_id), - 'simple-item' => Responses::notSupported(), + 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -151,7 +151,7 @@ public function optionsIndex(string $resource_type_id, string $resource_id, stri private function optionsAllocatedExpenseCollection(int $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType($resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $response = new AllocatedExpenseCollection($this->permissions((int) $resource_type_id)); @@ -166,7 +166,7 @@ private function optionsAllocatedExpenseCollection(int $resource_type_id): JsonR private function optionsGameCollection(int $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType($resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $response = new GameCollection($this->permissions($resource_type_id)); @@ -181,7 +181,7 @@ private function optionsGameCollection(int $resource_type_id): JsonResponse private function optionsSimpleExpenseCollection(int $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType($resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $response = new SimpleExpenseCollection($this->permissions($resource_type_id)); @@ -201,11 +201,11 @@ public function optionsShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } if ($item_category_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $item_type = Select::itemType((int) $resource_type_id); @@ -214,7 +214,7 @@ public function optionsShow( 'allocated-expense' => $this->optionsAllocatedExpenseShow((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id), 'game' => $this->optionsGameShow((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id), 'simple-expense' => $this->optionsSimpleExpenseShow((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id), - 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -234,7 +234,7 @@ private function optionsAllocatedExpenseShow( ); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $response = new AllocatedExpense($this->permissions((int) $resource_type_id)); @@ -257,7 +257,7 @@ private function optionsGameShow( ); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $response = new Game($this->permissions((int) $resource_type_id)); @@ -280,7 +280,7 @@ private function optionsSimpleExpenseShow( ); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $response = new SimpleExpense($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/ItemManage.php b/app/Http/Controllers/ItemManage.php index af5d5856..2da53283 100644 --- a/app/Http/Controllers/ItemManage.php +++ b/app/Http/Controllers/ItemManage.php @@ -5,7 +5,7 @@ use App\Cache\JobPayload; use App\Cache\KeyGroup; use App\HttpRequest\Hash; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Jobs\ClearCache; use App\Models\Item; @@ -29,7 +29,7 @@ class ItemManage extends Controller public function create(string $resource_type_id, string $resource_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -95,7 +95,7 @@ private function createAllocatedExpense(int $resource_type_id, int $resource_id) ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -148,7 +148,7 @@ private function createGame(int $resource_type_id, int $resource_id): JsonRespon ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -203,7 +203,7 @@ private function createSimpleExpense(int $resource_type_id, int $resource_id): J ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -257,7 +257,7 @@ private function createSimpleItem( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -271,11 +271,11 @@ private function createSimpleItem( public function update(string $resource_type_id, string $resource_id,string $item_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.item')); + return Response::notFoundOrNotAccessible(trans('entities.item')); } if (count(request()->all()) === 0) { - return Responses::nothingToPatch(); + return Response::nothingToPatch(); } $item_type = Select::itemType((int) $resource_type_id); @@ -312,7 +312,7 @@ private function updateAllocatedExpense( $item_type_instance = (new \App\ItemType\AllocatedExpense\Models\Item())->instance($item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } try { @@ -347,10 +347,10 @@ private function updateAllocatedExpense( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } private function updateGame( @@ -376,7 +376,7 @@ private function updateGame( $item_type_instance = (new \App\ItemType\Game\Models\Item())->instance($item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } try { @@ -410,10 +410,10 @@ private function updateGame( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } private function updateSimpleExpense( @@ -439,7 +439,7 @@ private function updateSimpleExpense( $item_type_instance = (new \App\ItemType\SimpleExpense\Models\Item())->instance($item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } try { @@ -465,10 +465,10 @@ private function updateSimpleExpense( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } private function updateSimpleItem( @@ -494,7 +494,7 @@ private function updateSimpleItem( $item_type_instance = (new \App\ItemType\SimpleItem\Models\Item())->instance($item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } try { @@ -515,16 +515,16 @@ private function updateSimpleItem( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } public function delete(string $resource_type_id, string $resource_id,string $item_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.item')); + return Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); @@ -559,11 +559,11 @@ private function deleteAllocatedExpense( $item_instance = (new Item())->instance($resource_type_id, $resource_id, $item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Responses::foreignKeyConstraintError(); + return Response::foreignKeyConstraintError(); } try { @@ -576,11 +576,11 @@ private function deleteAllocatedExpense( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.item'), $e); + return Response::notFound(trans('entities.item'), $e); } } @@ -605,11 +605,11 @@ private function deleteGame( $item_instance = (new Item())->instance($resource_type_id, $resource_id, $item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Responses::foreignKeyConstraintError(); + return Response::foreignKeyConstraintError(); } try { @@ -621,11 +621,11 @@ private function deleteGame( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.item'), $e); + return Response::notFound(trans('entities.item'), $e); } } @@ -650,11 +650,11 @@ private function deleteSimpleExpense( $item_instance = (new Item())->instance($resource_type_id, $resource_id, $item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Responses::foreignKeyConstraintError(); + return Response::foreignKeyConstraintError(); } try { @@ -666,11 +666,11 @@ private function deleteSimpleExpense( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.item'), $e); + return Response::notFound(trans('entities.item'), $e); } } @@ -695,11 +695,11 @@ private function deleteSimpleItem( $item_instance = (new Item())->instance($resource_type_id, $resource_id, $item_id); if ($item_instance === null || $item_type_instance === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Responses::foreignKeyConstraintError(); + return Response::foreignKeyConstraintError(); } try { @@ -711,11 +711,11 @@ private function deleteSimpleItem( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.item'), $e); + return Response::notFound(trans('entities.item'), $e); } } @@ -746,7 +746,7 @@ private function validateAllocatedExpenseForCreate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -763,7 +763,7 @@ private function validateAllocatedExpenseForUpdate() ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } $merge_array = []; @@ -792,7 +792,7 @@ private function validateAllocatedExpenseForUpdate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -816,7 +816,7 @@ private function validateGameForCreate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -833,7 +833,7 @@ private function validateGameForUpdate() ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } $merge_array = []; @@ -862,7 +862,7 @@ private function validateGameForUpdate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -895,7 +895,7 @@ private function validateSimpleExpenseForCreate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -912,7 +912,7 @@ private function validateSimpleExpenseForUpdate() ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } $merge_array = []; @@ -941,7 +941,7 @@ private function validateSimpleExpenseForUpdate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -965,7 +965,7 @@ private function validateSimpleItemForCreate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; @@ -982,7 +982,7 @@ private function validateSimpleItemForUpdate() ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } $messages = []; @@ -997,7 +997,7 @@ private function validateSimpleItemForUpdate() ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } return null; diff --git a/app/Http/Controllers/ItemPartialTransferManage.php b/app/Http/Controllers/ItemPartialTransferManage.php index 94502378..5a8e9d1c 100644 --- a/app/Http/Controllers/ItemPartialTransferManage.php +++ b/app/Http/Controllers/ItemPartialTransferManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Jobs\ClearCache; use App\Models\ItemPartialTransfer; @@ -25,14 +25,14 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-partial-transfer')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-partial-transfer')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->deleteAllocatedExpense((int) $resource_type_id, (int) $item_partial_transfer_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -58,14 +58,14 @@ private function deleteAllocatedExpense( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.item-partial-transfer'), $e); + return Response::notFound(trans('entities.item-partial-transfer'), $e); } } @@ -76,14 +76,14 @@ public function transfer( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->transferAllocatedExpense((int) $resource_type_id, (int) $resource_id, (int) $item_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -102,13 +102,13 @@ private function transferAllocatedExpense( ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $new_resource_id = $this->hash->decode('resource', request()->input('resource_id')); if ($new_resource_id === false) { - return Responses::unableToDecode(); + return Response::unableToDecode(); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -133,9 +133,9 @@ private function transferAllocatedExpense( ClearCache::dispatch($cache_job_payload->payload()); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } $item_partial_transfer = (new ItemPartialTransfer())->single( @@ -144,7 +144,7 @@ private function transferAllocatedExpense( ); if ($item_partial_transfer === null) { - return Responses::notFound(trans('entities.item_partial_transfer')); + return Response::notFound(trans('entities.item_partial_transfer')); } return response()->json( diff --git a/app/Http/Controllers/ItemPartialTransferView.php b/app/Http/Controllers/ItemPartialTransferView.php index e40f368c..e68f25fb 100644 --- a/app/Http/Controllers/ItemPartialTransferView.php +++ b/app/Http/Controllers/ItemPartialTransferView.php @@ -7,7 +7,7 @@ use App\HttpOptionResponse\ItemPartialTransfer\AllocatedExpenseTransfer; use App\HttpRequest\Parameter; use App\HttpResponse\Header; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Models\ItemPartialTransfer; use App\Transformer\ItemPartialTransfer as ItemPartialTransferTransformer; @@ -24,14 +24,14 @@ class ItemPartialTransferView extends Controller public function index($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->allocatedExpenseCollection((int) $resource_type_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -97,14 +97,14 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->allocatedExpense((int) $resource_type_id, (int) $item_partial_transfer_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -117,7 +117,7 @@ private function allocatedExpense($resource_type_id, $item_partial_transfer_id): ); if ($item_partial_transfer === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item_partial_transfer')); + return \App\HttpResponse\Response::notFound(trans('entities.item_partial_transfer')); } $headers = new Header(); @@ -133,14 +133,14 @@ private function allocatedExpense($resource_type_id, $item_partial_transfer_id): public function optionsIndex($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseCollection((int) $resource_type_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -155,14 +155,14 @@ private function optionsAllocatedExpenseCollection(int $resource_type_id): JsonR public function optionsShow($resource_type_id, $item_partial_transfer_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-partial-transfer')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-partial-transfer')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseShow((int) $resource_type_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -181,14 +181,14 @@ public function optionsTransfer( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseTransfer((int) $resource_type_id, (int) $resource_id), - 'game', 'simple-expense', 'simple-item' => Responses::notSupported(), + 'game', 'simple-expense', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } diff --git a/app/Http/Controllers/ItemSubcategoryManage.php b/app/Http/Controllers/ItemSubcategoryManage.php index fb7a8537..ddf27568 100644 --- a/app/Http/Controllers/ItemSubcategoryManage.php +++ b/app/Http/Controllers/ItemSubcategoryManage.php @@ -28,18 +28,18 @@ public function create( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } if ($item_category_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->createItemSubcategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id, 1), - 'game', 'simple-item' => \App\HttpResponse\Responses::subcategoryAssignmentLimit(0), + 'game', 'simple-item' => \App\HttpResponse\Response::subcategoryAssignmentLimit(0), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -60,7 +60,7 @@ private function createItemSubcategory( ); if ($assigned >= $assignment_limit) { - return \App\HttpResponse\Responses::subcategoryAssignmentLimit($assignment_limit); + return \App\HttpResponse\Response::subcategoryAssignmentLimit($assignment_limit); } $item_category = (new ItemCategory()) @@ -92,7 +92,7 @@ private function createItemSubcategory( ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors( + return \App\HttpResponse\Response::validationErrors( $validator, (new \App\Models\AllowedValue\Subcategory())->allowedValues($item_category->category_id) ); @@ -111,7 +111,7 @@ private function createItemSubcategory( $subcategory_id = $this->hash->decode('subcategory', request()->input('subcategory_id')); if ($subcategory_id === false) { - return \App\HttpResponse\Responses::unableToDecode(); + return \App\HttpResponse\Response::unableToDecode(); } $item_sub_category = new ItemSubcategory([ @@ -123,7 +123,7 @@ private function createItemSubcategory( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return \App\HttpResponse\Responses::failedToSaveModelForCreate($e); + return \App\HttpResponse\Response::failedToSaveModelForCreate($e); } return response()->json( @@ -141,18 +141,18 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-subcategory')); } if ($item_category_id === null || $item_subcategory_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->deleteItemSubcategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id, (int) $item_subcategory_id), - 'game', 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'game', 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -174,7 +174,7 @@ private function deleteItemSubcategory( ); if ($item_sub_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -191,11 +191,11 @@ private function deleteItemSubcategory( ClearCache::dispatch($cache_job_payload->payload()); - return \App\HttpResponse\Responses::successNoContent(); + return \App\HttpResponse\Response::successNoContent(); } catch (QueryException $e) { - return \App\HttpResponse\Responses::foreignKeyConstraintError($e); + return \App\HttpResponse\Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory'), $e); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory'), $e); } } } diff --git a/app/Http/Controllers/ItemSubcategoryView.php b/app/Http/Controllers/ItemSubcategoryView.php index d46d7373..bb7e8715 100644 --- a/app/Http/Controllers/ItemSubcategoryView.php +++ b/app/Http/Controllers/ItemSubcategoryView.php @@ -27,14 +27,14 @@ public function index( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->itemSubcategoryCollection((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id), - 'game', 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'game', 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -96,18 +96,18 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-subcategory')); } if ($item_category_id === null || $item_subcategory_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->itemSubcategory((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id, (int) $item_subcategory_id), - 'game', 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'game', 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -129,7 +129,7 @@ private function itemSubcategory( ); if ($item_sub_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $headers = new Header(); @@ -150,11 +150,11 @@ public function optionsIndex( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } if ($item_category_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $item_type = Select::itemType((int) $resource_type_id); @@ -162,7 +162,7 @@ public function optionsIndex( return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseCollection((int) $resource_type_id, (int) $item_category_id), 'simple-expense' => $this->optionsSimpleExpenseCollection((int) $resource_type_id, (int) $item_category_id), - 'game', 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'game', 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -173,12 +173,12 @@ private function optionsAllocatedExpenseCollection( ): JsonResponse { if ($this->hasViewAccessToResourceType($resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } $item_category = (new ItemCategory())->find($item_category_id); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $response = new AllocatedExpenseCollection($this->permissions((int) $resource_type_id)); @@ -194,12 +194,12 @@ private function optionsSimpleExpenseCollection( ): JsonResponse { if ($this->hasViewAccessToResourceType($resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-category')); } $item_category = (new ItemCategory())->find($item_category_id); if ($item_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-category')); + return \App\HttpResponse\Response::notFound(trans('entities.item-category')); } $response = new SimpleExpenseCollection($this->permissions((int) $resource_type_id)); @@ -218,18 +218,18 @@ public function optionsShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-subcategory')); } if ($item_category_id === null || $item_subcategory_id === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->optionsItemSubcategoryShow((int) $resource_type_id, (int) $resource_id, (int) $item_id, (int) $item_category_id, (int) $item_subcategory_id), - 'game', 'simple-item' => \App\HttpResponse\Responses::notSupported(), + 'game', 'simple-item' => \App\HttpResponse\Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -251,7 +251,7 @@ public function optionsItemSubcategoryShow( ); if ($item_sub_category === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.item-subcategory')); } $response = new ItemSubcategoryItem($this->permissions($resource_type_id)); diff --git a/app/Http/Controllers/ItemSubtypeView.php b/app/Http/Controllers/ItemSubtypeView.php index c75a7570..fc9e6f0a 100644 --- a/app/Http/Controllers/ItemSubtypeView.php +++ b/app/Http/Controllers/ItemSubtypeView.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use App\HttpResponse\Header; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Models\ItemSubtype; use App\HttpOptionResponse\ItemSubtypeCollection; use App\HttpOptionResponse\ItemSubtypeItem; @@ -25,7 +25,7 @@ class ItemSubtypeView extends Controller public function index($item_type_id): JsonResponse { if ((new Permission())->itemTypeExists((int) $item_type_id) === false) { - return Responses::notFound(trans('entities.item-subtype')); + return Response::notFound(trans('entities.item-subtype')); } $cache_control = new \App\Cache\Control(); @@ -87,7 +87,7 @@ static function ($subtype) { public function show($item_type_id, $item_subtype_id): JsonResponse { if ((new Permission())->itemSubTypeExists((int) $item_type_id, (int) $item_subtype_id) === false) { - return Responses::notFound(trans('entities.item-subtype')); + return Response::notFound(trans('entities.item-subtype')); } $subtype = (new ItemSubtype())->single( @@ -96,7 +96,7 @@ public function show($item_type_id, $item_subtype_id): JsonResponse ); if ($subtype === null) { - return Responses::notFound(trans('entities.item-subtype')); + return Response::notFound(trans('entities.item-subtype')); } $headers = new Header(); @@ -112,7 +112,7 @@ public function show($item_type_id, $item_subtype_id): JsonResponse public function optionsIndex($item_type_id): JsonResponse { if ((new Permission())->itemTypeExists((int) $item_type_id) === false) { - return Responses::notFound(trans('entities.item-subtype')); + return Response::notFound(trans('entities.item-subtype')); } $response = new ItemSubtypeCollection(['view'=> $this->user_id !== null]); @@ -123,7 +123,7 @@ public function optionsIndex($item_type_id): JsonResponse public function optionsShow($item_type_id, $item_subtype_id): JsonResponse { if ((new Permission())->itemSubTypeExists((int) $item_type_id, (int) $item_subtype_id) === false) { - return Responses::notFound(trans('entities.item-subtype')); + return Response::notFound(trans('entities.item-subtype')); } $response = new ItemSubtypeItem(['view'=> $this->user_id !== null]); diff --git a/app/Http/Controllers/ItemTransferManage.php b/app/Http/Controllers/ItemTransferManage.php index 7a4a30fe..36f846fc 100644 --- a/app/Http/Controllers/ItemTransferManage.php +++ b/app/Http/Controllers/ItemTransferManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Jobs\ClearCache; use App\Models\Item; @@ -27,14 +27,14 @@ public function transfer( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->transferItem((int) $resource_type_id, (int) $resource_id, (int) $item_id), - 'game', 'simple-item' => Responses::notSupported(), + 'game', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -55,7 +55,7 @@ private function transferItem( ); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -70,7 +70,7 @@ private function transferItem( $new_resource_id = $this->hash->decode('resource', request()->input('resource_id')); if ($new_resource_id === false) { - return \App\HttpResponse\Responses::unableToDecode(); + return \App\HttpResponse\Response::unableToDecode(); } DB::transaction(static function() use ($resource_type_id, $resource_id, $item_id, $new_resource_id, $user_id) { @@ -79,7 +79,7 @@ private function transferItem( $item->resource_id = $new_resource_id; $item->save(); } else { - return \App\HttpResponse\Responses::failedToSelectModelForUpdateOrDelete(); + return \App\HttpResponse\Response::failedToSelectModelForUpdateOrDelete(); } $item_transfer = new ItemTransfer([ @@ -95,11 +95,11 @@ private function transferItem( ClearCache::dispatch($cache_job_payload->payload()); } catch (QueryException $e) { - return \App\HttpResponse\Responses::foreignKeyConstraintError($e); + return \App\HttpResponse\Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return \App\HttpResponse\Responses::failedToSaveModelForUpdate($e); + return \App\HttpResponse\Response::failedToSaveModelForUpdate($e); } - return \App\HttpResponse\Responses::successNoContent(); + return \App\HttpResponse\Response::successNoContent(); } } diff --git a/app/Http/Controllers/ItemTransferView.php b/app/Http/Controllers/ItemTransferView.php index 9b682518..d5e66776 100644 --- a/app/Http/Controllers/ItemTransferView.php +++ b/app/Http/Controllers/ItemTransferView.php @@ -10,7 +10,7 @@ use App\HttpOptionResponse\ItemTransfer\SimpleExpenseTransfer; use App\HttpRequest\Parameter; use App\HttpResponse\Header; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\Select; use App\Models\ItemTransfer; use App\Transformer\ItemTransfer as ItemTransferTransformer; @@ -27,14 +27,14 @@ class ItemTransferView extends Controller public function index($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-transfer')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-transfer')); } $item_type = Select::itemType((int) $resource_type_id); return match ($item_type) { 'allocated-expense', 'simple-expense' => $this->collection((int) $resource_type_id), - 'game', 'simple-item' => Responses::notSupported(), + 'game', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -97,7 +97,7 @@ static function ($transfer) { public function optionsIndex($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); @@ -105,7 +105,7 @@ public function optionsIndex($resource_type_id): JsonResponse return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseCollection((int) $resource_type_id), 'simple-expense' => $this->optionsSimpleExpenseCollection((int) $resource_type_id), - 'game', 'simple-item' => Responses::notSupported(), + 'game', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -127,7 +127,7 @@ private function optionsSimpleExpenseCollection(int $resource_type_id): JsonResp public function optionsShow($resource_type_id, $item_transfer_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $item_type = Select::itemType((int) $resource_type_id); @@ -135,7 +135,7 @@ public function optionsShow($resource_type_id, $item_transfer_id): JsonResponse return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseShow((int) $resource_type_id), 'simple-expense' => $this->optionsSimpleExpenseShow((int) $resource_type_id), - 'game', 'simple-item' => Responses::notSupported(), + 'game', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -161,7 +161,7 @@ public function optionsTransfer( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item_type = Select::itemType((int) $resource_type_id); @@ -169,7 +169,7 @@ public function optionsTransfer( return match ($item_type) { 'allocated-expense' => $this->optionsAllocatedExpenseTransfer((int) $resource_type_id, (int) $resource_id), 'simple-expense' => $this->optionsSimpleExpenseTransfer((int) $resource_type_id, (int) $resource_id), - 'game', 'simple-item' => Responses::notSupported(), + 'game', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -214,7 +214,7 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item-transfer')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item-transfer')); } $item_type = Select::itemType((int) $resource_type_id); @@ -222,7 +222,7 @@ public function show( return match ($item_type) { 'allocated-expense' => $this->allocatedExpense((int) $resource_type_id, (int) $item_transfer_id), 'simple-expense' => $this->simpleExpense((int) $resource_type_id, (int) $item_transfer_id), - 'game', 'simple-item' => Responses::notSupported(), + 'game', 'simple-item' => Response::notSupported(), default => throw new \OutOfRangeException('No item type definition for ' . $item_type, 500), }; } @@ -238,7 +238,7 @@ private function allocatedExpense( ); if ($item_transfer === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item_transfer')); + return \App\HttpResponse\Response::notFound(trans('entities.item_transfer')); } $headers = new Header(); @@ -262,7 +262,7 @@ private function simpleExpense( ); if ($item_transfer === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item_transfer')); + return \App\HttpResponse\Response::notFound(trans('entities.item_transfer')); } $headers = new Header(); diff --git a/app/Http/Controllers/ItemTypeView.php b/app/Http/Controllers/ItemTypeView.php index e121bbfd..2e0c47a7 100644 --- a/app/Http/Controllers/ItemTypeView.php +++ b/app/Http/Controllers/ItemTypeView.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use App\HttpResponse\Header; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Models\ItemType; use App\HttpOptionResponse\ItemTypeCollection; use App\HttpOptionResponse\ItemTypeItem; @@ -93,13 +93,13 @@ static function($item_type) { public function show(string $item_type_id): JsonResponse { if ((new Permission())->itemTypeExists((int) $item_type_id) === false) { - Responses::notFound(trans('entities.item-type')); + Response::notFound(trans('entities.item-type')); } $item_type = (new ItemType())->single($item_type_id); if ($item_type === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item-type')); + return \App\HttpResponse\Response::notFound(trans('entities.item-type')); } $headers = new Header(); @@ -134,7 +134,7 @@ public function optionsIndex(): JsonResponse public function optionsShow(string $item_type_id): JsonResponse { if ((new Permission())->itemTypeExists((int) $item_type_id) === false) { - Responses::notFound(trans('entities.item-type')); + Response::notFound(trans('entities.item-type')); } $response = new ItemTypeItem(['view'=> $this->user_id !== null]); diff --git a/app/Http/Controllers/ItemView.php b/app/Http/Controllers/ItemView.php index 9714d99c..7d21cc13 100644 --- a/app/Http/Controllers/ItemView.php +++ b/app/Http/Controllers/ItemView.php @@ -22,7 +22,7 @@ public function index( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -91,7 +91,7 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -159,7 +159,7 @@ public function optionsIndex( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -238,7 +238,7 @@ public function optionsShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -259,13 +259,13 @@ private function optionsAllocatedExpenseShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item = (new \App\ItemType\AllocatedExpense\Models\Item())->single($resource_type_id, $resource_id, $item_id); if ($item === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item')); + return \App\HttpResponse\Response::notFound(trans('entities.item')); } $allowed_values = new AllocatedExpenseAllowedValue( @@ -287,13 +287,13 @@ private function optionsGameShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item = (new \App\ItemType\Game\Models\Item())->single($resource_type_id, $resource_id, $item_id); if ($item === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item')); + return \App\HttpResponse\Response::notFound(trans('entities.item')); } $allowed_values = new GameAllowedValue( @@ -315,13 +315,13 @@ private function optionsSimpleExpenseShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $item = (new \App\ItemType\SimpleExpense\Models\Item())->single($resource_type_id, $resource_id, $item_id); if ($item === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item')); + return \App\HttpResponse\Response::notFound(trans('entities.item')); } $allowed_values = new SimpleExpenseAllowedValue( @@ -343,7 +343,7 @@ private function optionsSimpleItemShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.item')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.item')); } $allowed_values = new SimpleItemAllowedValue( @@ -355,7 +355,7 @@ private function optionsSimpleItemShow( $item = (new \App\ItemType\SimpleItem\Models\Item())->single($resource_type_id, $resource_id, $item_id); if ($item === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.item')); + return \App\HttpResponse\Response::notFound(trans('entities.item')); } return (new \App\HttpOptionResponse\Item\SimpleItem($this->permissions((int) $resource_type_id))) diff --git a/app/Http/Controllers/PermittedUserManage.php b/app/Http/Controllers/PermittedUserManage.php index 772ff37c..6c247609 100644 --- a/app/Http/Controllers/PermittedUserManage.php +++ b/app/Http/Controllers/PermittedUserManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Jobs\ClearCache; use App\Models\PermittedUser; use App\Models\ResourceType; @@ -22,7 +22,7 @@ class PermittedUserManage extends Controller public function create(string $resource_type_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $resource_type = (new ResourceType())->single( @@ -35,7 +35,7 @@ public function create(string $resource_type_id): JsonResponse ]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -78,10 +78,10 @@ public function create(string $resource_type_id): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } public function delete( @@ -90,13 +90,13 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.permitted-user')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.permitted-user')); } $permitted_user = (new PermittedUser())->instance($resource_type_id, $permitted_user_id); if ($permitted_user === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -112,11 +112,11 @@ public function delete( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.permitted-user'), $e); + return Response::notFound(trans('entities.permitted-user'), $e); } } } diff --git a/app/Http/Controllers/PermittedUserView.php b/app/Http/Controllers/PermittedUserView.php index 802c4201..22376d2b 100644 --- a/app/Http/Controllers/PermittedUserView.php +++ b/app/Http/Controllers/PermittedUserView.php @@ -23,7 +23,7 @@ class PermittedUserView extends Controller public function index(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $cache_control = new \App\Cache\Control( @@ -91,13 +91,13 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $permitted_user = (new PermittedUser())->single($resource_type_id, $permitted_user_id); if ($permitted_user === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.permitted-user')); + return \App\HttpResponse\Response::notFound(trans('entities.permitted-user')); } $headers = new Header(); @@ -113,7 +113,7 @@ public function show( public function optionsIndex(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $response = new PermittedUserCollection($this->permissions((int) $resource_type_id)); @@ -124,7 +124,7 @@ public function optionsIndex(string $resource_type_id): JsonResponse public function optionsShow(string $resource_type_id, string $permitted_user_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $permitted_user = (new PermittedUser())->single( @@ -133,7 +133,7 @@ public function optionsShow(string $resource_type_id, string $permitted_user_id) ); if ($permitted_user === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.permitted-user')); + return \App\HttpResponse\Response::notFound(trans('entities.permitted-user')); } $response = new PermittedUserItem($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/QueueView.php b/app/Http/Controllers/QueueView.php index d9b35c1e..a07846c6 100644 --- a/app/Http/Controllers/QueueView.php +++ b/app/Http/Controllers/QueueView.php @@ -71,13 +71,13 @@ static function($jon) { public function show(string $queue_id): JsonResponse { if ((new Permission())->queueItemExists((int) $queue_id) === false) { - return \App\HttpResponse\Responses::notFound(trans('entities.queue')); + return \App\HttpResponse\Response::notFound(trans('entities.queue')); } $job = (new Queue())->single($queue_id); if ($job === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.queue')); + return \App\HttpResponse\Response::notFound(trans('entities.queue')); } $headers = new Header(); @@ -108,7 +108,7 @@ public function optionsIndex(): JsonResponse public function optionsShow(string $queue_id): JsonResponse { if ((new Permission())->queueItemExists((int) $queue_id) === false) { - return \App\HttpResponse\Responses::notFound(trans('entities.queue')); + return \App\HttpResponse\Response::notFound(trans('entities.queue')); } $response = new QueueItem(['view'=> $this->user_id !== null]); diff --git a/app/Http/Controllers/RequestManage.php b/app/Http/Controllers/RequestManage.php index f3a95b2f..3843b522 100644 --- a/app/Http/Controllers/RequestManage.php +++ b/app/Http/Controllers/RequestManage.php @@ -28,7 +28,7 @@ public function createErrorLog(): JsonResponse $validator = (new RequestErrorLogValidator())->create(); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } try { @@ -55,9 +55,9 @@ public function createErrorLog(): JsonResponse } } catch (Exception $e) { - return \App\HttpResponse\Responses::failedToSaveModelForCreate($e); + return \App\HttpResponse\Response::failedToSaveModelForCreate($e); } - return \App\HttpResponse\Responses::successNoContent(); + return \App\HttpResponse\Response::successNoContent(); } } diff --git a/app/Http/Controllers/ResourceManage.php b/app/Http/Controllers/ResourceManage.php index 834a5e42..b707bd1a 100644 --- a/app/Http/Controllers/ResourceManage.php +++ b/app/Http/Controllers/ResourceManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Jobs\ClearCache; use App\Models\Resource; use App\Models\ResourceItemSubtype; @@ -33,7 +33,7 @@ class ResourceManage extends Controller public function create(string $resource_type_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $resource_type = (new ResourceType())->single( @@ -47,7 +47,7 @@ public function create(string $resource_type_id): JsonResponse ]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -71,7 +71,7 @@ public function create(string $resource_type_id): JsonResponse $item_subtype_id = $this->hash->decode('item-subtype', request()->input('item_subtype_id')); if ($item_subtype_id === false) { - return \App\HttpResponse\Responses::unableToDecode(); + return \App\HttpResponse\Response::unableToDecode(); } $resource_item_subtype = new ResourceItemSubtype([ @@ -86,7 +86,7 @@ public function create(string $resource_type_id): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -109,14 +109,14 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $resource = (new Resource())->instance($resource_type_id, $resource_id); $resource_item_subtype = (new ResourceItemSubtype())->instance($resource_id); if ($resource === null || $resource_item_subtype === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -136,11 +136,11 @@ public function delete( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.resource'), $e); + return Response::notFound(trans('entities.resource'), $e); } } @@ -158,17 +158,17 @@ public function update( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $resource = (new Resource())->instance($resource_type_id, $resource_id); if ($resource === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } if (count(request()->all()) === 0) { - return \App\HttpResponse\Responses::nothingToPatch(); + return \App\HttpResponse\Response::nothingToPatch(); } $validator = (new ResourceValidator())->update([ @@ -177,7 +177,7 @@ public function update( ]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $invalid_fields = $this->checkForInvalidFields( @@ -188,7 +188,7 @@ public function update( ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } foreach (request()->all() as $key => $value) { @@ -209,9 +209,9 @@ public function update( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } } diff --git a/app/Http/Controllers/ResourceTypeItemView.php b/app/Http/Controllers/ResourceTypeItemView.php index e733ac80..4afda354 100644 --- a/app/Http/Controllers/ResourceTypeItemView.php +++ b/app/Http/Controllers/ResourceTypeItemView.php @@ -21,7 +21,7 @@ class ResourceTypeItemView extends Controller public function index(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $item_type = Select::itemType((int) $resource_type_id); @@ -82,7 +82,7 @@ private function simpleItemCollection(int $resource_type_id): JsonResponse public function optionsIndex(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $item_type = Select::itemType((int) $resource_type_id); diff --git a/app/Http/Controllers/ResourceTypeManage.php b/app/Http/Controllers/ResourceTypeManage.php index fc063a18..bd7a5595 100644 --- a/app/Http/Controllers/ResourceTypeManage.php +++ b/app/Http/Controllers/ResourceTypeManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Jobs\ClearCache; use App\Models\Category; use App\Models\PermittedUser; @@ -36,7 +36,7 @@ public function create(Request $request): JsonResponse ]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -65,7 +65,7 @@ public function create(Request $request): JsonResponse $item_type_id = $this->hash->decode('item-type', $request->input('item_type_id')); if ($item_type_id === false) { - return \App\HttpResponse\Responses::unableToDecode(); + return \App\HttpResponse\Response::unableToDecode(); } $resource_type_item_type = new ResourceTypeItemType([ @@ -80,7 +80,7 @@ public function create(Request $request): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return \App\HttpResponse\Responses::failedToSaveModelForCreate($e); + return \App\HttpResponse\Response::failedToSaveModelForCreate($e); } return response()->json( @@ -95,7 +95,7 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $resource_type_item_type = (new ResourceTypeItemType())->instance($resource_type_id); @@ -136,14 +136,14 @@ public function delete( ClearCache::dispatch($cache_job_payload->payload()); - return \App\HttpResponse\Responses::successNoContent(); + return \App\HttpResponse\Response::successNoContent(); } catch (QueryException $e) { - return \App\HttpResponse\Responses::foreignKeyConstraintError($e); + return \App\HttpResponse\Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return \App\HttpResponse\Responses::notFound(trans('entities.resource-type'), $e); + return \App\HttpResponse\Response::notFound(trans('entities.resource-type'), $e); } } else { - return \App\HttpResponse\Responses::foreignKeyConstraintError(); + return \App\HttpResponse\Response::foreignKeyConstraintError(); } } @@ -153,17 +153,17 @@ public function update( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $resource_type = (new ResourceType())->instance($resource_type_id); if ($resource_type === null) { - return \App\HttpResponse\Responses::failedToSelectModelForUpdateOrDelete(); + return \App\HttpResponse\Response::failedToSelectModelForUpdateOrDelete(); } if (count($request->all()) === 0) { - return \App\HttpResponse\Responses::nothingToPatch(); + return \App\HttpResponse\Response::nothingToPatch(); } $validator = (new ResourceTypeValidator())->update([ @@ -172,7 +172,7 @@ public function update( ]); if ($validator !== null && $validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $invalid_fields = $this->checkForInvalidFields( @@ -183,7 +183,7 @@ public function update( ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } foreach ($request->all() as $key => $value) { @@ -204,9 +204,9 @@ public function update( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return \App\HttpResponse\Responses::failedToSaveModelForUpdate($e); + return \App\HttpResponse\Response::failedToSaveModelForUpdate($e); } - return \App\HttpResponse\Responses::successNoContent(); + return \App\HttpResponse\Response::successNoContent(); } } diff --git a/app/Http/Controllers/ResourceTypeView.php b/app/Http/Controllers/ResourceTypeView.php index de68ae71..1a4637fc 100644 --- a/app/Http/Controllers/ResourceTypeView.php +++ b/app/Http/Controllers/ResourceTypeView.php @@ -6,7 +6,7 @@ use App\HttpOptionResponse\ResourceTypeItem; use App\HttpRequest\Parameter; use App\HttpResponse\Header; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Models\AllowedValue\ItemType; use App\Models\PermittedUser; use App\Models\Resource; @@ -104,7 +104,7 @@ public function show($resource_type_id): JsonResponse ); if ($resource_type === null) { - return Responses::notFound(trans('entities.resource-type')); + return Response::notFound(trans('entities.resource-type')); } $transformer_relations = []; diff --git a/app/Http/Controllers/ResourceView.php b/app/Http/Controllers/ResourceView.php index da1f7564..36e29597 100644 --- a/app/Http/Controllers/ResourceView.php +++ b/app/Http/Controllers/ResourceView.php @@ -34,7 +34,7 @@ class ResourceView extends Controller public function index(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $cache_control = new \App\Cache\Control( @@ -121,13 +121,13 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $resource = (new Resource)->single($resource_type_id, $resource_id); if ($resource === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.resource')); + return \App\HttpResponse\Response::notFound(trans('entities.resource')); } $headers = new Header(); @@ -143,7 +143,7 @@ public function show( public function optionsIndex(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $resource_type = (new ResourceType())->single( @@ -161,7 +161,7 @@ public function optionsIndex(string $resource_type_id): JsonResponse public function optionsShow(string $resource_type_id, string $resource_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource')); } $resource = (new Resource)->single( @@ -170,7 +170,7 @@ public function optionsShow(string $resource_type_id, string $resource_id): Json ); if ($resource === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.resource')); + return \App\HttpResponse\Response::notFound(trans('entities.resource')); } $response = new ResourceItem($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/SubcategoryManage.php b/app/Http/Controllers/SubcategoryManage.php index 9a8c88cb..0fec561e 100644 --- a/app/Http/Controllers/SubcategoryManage.php +++ b/app/Http/Controllers/SubcategoryManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Jobs\ClearCache; use App\Models\Subcategory; use App\HttpRequest\Validate\Subcategory as SubcategoryValidator; @@ -33,13 +33,13 @@ class SubcategoryManage extends Controller public function create($resource_type_id, $category_id): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $validator = (new SubcategoryValidator)->create(['category_id' => $category_id]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -62,7 +62,7 @@ public function create($resource_type_id, $category_id): JsonResponse ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForCreate($e); + return Response::failedToSaveModelForCreate($e); } return response()->json( @@ -87,7 +87,7 @@ public function delete( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.subcategory')); } $sub_category = (new Subcategory())->instance( @@ -96,7 +96,7 @@ public function delete( ); if ($sub_category === null) { - return Responses::notFound(trans('entities.subcategory')); + return Response::notFound(trans('entities.subcategory')); } $cache_job_payload = (new \App\Cache\JobPayload()) @@ -113,11 +113,11 @@ public function delete( ClearCache::dispatch($cache_job_payload->payload()); - return Responses::successNoContent(); + return Response::successNoContent(); } catch (QueryException $e) { - return Responses::foreignKeyConstraintError($e); + return Response::foreignKeyConstraintError($e); } catch (Exception $e) { - return Responses::notFound(trans('entities.subcategory'), $e); + return Response::notFound(trans('entities.subcategory'), $e); } } @@ -137,17 +137,17 @@ public function update( ): JsonResponse { if ($this->hasWriteAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.subcategory')); } $subcategory = (new Subcategory())->instance($category_id, $subcategory_id); if ($subcategory === null) { - return Responses::failedToSelectModelForUpdateOrDelete(); + return Response::failedToSelectModelForUpdateOrDelete(); } if (count(request()->all()) === 0) { - return \App\HttpResponse\Responses::nothingToPatch(); + return \App\HttpResponse\Response::nothingToPatch(); } $validator = (new SubcategoryValidator())->update([ @@ -156,7 +156,7 @@ public function update( ]); if ($validator->fails()) { - return \App\HttpResponse\Responses::validationErrors($validator); + return \App\HttpResponse\Response::validationErrors($validator); } $invalid_fields = $this->checkForInvalidFields( @@ -167,7 +167,7 @@ public function update( ); if (count($invalid_fields) > 0) { - return Responses::invalidFieldsInRequest($invalid_fields); + return Response::invalidFieldsInRequest($invalid_fields); } foreach (request()->all() as $key => $value) { @@ -189,9 +189,9 @@ public function update( ClearCache::dispatch($cache_job_payload->payload()); } catch (Exception $e) { - return Responses::failedToSaveModelForUpdate($e); + return Response::failedToSaveModelForUpdate($e); } - return Responses::successNoContent(); + return Response::successNoContent(); } } diff --git a/app/Http/Controllers/SubcategoryView.php b/app/Http/Controllers/SubcategoryView.php index 5869ed3e..b4b8f116 100644 --- a/app/Http/Controllers/SubcategoryView.php +++ b/app/Http/Controllers/SubcategoryView.php @@ -25,7 +25,7 @@ class SubcategoryView extends Controller public function index($resource_type_id, $category_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $cache_control = new \App\Cache\Control( @@ -115,7 +115,7 @@ public function show( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.subcategory')); } $subcategory = (new Subcategory())->single( @@ -124,7 +124,7 @@ public function show( ); if ($subcategory === null) { - return \App\HttpResponse\Responses::notFound(trans('entities.subcategory')); + return \App\HttpResponse\Response::notFound(trans('entities.subcategory')); } $headers = new Header(); @@ -148,7 +148,7 @@ public function show( public function optionsIndex($resource_type_id, $category_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $response = new SubcategoryCollection($this->permissions((int) $resource_type_id)); @@ -172,7 +172,7 @@ public function optionsShow( ): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.subcategory')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.subcategory')); } $response = new SubcategoryItem($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/Summary/CategoryView.php b/app/Http/Controllers/Summary/CategoryView.php index ddbd0ce8..9b485d68 100644 --- a/app/Http/Controllers/Summary/CategoryView.php +++ b/app/Http/Controllers/Summary/CategoryView.php @@ -30,7 +30,7 @@ class CategoryView extends Controller public function index($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $cache_control = new \App\Cache\Control( @@ -95,7 +95,7 @@ public function index($resource_type_id): JsonResponse public function optionsIndex($resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $response = new SummaryCategoryCollection($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/Summary/ItemView.php b/app/Http/Controllers/Summary/ItemView.php index 17e9f708..f4c8db88 100644 --- a/app/Http/Controllers/Summary/ItemView.php +++ b/app/Http/Controllers/Summary/ItemView.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Summary; use App\Http\Controllers\Controller; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\AllocatedExpense\AllowedValue as AllocatedExpenseAllowedValue; use App\ItemType\Game\AllowedValue as GameAllowedValue; use App\ItemType\SimpleExpense\AllowedValue as SimpleExpenseAllowedValue; @@ -20,7 +20,7 @@ class ItemView extends Controller public function index(string $resource_type_id, string $resource_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -85,7 +85,7 @@ private function simpleItemSummary(int $resource_type_id, int $resource_id): Jso public function optionsIndex(string $resource_type_id, string $resource_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); diff --git a/app/Http/Controllers/Summary/ResourceTypeItemView.php b/app/Http/Controllers/Summary/ResourceTypeItemView.php index 55a5d10c..a1455859 100644 --- a/app/Http/Controllers/Summary/ResourceTypeItemView.php +++ b/app/Http/Controllers/Summary/ResourceTypeItemView.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Summary; use App\Http\Controllers\Controller; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\AllocatedExpense\AllowedValue as AllocatedExpenseAllowedValue; use App\ItemType\Game\AllowedValue as GameAllowedValue; use App\ItemType\SimpleExpense\AllowedValue as SimpleExpenseAllowedValue; @@ -25,7 +25,7 @@ class ResourceTypeItemView extends Controller public function index(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); @@ -86,7 +86,7 @@ private function simpleItemSummary(int $resource_type_id): JsonResponse public function optionsIndex(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return Responses::notFoundOrNotAccessible(trans('entities.resource')); + return Response::notFoundOrNotAccessible(trans('entities.resource')); } $item_type = Select::itemType((int) $resource_type_id); diff --git a/app/Http/Controllers/Summary/ResourceView.php b/app/Http/Controllers/Summary/ResourceView.php index 3175ad62..a2ea59d0 100644 --- a/app/Http/Controllers/Summary/ResourceView.php +++ b/app/Http/Controllers/Summary/ResourceView.php @@ -29,7 +29,7 @@ class ResourceView extends Controller public function index(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $cache_control = new \App\Cache\Control( @@ -95,7 +95,7 @@ public function index(string $resource_type_id): JsonResponse public function optionsIndex(string $resource_type_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.resource-type')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.resource-type')); } $response = new SummaryResourceCollection($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/Summary/SubcategoryView.php b/app/Http/Controllers/Summary/SubcategoryView.php index a46c2ef5..ed4ceca9 100644 --- a/app/Http/Controllers/Summary/SubcategoryView.php +++ b/app/Http/Controllers/Summary/SubcategoryView.php @@ -30,7 +30,7 @@ class SubcategoryView extends Controller public function index($resource_type_id, $category_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $cache_control = new \App\Cache\Control( @@ -97,7 +97,7 @@ public function index($resource_type_id, $category_id): JsonResponse public function optionsIndex($resource_type_id, $category_id): JsonResponse { if ($this->hasViewAccessToResourceType((int) $resource_type_id) === false) { - return \App\HttpResponse\Responses::notFoundOrNotAccessible(trans('entities.category')); + return \App\HttpResponse\Response::notFoundOrNotAccessible(trans('entities.category')); } $response = new SummarySubcategoryCollection($this->permissions((int) $resource_type_id)); diff --git a/app/Http/Controllers/ToolManage.php b/app/Http/Controllers/ToolManage.php index 06181509..305096f4 100644 --- a/app/Http/Controllers/ToolManage.php +++ b/app/Http/Controllers/ToolManage.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use Illuminate\Http\JsonResponse; /** @@ -37,6 +37,6 @@ public function deleteCache(): JsonResponse } // This will leave two cache keys set in the base controller - return Responses::successNoContent(); + return Response::successNoContent(); } } diff --git a/app/Http/Middleware/ConvertGetParameters.php b/app/Http/Middleware/ConvertGetParameters.php index 608830fc..4bd34d3b 100644 --- a/app/Http/Middleware/ConvertGetParameters.php +++ b/app/Http/Middleware/ConvertGetParameters.php @@ -3,7 +3,7 @@ namespace App\Http\Middleware; use App\HttpRequest\Hash; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use Closure; use Illuminate\Http\Request; diff --git a/app/Http/Middleware/ConvertRouteParameters.php b/app/Http/Middleware/ConvertRouteParameters.php index 8ccf7cb2..c8752cf9 100644 --- a/app/Http/Middleware/ConvertRouteParameters.php +++ b/app/Http/Middleware/ConvertRouteParameters.php @@ -2,7 +2,7 @@ namespace App\Http\Middleware; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\HttpRequest\Hash; use Closure; @@ -51,11 +51,11 @@ public function handle($request, Closure $next) $id = $hash->decode($route_params[$param], $param_value); if ($id === false) { - return Responses::notFoundOrNotAccessible($route_params[$param]); + return Response::notFoundOrNotAccessible($route_params[$param]); } if (is_int($id) === false) { - return Responses::notFoundOrNotAccessible($route_params[$param]); + return Response::notFoundOrNotAccessible($route_params[$param]); } $request->route()->setParameter($param, $id); diff --git a/app/HttpResponse/Responses.php b/app/HttpResponse/Response.php similarity index 99% rename from app/HttpResponse/Responses.php rename to app/HttpResponse/Response.php index 41239a4e..68de8383 100644 --- a/app/HttpResponse/Responses.php +++ b/app/HttpResponse/Response.php @@ -13,7 +13,7 @@ * @copyright Dean Blackborough 2018-2022 * @license https://github.com/costs-to-expect/api/blob/master/LICENSE */ -class Responses +class Response { private static function addException(array $response, Throwable $e = null): array { diff --git a/app/ItemType/AllocatedExpense/AllowedValue.php b/app/ItemType/AllocatedExpense/AllowedValue.php index ac668893..deae8c42 100644 --- a/app/ItemType/AllocatedExpense/AllowedValue.php +++ b/app/ItemType/AllocatedExpense/AllowedValue.php @@ -5,7 +5,7 @@ use App\HttpRequest\Hash; use App\HttpRequest\Parameter\Request; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Models\Category; use App\Models\EntityLimits; use App\Models\Subcategory; @@ -116,7 +116,7 @@ private function assignAllowedValuesForCategory(): array $category_id = $this->hash->encode('category', $category['category_id']); if ($category_id === false) { - Responses::unableToDecode(); + Response::unableToDecode(); } $allowed_values[$category_id] = [ @@ -142,7 +142,7 @@ private function assignAllowedValuesForCurrency(): array $id = $this->hash->encode('currency', $currency['currency_id']); if ($id === false) { - Responses::unableToDecode(); + Response::unableToDecode(); } $allowed_values[$id] = [ diff --git a/app/ItemType/AllocatedExpense/HttpResponse/Item.php b/app/ItemType/AllocatedExpense/HttpResponse/Item.php index 146cb9e0..47ab5b42 100644 --- a/app/ItemType/AllocatedExpense/HttpResponse/Item.php +++ b/app/ItemType/AllocatedExpense/HttpResponse/Item.php @@ -7,7 +7,7 @@ use App\HttpRequest\Parameter\Request; use App\HttpRequest\Parameter\Search; use App\HttpRequest\Parameter\Sort; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\HttpResponse\ApiItemResponse; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Config as LaravelConfig; @@ -99,7 +99,7 @@ public function showResponse(int $item_id): JsonResponse ); if ($item === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } return response()->json( diff --git a/app/ItemType/Game/HttpResponse/Item.php b/app/ItemType/Game/HttpResponse/Item.php index 910cb4d8..83bd9dc4 100644 --- a/app/ItemType/Game/HttpResponse/Item.php +++ b/app/ItemType/Game/HttpResponse/Item.php @@ -7,7 +7,7 @@ use App\HttpRequest\Parameter\Request; use App\HttpRequest\Parameter\Search; use App\HttpRequest\Parameter\Sort; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\HttpResponse\ApiItemResponse; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Config as LaravelConfig; @@ -95,7 +95,7 @@ public function showResponse(int $item_id): JsonResponse ); if ($item === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } return response()->json( diff --git a/app/ItemType/SimpleExpense/AllowedValue.php b/app/ItemType/SimpleExpense/AllowedValue.php index e86125be..b6e47f7b 100644 --- a/app/ItemType/SimpleExpense/AllowedValue.php +++ b/app/ItemType/SimpleExpense/AllowedValue.php @@ -5,7 +5,7 @@ use App\HttpRequest\Hash; use App\HttpRequest\Parameter\Request; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\Models\Category; use App\Models\Subcategory; use Illuminate\Support\Facades\Config; @@ -104,7 +104,7 @@ private function assignAllowedValuesForCategory(): array $category_id = $this->hash->encode('category', $category['category_id']); if ($category_id === false) { - Responses::unableToDecode(); + Response::unableToDecode(); } $allowed_values[$category_id] = [ @@ -130,7 +130,7 @@ private function assignAllowedValuesForCurrency(): array $id = $this->hash->encode('currency', $currency['currency_id']); if ($id === false) { - Responses::unableToDecode(); + Response::unableToDecode(); } $allowed_values[$id] = [ diff --git a/app/ItemType/SimpleExpense/HttpResponse/Item.php b/app/ItemType/SimpleExpense/HttpResponse/Item.php index 57138e5c..fc65ba79 100644 --- a/app/ItemType/SimpleExpense/HttpResponse/Item.php +++ b/app/ItemType/SimpleExpense/HttpResponse/Item.php @@ -7,7 +7,7 @@ use App\HttpRequest\Parameter\Request; use App\HttpRequest\Parameter\Search; use App\HttpRequest\Parameter\Sort; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\HttpResponse\ApiItemResponse; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Config as LaravelConfig; @@ -95,7 +95,7 @@ public function showResponse(int $item_id): JsonResponse ); if ($item === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } return response()->json( diff --git a/app/ItemType/SimpleItem/HttpResponse/Item.php b/app/ItemType/SimpleItem/HttpResponse/Item.php index e0ad906e..6b6904ca 100644 --- a/app/ItemType/SimpleItem/HttpResponse/Item.php +++ b/app/ItemType/SimpleItem/HttpResponse/Item.php @@ -7,7 +7,7 @@ use App\HttpRequest\Parameter\Request; use App\HttpRequest\Parameter\Search; use App\HttpRequest\Parameter\Sort; -use App\HttpResponse\Responses; +use App\HttpResponse\Response; use App\ItemType\HttpResponse\ApiItemResponse; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Config as LaravelConfig; @@ -94,7 +94,7 @@ public function showResponse(int $item_id): JsonResponse ); if ($item === null) { - return Responses::notFound(trans('entities.item')); + return Response::notFound(trans('entities.item')); } return response()->json( diff --git a/app/Models/AllowedValue/Category.php b/app/Models/AllowedValue/Category.php index fe537f3c..0d056995 100644 --- a/app/Models/AllowedValue/Category.php +++ b/app/Models/AllowedValue/Category.php @@ -32,7 +32,7 @@ public function allowedValues(int $resource_type_id, string $field_name = 'categ $id = $this->hash->encode('category', $category['category_id']); if ($id === false) { - \App\HttpResponse\Responses::unableToDecode(); + \App\HttpResponse\Response::unableToDecode(); } $parameters[$field_name]['allowed_values'][$id] = [ diff --git a/app/Models/AllowedValue/Currency.php b/app/Models/AllowedValue/Currency.php index b78c22e4..1a47903d 100644 --- a/app/Models/AllowedValue/Currency.php +++ b/app/Models/AllowedValue/Currency.php @@ -24,7 +24,7 @@ public function allowedValues(): array $id = $this->hash->encode('currency', $currency['currency_id']); if ($id === false) { - \App\HttpResponse\Responses::unableToDecode(); + \App\HttpResponse\Response::unableToDecode(); } $parameters['currency_id']['allowed_values'][$id] = [ diff --git a/app/Models/AllowedValue/ItemSubtype.php b/app/Models/AllowedValue/ItemSubtype.php index 1bedd1ae..bd47712c 100644 --- a/app/Models/AllowedValue/ItemSubtype.php +++ b/app/Models/AllowedValue/ItemSubtype.php @@ -24,7 +24,7 @@ public function allowedValues(int $item_type_id): array $id = $this->hash->encode('item-subtype', $item_subtype['item_subtype_id']); if ($id === false) { - \App\HttpResponse\Responses::unableToDecode(); + \App\HttpResponse\Response::unableToDecode(); } $parameters['item_subtype_id']['allowed_values'][$id] = [ diff --git a/app/Models/AllowedValue/ItemType.php b/app/Models/AllowedValue/ItemType.php index a34169ac..07fa2b4d 100644 --- a/app/Models/AllowedValue/ItemType.php +++ b/app/Models/AllowedValue/ItemType.php @@ -30,7 +30,7 @@ public function allowedValues(): array $id = $this->hash->encode('item-type', $item_type['item_type_id']); if ($id === false) { - \App\HttpResponse\Responses::unableToDecode(); + \App\HttpResponse\Response::unableToDecode(); } $parameters['item_type_id']['allowed_values'][$id] = [ diff --git a/app/Models/AllowedValue/Resource.php b/app/Models/AllowedValue/Resource.php index 91153a53..42a300c9 100644 --- a/app/Models/AllowedValue/Resource.php +++ b/app/Models/AllowedValue/Resource.php @@ -35,7 +35,7 @@ public function allowedValues(int $resource_type_id, int $exclude_resource_id): $id = $this->hash->encode('resource', $resource['resource_id']); if ($id === false) { - \App\HttpResponse\Responses::unableToDecode(); + \App\HttpResponse\Response::unableToDecode(); } $parameters['resource_id']['allowed_values'][$id] = [ diff --git a/app/Models/AllowedValue/Subcategory.php b/app/Models/AllowedValue/Subcategory.php index d7e4ac43..fd32a3a7 100644 --- a/app/Models/AllowedValue/Subcategory.php +++ b/app/Models/AllowedValue/Subcategory.php @@ -35,7 +35,7 @@ public function allowedValues(int $category_id): array $id = $this->hash->encode('subcategory', $subcategory->id); if ($id === false) { - \App\HttpResponse\Responses::unableToDecode(); + \App\HttpResponse\Response::unableToDecode(); } $parameters['subcategory_id']['allowed_values'][$id] = [ From 371843346d114dec69b8393803abbd93416c66cd Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Thu, 16 Jun 2022 22:22:39 +0100 Subject: [PATCH 12/32] Moved responses - Moved additional responses to the response class --- app/Http/Controllers/Authentication.php | 21 ++++++++-------- app/HttpResponse/Response.php | 32 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Authentication.php b/app/Http/Controllers/Authentication.php index 4f514dcf..088ceeb9 100644 --- a/app/Http/Controllers/Authentication.php +++ b/app/Http/Controllers/Authentication.php @@ -20,7 +20,6 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Validation\Rule; @@ -321,10 +320,10 @@ public function login(Request $request): Http\JsonResponse ); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function optionsLogin(): Http\JsonResponse @@ -391,7 +390,7 @@ public function register(Request $request): Http\JsonResponse } } catch (Exception $e) { - return response()->json(['error' => trans('auth.unable-to-create-account')], 500); + return Response::unableToCreateAccount($e); } return response()->json( @@ -453,7 +452,7 @@ public function updatePassword(Request $request): Http\JsonResponse return response()->json([], 204); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function optionsUpdateProfile(): Http\JsonResponse @@ -511,7 +510,7 @@ public function updateProfile(Request $request): Http\JsonResponse } if (count($fields) === 0) { - return response()->json(['message' => trans('responses.patch-empty')], 400); + return Response::nothingToPatch(); } try { @@ -528,7 +527,7 @@ public function updateProfile(Request $request): Http\JsonResponse return response()->json([], 204); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function user(): Http\JsonResponse @@ -562,7 +561,7 @@ public function user(): Http\JsonResponse return response()->json($user); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function tokens(): Http\JsonResponse @@ -585,7 +584,7 @@ public function tokens(): Http\JsonResponse return response()->json($tokens); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function token($token_id): Http\JsonResponse @@ -612,7 +611,7 @@ public function token($token_id): Http\JsonResponse return Response::notFound(); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function deleteToken($token_id): Http\JsonResponse @@ -640,7 +639,7 @@ public function deleteToken($token_id): Http\JsonResponse return Response::notFound(); } - return response()->json(['message' => trans('auth.failed')], 401); + return Response::authenticationFailed(); } public function optionsUser(): Http\JsonResponse diff --git a/app/HttpResponse/Response.php b/app/HttpResponse/Response.php index 68de8383..180893da 100644 --- a/app/HttpResponse/Response.php +++ b/app/HttpResponse/Response.php @@ -127,6 +127,22 @@ public static function authenticationRequired(?Throwable $e = null): JsonRespons ); } + public static function authenticationFailed(?Throwable $e = null): JsonResponse + { + $response = [ + 'message' => trans('auth.failed') + ]; + + if ($e instanceOf Throwable && app()->environment() !== 'production') { + $response = self::addException($response, $e); + } + + return response()->json( + $response, + 401 + ); + } + public static function categoryAssignmentLimit(int $limit): JsonResponse { $response = [ @@ -164,6 +180,22 @@ public static function failedToSaveModelForCreate(?Throwable $e = null): JsonRes ); } + public static function unableToCreateAccount(?Throwable $e = null): JsonResponse + { + $response = [ + 'message' => trans('auth.unable-to-create-account') + ]; + + if ($e instanceOf Throwable && app()->environment() !== 'production') { + $response = self::addException($response, $e); + } + + return response()->json( + $response, + 500 + ); + } + public static function unableToDecode(): JsonResponse { return response()->json( From dca261e84614edcd04f329e2f235d3776f258bf9 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Thu, 16 Jun 2022 22:42:40 +0100 Subject: [PATCH 13/32] Allow entire collection - Allow fetching the entire collection for simple item type --- app/HttpOptionResponse/Item/SimpleItemCollection.php | 2 +- app/ItemType/HttpResponse/ApiItemResponse.php | 4 ++-- app/ItemType/SimpleItem/HttpResponse/Item.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/HttpOptionResponse/Item/SimpleItemCollection.php b/app/HttpOptionResponse/Item/SimpleItemCollection.php index cc6af232..d4f52bb1 100644 --- a/app/HttpOptionResponse/Item/SimpleItemCollection.php +++ b/app/HttpOptionResponse/Item/SimpleItemCollection.php @@ -18,7 +18,7 @@ public function create() ->setFilterableParameters(LaravelConfig::get($base_path . '.filterable', [])) ->setParameters(LaravelConfig::get($base_path . '.parameters', [])) ->setDynamicParameters($this->allowed_parameters) - ->setPaginationStatus(true) + ->setPaginationStatus(true, true) ->setAuthenticationStatus($this->permissions['view']) ->setDescription('route-descriptions.item_GET_index') ->option(); diff --git a/app/ItemType/HttpResponse/ApiItemResponse.php b/app/ItemType/HttpResponse/ApiItemResponse.php index 6c17fc37..56336779 100644 --- a/app/ItemType/HttpResponse/ApiItemResponse.php +++ b/app/ItemType/HttpResponse/ApiItemResponse.php @@ -82,10 +82,10 @@ protected function showHeaders(): array return $headers->headers(); } - protected function pagination_parameters(int $total): array + protected function pagination_parameters(int $total, bool $allow_override = false): array { $pagination = new UtilityPagination(request()->path(), $total); - return $pagination->allowPaginationOverride(false) + return $pagination->allowPaginationOverride($allow_override) ->setSearchParameters($this->search_parameters) ->setSortParameters($this->sort_fields) ->setParameters($this->request_parameters) diff --git a/app/ItemType/SimpleItem/HttpResponse/Item.php b/app/ItemType/SimpleItem/HttpResponse/Item.php index 6b6904ca..7675762e 100644 --- a/app/ItemType/SimpleItem/HttpResponse/Item.php +++ b/app/ItemType/SimpleItem/HttpResponse/Item.php @@ -40,7 +40,7 @@ public function collectionResponse(): JsonResponse $this->filter_parameters ); - $pagination_parameters = $this->pagination_parameters($total); + $pagination_parameters = $this->pagination_parameters($total, true); $items = $model->paginatedCollection( $this->resource_type_id, From 8d4410768d0a25695c5bb5ee1811fa62c7ed3f74 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 10:40:30 +0100 Subject: [PATCH 14/32] Options scheme - Working on the options schema for the resource type collection. --- Tests/TestCase.php | 5 + .../Http/Controllers/ResourceTypeViewTest.php | 9 + .../options/resource-type-collection.json | 261 ++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 public/api/schema/options/resource-type-collection.json diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 16eb1204..9e2a584c 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -273,6 +273,11 @@ protected function optionsRegister(array $parameters = []): TestResponse return $this->optionsRoute('auth.register.options', $parameters); } + protected function optionsResourceTypeCollection(array $parameters = []): TestResponse + { + return $this->optionsRoute('resource-type.list.options', $parameters); + } + protected function optionsRoute(string $route, array $parameters = []): TestResponse { return $this->options(route($route, $parameters)); diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index 914b15b7..d40e21af 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -7,6 +7,15 @@ final class ResourceTypeViewTest extends TestCase { + /** @test */ + public function optionsRequestForResourceTypeCollection(): void + { + $response = $this->optionsResourceTypeCollection(); + $response->assertStatus(200); + + $this->assertJsonMatchesSchema($response->content(), 'api/schema/options/resource-type-collection.json'); + } + /** @test */ public function resourceTypeCollection(): void { diff --git a/public/api/schema/options/resource-type-collection.json b/public/api/schema/options/resource-type-collection.json new file mode 100644 index 00000000..eaf8a119 --- /dev/null +++ b/public/api/schema/options/resource-type-collection.json @@ -0,0 +1,261 @@ +{ + "type": "object", + "properties": { + "GET": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + }, + "sortable": { + "type": "array" + }, + "searchable": { + "type": "object" + }, + "filterable": { + "type": [ + "object", + "array" + ] + }, + "parameters": { + "type":"object" + } + }, + "required": [ + "description", + "authentication", + "sortable", + "searchable", + "filterable", + "parameters" + ] + }, + "POST": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + }, + "fields": { + "type": "object", + "properties": { + "name": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "validation": { + "type": "object", + "properties": { + "max-length": { + "type": "integer" + } + }, + "required": [ + "max-length" + ] + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "validation", + "required" + ] + }, + "description": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "data": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "item_type_id": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "validation": { + "type": "object", + "properties": { + "length": { + "type": "integer" + } + }, + "required": [ + "length" + ] + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "validation", + "required" + ] + }, + "public": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + } + }, + "required": [ + "name", + "description", + "data", + "item_type_id", + "public" + ] + }, + "parameters": { + "type": [ + "object", + "array" + ] + } + }, + "required": [ + "description", + "authentication", + "fields", + "parameters" + ] + } + }, + "required": [ + "GET", + "POST" + ] +} \ No newline at end of file From 1a9169272afc6c16bb8e9ba0870d4239747008c8 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 10:46:25 +0100 Subject: [PATCH 15/32] Schema file - Schema file for an options request --- .../options/resource-type-collection.json | 89 ++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/public/api/schema/options/resource-type-collection.json b/public/api/schema/options/resource-type-collection.json index eaf8a119..eb7d4832 100644 --- a/public/api/schema/options/resource-type-collection.json +++ b/public/api/schema/options/resource-type-collection.json @@ -192,6 +192,93 @@ }, "required": { "type": "boolean" + }, + "allowed_values": { + "type": "object", + "properties": { + "OqZwKX16bW": { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "value", + "name", + "description" + ] + }, + "gjp4P71YJe": { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "value", + "name", + "description" + ] + }, + "QxO1VLyM86": { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "value", + "name", + "description" + ] + }, + "2AP1axw6L7": { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "value", + "name", + "description" + ] + } + }, + "required": [ + "OqZwKX16bW", + "gjp4P71YJe", + "QxO1VLyM86", + "2AP1axw6L7" + ] } }, "required": [ @@ -258,4 +345,4 @@ "GET", "POST" ] -} \ No newline at end of file +} From ff31bcb24f30454a1390ce76501189ae9d321a78 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 11:24:53 +0100 Subject: [PATCH 16/32] Options response schema - Options response schema for resource types collection --- .../options/resource-type-collection.json | 196 +++++++++++++++++- 1 file changed, 193 insertions(+), 3 deletions(-) diff --git a/public/api/schema/options/resource-type-collection.json b/public/api/schema/options/resource-type-collection.json index eb7d4832..cc9f7268 100644 --- a/public/api/schema/options/resource-type-collection.json +++ b/public/api/schema/options/resource-type-collection.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/options/resource-type-collection.json", "type": "object", "properties": { "GET": { @@ -23,10 +24,35 @@ ] }, "sortable": { - "type": "array" + "type": "array", + "items": { + "type": "string" + } }, "searchable": { - "type": "object" + "type": "object", + "properties": { + "name": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + } + }, + "description": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + } + } + }, + "required": [ + "name", + "description" + ] }, "filterable": { "type": [ @@ -35,7 +61,171 @@ ] }, "parameters": { - "type":"object" + "type":"object", + "properties": { + "offset": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "limit": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "collection": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "boolean" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "sort": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "null" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "search": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "null" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + } + }, + "required": [ + "offset", + "limit", + "collection", + "sort", + "search" + ] } }, "required": [ From cd5dd148f262b450c6dcf43ba0ccf6920ed85a0c Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 11:41:43 +0100 Subject: [PATCH 17/32] Update README - Update the readme with the new test --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a6faa53..cda32b3d 100644 --- a/README.md +++ b/README.md @@ -276,8 +276,8 @@ our local test suite is as complete as the Postman request tests. | RequestManage (Actions) | Not started | | ResourceManage (Actions) | Complete (14 Tests) | | ResourceTypeManage (Actions) | Complete (14 Tests) | -| ResourceTypeView (Responses) | In Progress (3 Tests) | +| ResourceTypeView (Responses) | In Progress (4 Tests) | | SubcategoryManage (Actions) | Complete (12 Tests) | | ToolManage (Actions) | Not started | | Summaries (Responses) | Not started | -| Total | In Progress (104 Tests) | +| Total | In Progress (105 Tests) | From 0e404360d1fcceef714c7ee439bb0897b36ee37e Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 12:53:11 +0100 Subject: [PATCH 18/32] Patch - Documented PATCH in the json schema file --- README.md | 43 ++--- Tests/TestCase.php | 5 + .../Http/Controllers/ResourceTypeViewTest.php | 12 ++ public/api/schema/options/resource-type.json | 176 ++++++++++++++++++ 4 files changed, 215 insertions(+), 21 deletions(-) create mode 100644 public/api/schema/options/resource-type.json diff --git a/README.md b/README.md index cda32b3d..a25067b7 100644 --- a/README.md +++ b/README.md @@ -260,24 +260,25 @@ You can see our progress in the table below. We are hoping to add tests in each not too concerned about missing anything as we still have all our tests in Postman, we won't disable our test monitor until our local test suite is as complete as the Postman request tests. -| Controller | Progress | -|:------------------------------------|:------------------------| -| Authentication (Actions) | Complete (35 Tests) | -| Authentication (Responses) | In Progress (2 Tests) | -| CategoryManage (Actions) | Complete (11 Tests) | -| ItemCategoryManage (Actions) | Not started | -| ItemManage (Actions) | Not started | -| ItemPartialTransferManage (Actions) | Not started | -| ItemSubcategoryManage (Actions) | Not started | -| ItemTransferManage (Actions) | Not started | -| ItemTypeView (Responses) | Complete (7 tests) | -| PermittedUserManage (Actions) | In Progress (4 Tests) | -| PermittedUserView (Responses) | In Progress (2 Tests) | -| RequestManage (Actions) | Not started | -| ResourceManage (Actions) | Complete (14 Tests) | -| ResourceTypeManage (Actions) | Complete (14 Tests) | -| ResourceTypeView (Responses) | In Progress (4 Tests) | -| SubcategoryManage (Actions) | Complete (12 Tests) | -| ToolManage (Actions) | Not started | -| Summaries (Responses) | Not started | -| Total | In Progress (105 Tests) | +| Controller | Progress | +|:------------------------------------|:----------------------| +| Authentication (Actions) | Complete (35 Tests) | +| Authentication (Responses) | In Progress (2 Tests) | +| CategoryManage (Actions) | Complete (11 Tests) | +| ItemCategoryManage (Actions) | Not started | +| ItemManage (Actions) | Not started | +| ItemPartialTransferManage (Actions) | Not started | +| ItemSubcategoryManage (Actions) | Not started | +| ItemTransferManage (Actions) | Not started | +| ItemTypeView (Responses) | Complete (7 tests) | +| PermittedUserManage (Actions) | In Progress (4 Tests) | +| PermittedUserView (Responses) | In Progress (2 Tests) | +| RequestManage (Actions) | Not started | +| ResourceManage (Actions) | Complete (14 Tests) | +| ResourceTypeManage (Actions) | Complete (14 Tests) | +| ResourceTypeView (Responses) | In Progress (5 Tests) | +| SubcategoryManage (Actions) | Complete (12 Tests) | +| ToolManage (Actions) | Not started | +| Summaries (Responses) | Not started | +| **Total tests** | **106** | +| **Total assertions** | **309** | diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 9e2a584c..61568719 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -273,6 +273,11 @@ protected function optionsRegister(array $parameters = []): TestResponse return $this->optionsRoute('auth.register.options', $parameters); } + protected function optionsResourceType(array $parameters = []): TestResponse + { + return $this->optionsRoute('resource-type.show.options', $parameters); + } + protected function optionsResourceTypeCollection(array $parameters = []): TestResponse { return $this->optionsRoute('resource-type.list.options', $parameters); diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index d40e21af..9fca6676 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -7,6 +7,18 @@ final class ResourceTypeViewTest extends TestCase { + /** @test */ + public function optionsRequestForResourceType(): void + { + $this->actingAs(User::find(1)); + $resource_type_id = $this->createAndReturnResourceTypeId(); + + $response = $this->optionsResourceType(['resource_type_id' => $resource_type_id]); + $response->assertStatus(200); + + $this->assertJsonMatchesSchema($response->content(), 'api/schema/options/resource-type.json'); + } + /** @test */ public function optionsRequestForResourceTypeCollection(): void { diff --git a/public/api/schema/options/resource-type.json b/public/api/schema/options/resource-type.json new file mode 100644 index 00000000..e098ace3 --- /dev/null +++ b/public/api/schema/options/resource-type.json @@ -0,0 +1,176 @@ +{ + "$id": "https://api.costs-to-expect.com/v2/api/schema/options/resource-type-collection.json", + "type": "object", + "properties": { + "DELETE": { + "type": "object" + }, + "GET" : { + "type": "object" + }, + "PATCH": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + }, + "fields": { + "type": "object", + "properties": { + "name": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "validation": { + "type": "object", + "properties": { + "max-length": { + "type": "integer" + } + }, + "required": [ + "max-length" + ] + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "validation", + "required" + ] + }, + "description": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "data": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "public": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + } + }, + "required": [ + "name", + "description", + "data", + "public" + ] + } + }, + "required": [ + "description", + "authentication", + "fields" + ] + } + }, + "required": [ + "DELETE", + "GET", + "DELETE" + ] +} \ No newline at end of file From e55283f849d4ef08aedfda41cfa020296d52b36e Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 13:06:08 +0100 Subject: [PATCH 19/32] Schema JSON schema for the resource type options request --- public/api/schema/options/resource-type.json | 127 ++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/public/api/schema/options/resource-type.json b/public/api/schema/options/resource-type.json index e098ace3..f8d0a28a 100644 --- a/public/api/schema/options/resource-type.json +++ b/public/api/schema/options/resource-type.json @@ -3,10 +3,133 @@ "type": "object", "properties": { "DELETE": { - "type": "object" + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + } + }, + "required": [ + "description", + "authentication" + ] }, "GET" : { - "type": "object" + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + }, + "sortable": { + "type": "array" + }, + "searchable": { + "type": "array" + }, + "filterable": { + "type": "array" + }, + "parameters": { + "type": "object", + "properties": { + "include-resources": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "include-permitted-users": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + } + }, + "required": [ + "include-resources", + "include-permitted-users" + ] + } + }, + "required": [ + "description", + "authentication", + "sortable", + "searchable", + "filterable" + ] }, "PATCH": { "type": "object", From eadaeed816d33b0f9e33afd66590891b6b03381e Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 13:11:52 +0100 Subject: [PATCH 20/32] Updated the resource type schema - Correct the resource type schema, missing uri, also, permitted users not present without parameter --- public/api/schema/resource-type.json | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/public/api/schema/resource-type.json b/public/api/schema/resource-type.json index e905e0d9..d775ce6f 100644 --- a/public/api/schema/resource-type.json +++ b/public/api/schema/resource-type.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type.json", "type": "object", "properties": { "id": { @@ -22,6 +23,9 @@ "item_type": { "type": "object", "properties": { + "uri": { + "type": "string" + }, "id": { "type": "string" }, @@ -36,6 +40,7 @@ } }, "required": [ + "uri", "id", "name", "friendly_name", @@ -45,23 +50,17 @@ "resources": { "type": "object", "properties": { + "uri": { + "type": "string" + }, "count": { "type": "integer" } }, "required": [ + "uri", "count" ] - - }, - "permitted_users": { - "type": "object", - "properties": { - "count": { - "type": "integer" - } - } - } }, "required": [ From cc1393b3e8ecedc8c86b65c60e0148c1be9de0b1 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 14:06:09 +0100 Subject: [PATCH 21/32] resourceTypeShowWithParameterIncludeResource test - Include the uri to the collection. - New test --- Tests/TestCase.php | 5 + .../Http/Controllers/ResourceTypeViewTest.php | 21 +++ app/Models/Resource.php | 6 +- app/Transformer/Resource.php | 7 +- .../resource-type-include-resources.json | 133 ++++++++++++++++++ routes/api/public-routes.php | 4 +- 6 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 public/api/schema/resource-type-include-resources.json diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 61568719..2bedac78 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -43,6 +43,11 @@ protected function assertJsonIsResourceType($content): void $this->assertJsonMatchesSchema($content, 'api/schema/resource-type.json'); } + protected function assertJsonIsResourceTypeAndIncludesResources($content): void + { + $this->assertJsonMatchesSchema($content, 'api/schema/resource-type-include-resources.json'); + } + protected function assertJsonMatchesSchema($content, $schema_file): void { $schema = Schema::fromJsonString(file_get_contents(public_path($schema_file))); diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index 9fca6676..8119f853 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -85,4 +85,25 @@ public function resourceTypeShow(): void $this->assertJsonIsResourceType($response->content()); } + + /** @test */ + public function resourceTypeShowWithParameterIncludeResource(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['offset'=>0, 'limit'=> 1]); + $response->assertStatus(200); + + $resource_type_id = $response->json()[0]['id']; + + $resource_id = $this->createAndReturnResourceId($resource_type_id); + + $response = $this->getResourceType([ + 'resource_type_id'=> $resource_type_id, + 'include-resources' => true + ]); + $response->assertStatus(200); + + $this->assertJsonIsResourceTypeAndIncludesResources($response->content()); + } } diff --git a/app/Models/Resource.php b/app/Models/Resource.php index 12493439..3d381d7b 100644 --- a/app/Models/Resource.php +++ b/app/Models/Resource.php @@ -87,12 +87,14 @@ public function paginatedCollection( { $collection = $this ->select( + 'resource_type_item_type.item_type_id AS resource_type_item_type_id', 'resource.id AS resource_id', 'resource.name AS resource_name', 'resource.description AS resource_description', 'resource.data AS resource_data', 'resource.created_at AS resource_created_at', 'item_subtype.id AS resource_item_subtype_id', + 'item_subtype.id AS resource_item_subtype_id', 'item_subtype.name AS resource_item_subtype_name', 'item_subtype.description AS resource_item_subtype_description' ) @@ -113,9 +115,11 @@ public function paginatedCollection( $resource_type_id ] ) + ->join('resource_type', 'resource.resource_type_id', 'resource_type.id') + ->join('resource_type_item_type', 'resource_type_item_type.resource_type_id', 'resource_type.id') ->join('resource_item_subtype', 'resource_item_subtype.resource_id', 'resource.id') ->join('item_subtype', 'resource_item_subtype.item_subtype_id', 'item_subtype.id') - ->where('resource_type_id', '=', $resource_type_id); + ->where('resource.resource_type_id', '=', $resource_type_id); $collection = Clause::applySearch($collection, $this->table, $search_parameters); diff --git a/app/Transformer/Resource.php b/app/Transformer/Resource.php index 1e7e867f..67d66899 100644 --- a/app/Transformer/Resource.php +++ b/app/Transformer/Resource.php @@ -33,12 +33,17 @@ public function format(array $to_transform): void ]; if ( + array_key_exists('resource_type_item_type_id', $to_transform) === true && array_key_exists('resource_item_subtype_id', $to_transform) === true && array_key_exists('resource_item_subtype_name', $to_transform) === true && array_key_exists('resource_item_subtype_description', $to_transform) === true ) { + $item_type_id = $this->hash->itemType()->encode($to_transform['resource_type_item_type_id']); + $item_sub_type_id = $this->hash->itemSubtype()->encode($to_transform['resource_item_subtype_id']); + $this->transformed['item_subtype'] = [ - 'id' => $this->hash->itemSubtype()->encode($to_transform['resource_item_subtype_id']), + 'uri' => route('item-subtype.show', ['item_type_id' => $item_type_id, 'item_subtype_id' => $item_sub_type_id], false), + 'id' => $item_sub_type_id, 'name' => $to_transform['resource_item_subtype_name'], 'description' => $to_transform['resource_item_subtype_description'] ]; diff --git a/public/api/schema/resource-type-include-resources.json b/public/api/schema/resource-type-include-resources.json new file mode 100644 index 00000000..1370fd48 --- /dev/null +++ b/public/api/schema/resource-type-include-resources.json @@ -0,0 +1,133 @@ +{ + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type-include-resources.json", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "data": { + "type": ["object", "null"] + }, + "created": { + "type": "string" + }, + "public": { + "type": "boolean" + }, + "item_type": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "friendly_name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "uri", + "id", + "name", + "friendly_name", + "description" + ] + }, + "resources": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "count": { + "type": "integer" + }, + "collection": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "data": { + "type": [ + "object", + "null" + ] + }, + "created": { + "type": "string" + }, + "item_subtype": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "uri", + "id", + "name", + "description" + ] + } + }, + "required": [ + "id", + "name", + "description", + "data", + "created" + ] + } + } + }, + "required": [ + "uri", + "count", + "collection" + ] + } + }, + "required": [ + "id", + "name", + "description", + "data", + "created", + "public", + "item_type", + "resources" + ] +} diff --git a/routes/api/public-routes.php b/routes/api/public-routes.php index 620cab21..b8cd4bda 100644 --- a/routes/api/public-routes.php +++ b/routes/api/public-routes.php @@ -89,8 +89,8 @@ static function () { Route::get( 'item-types/{item_type_id}/item-subtypes/{item_subtype_id}', - 'ItemSubtypeView@show' - ); + [\App\Http\Controllers\ItemSubtypeView::class, 'show'] + )->name('item-subtype.show'); Route::options( 'item-types/{item_type_id}/item-subtypes/{item_subtype_id}', From 6c36118bf8098015a89b2c479c07580ec706cbe9 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 14:13:29 +0100 Subject: [PATCH 22/32] Remove item subtype - Item subtype is not always present on a resource and we haven't yet got to the resource tests --- public/api/schema/resource.json | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/public/api/schema/resource.json b/public/api/schema/resource.json index fafe26ed..5df75e57 100644 --- a/public/api/schema/resource.json +++ b/public/api/schema/resource.json @@ -13,25 +13,6 @@ "data": { "type": ["object", "null"] }, - "item_subtype": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "description": { - "type": "string" - } - }, - "required": [ - "id", - "name", - "description" - ] - }, "created": { "type": "string" } @@ -41,7 +22,6 @@ "name", "description", "data", - "item_subtype", "created" ] } From ae8bd15abfcde2d4084c4324995b930a12e331d5 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 14:19:04 +0100 Subject: [PATCH 23/32] Readme - Update the readme, tests are never complete so the status is stupid --- README.md | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a25067b7..09baa475 100644 --- a/README.md +++ b/README.md @@ -260,25 +260,28 @@ You can see our progress in the table below. We are hoping to add tests in each not too concerned about missing anything as we still have all our tests in Postman, we won't disable our test monitor until our local test suite is as complete as the Postman request tests. -| Controller | Progress | -|:------------------------------------|:----------------------| -| Authentication (Actions) | Complete (35 Tests) | -| Authentication (Responses) | In Progress (2 Tests) | -| CategoryManage (Actions) | Complete (11 Tests) | -| ItemCategoryManage (Actions) | Not started | -| ItemManage (Actions) | Not started | -| ItemPartialTransferManage (Actions) | Not started | -| ItemSubcategoryManage (Actions) | Not started | -| ItemTransferManage (Actions) | Not started | -| ItemTypeView (Responses) | Complete (7 tests) | -| PermittedUserManage (Actions) | In Progress (4 Tests) | -| PermittedUserView (Responses) | In Progress (2 Tests) | -| RequestManage (Actions) | Not started | -| ResourceManage (Actions) | Complete (14 Tests) | -| ResourceTypeManage (Actions) | Complete (14 Tests) | -| ResourceTypeView (Responses) | In Progress (5 Tests) | -| SubcategoryManage (Actions) | Complete (12 Tests) | -| ToolManage (Actions) | Not started | -| Summaries (Responses) | Not started | -| **Total tests** | **106** | -| **Total assertions** | **309** | +| Controller | Progress | +|:------------------------------------|:---------| +| Authentication (Actions) | 35 Tests | +| Authentication (Responses) | 2 Tests | +| CategoryManage (Actions) | 11 Tests | +| ItemCategoryManage (Actions) | Non yet* | +| ItemManage (Actions) | Non yet* | +| ItemPartialTransferManage (Actions) | Non yet* | +| ItemSubcategoryManage (Actions) | Non yet* | +| ItemTransferManage (Actions) | Non yet* | +| ItemTypeView (Responses) | 7 tests | +| PermittedUserManage (Actions) | 4 Tests | +| PermittedUserView (Responses) | 2 Tests | +| RequestManage (Actions) | Non yet* | +| ResourceManage (Actions) | 14 Tests | +| ResourceTypeManage (Actions) | 14 Tests | +| ResourceTypeView (Responses) | 6 Tests | +| SubcategoryManage (Actions) | 12 Tests | +| ToolManage (Actions) | Non yet* | +| Summaries (Responses) | Non yet* | +| **Total tests** | **107** | +| **Total assertions** | **313** | + +*Non yet does not mean there are no tests, it just means there are no PHPUnit tests. There are over 2000 tests in +a private Postman collection, I'm slowing transferring them locally. \ No newline at end of file From 203f4a46933b5a4c92f4727d0fbadfa1c36bd719 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 14:57:09 +0100 Subject: [PATCH 24/32] include-permitted-users Added test for when include-permitted-users parameter is added to the resource type collection --- README.md | 8 +- Tests/TestCase.php | 5 + .../Http/Controllers/ResourceTypeViewTest.php | 19 +++ ...resource-type-include-permitted-users.json | 114 ++++++++++++++++++ 4 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 public/api/schema/resource-type-include-permitted-users.json diff --git a/README.md b/README.md index 09baa475..d2e3593d 100644 --- a/README.md +++ b/README.md @@ -276,12 +276,12 @@ our local test suite is as complete as the Postman request tests. | RequestManage (Actions) | Non yet* | | ResourceManage (Actions) | 14 Tests | | ResourceTypeManage (Actions) | 14 Tests | -| ResourceTypeView (Responses) | 6 Tests | +| ResourceTypeView (Responses) | 7 Tests | | SubcategoryManage (Actions) | 12 Tests | | ToolManage (Actions) | Non yet* | | Summaries (Responses) | Non yet* | -| **Total tests** | **107** | -| **Total assertions** | **313** | +| **Total tests** | **108** | +| **Total assertions** | **316** | *Non yet does not mean there are no tests, it just means there are no PHPUnit tests. There are over 2000 tests in -a private Postman collection, I'm slowing transferring them locally. \ No newline at end of file +a private Postman collection, I'm slowing transferring them locally. diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 2bedac78..eb40bc85 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -43,6 +43,11 @@ protected function assertJsonIsResourceType($content): void $this->assertJsonMatchesSchema($content, 'api/schema/resource-type.json'); } + protected function assertJsonIsResourceTypeAndIncludesPermittedUsers($content): void + { + $this->assertJsonMatchesSchema($content, 'api/schema/resource-type-include-permitted-users.json'); + } + protected function assertJsonIsResourceTypeAndIncludesResources($content): void { $this->assertJsonMatchesSchema($content, 'api/schema/resource-type-include-resources.json'); diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index 8119f853..56120fab 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -86,6 +86,25 @@ public function resourceTypeShow(): void $this->assertJsonIsResourceType($response->content()); } + /** @test */ + public function resourceTypeShowWithParameterIncludePermittedUsers(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['offset'=>0, 'limit'=> 1]); + $response->assertStatus(200); + + $resource_type_id = $response->json()[0]['id']; + + $response = $this->getResourceType([ + 'resource_type_id'=> $resource_type_id, + 'include-permitted-users' => true + ]); + $response->assertStatus(200); + + $this->assertJsonIsResourceTypeAndIncludesPermittedUsers($response->content()); + } + /** @test */ public function resourceTypeShowWithParameterIncludeResource(): void { diff --git a/public/api/schema/resource-type-include-permitted-users.json b/public/api/schema/resource-type-include-permitted-users.json new file mode 100644 index 00000000..78edc530 --- /dev/null +++ b/public/api/schema/resource-type-include-permitted-users.json @@ -0,0 +1,114 @@ +{ + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type-include-permitted-users.json", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "data": { + "type": ["object", "null"] + }, + "created": { + "type": "string" + }, + "public": { + "type": "boolean" + }, + "item_type": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "friendly_name": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "uri", + "id", + "name", + "friendly_name", + "description" + ] + }, + "resources": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "count": { + "type": "integer" + } + }, + "required": [ + "uri", + "count" + ] + }, + "permitted_users": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "count": { + "type": "integer" + }, + "collection": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "email": { + "type": "string" + }, + "created": { + "type": "string" + } + }, + "required": [] + } + } + }, + "required": [ + "uri", + "count", + "collection" + ] + } + }, + "required": [ + "id", + "name", + "description", + "data", + "created", + "public", + "item_type", + "resources", + "permitted_users" + ] +} From ec57acbadb284019b92b319c6dc4cd67b74f1454 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 23:30:52 +0100 Subject: [PATCH 25/32] Resource type tests - Added a few more resource type tests. - Removed assertions count from README, will not be accurate for a new setup --- README.md | 5 +- .../Http/Controllers/ResourceTypeViewTest.php | 100 ++++++++++++++++++ .../options/resource-type-collection.json | 1 - 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d2e3593d..2ccb703a 100644 --- a/README.md +++ b/README.md @@ -276,12 +276,11 @@ our local test suite is as complete as the Postman request tests. | RequestManage (Actions) | Non yet* | | ResourceManage (Actions) | 14 Tests | | ResourceTypeManage (Actions) | 14 Tests | -| ResourceTypeView (Responses) | 7 Tests | +| ResourceTypeView (Responses) | 11 Tests | | SubcategoryManage (Actions) | 12 Tests | | ToolManage (Actions) | Non yet* | | Summaries (Responses) | Non yet* | -| **Total tests** | **108** | -| **Total assertions** | **316** | +| **Total tests** | **112** | *Non yet does not mean there are no tests, it just means there are no PHPUnit tests. There are over 2000 tests in a private Postman collection, I'm slowing transferring them locally. diff --git a/Tests/View/Http/Controllers/ResourceTypeViewTest.php b/Tests/View/Http/Controllers/ResourceTypeViewTest.php index 56120fab..6b78945e 100644 --- a/Tests/View/Http/Controllers/ResourceTypeViewTest.php +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -70,6 +70,106 @@ public function resourceTypeCollectionPagination(): void } } + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function resourceTypeCollectionSearchDescription(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['search'=>'description:resource-search']); + + $response->assertStatus(200); + $response->assertHeader('X-Search', 'description:resource-search'); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsResourceType($json); + } + } + + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function resourceTypeCollectionSearchName(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['search'=>'name:resource-search']); + + $response->assertStatus(200); + $response->assertHeader('X-Search', 'name:resource-search'); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsResourceType($json); + } + } + + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function resourceTypeCollectionSortCreated(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['sort'=>'created:asc']); + + $response->assertStatus(200); + $response->assertHeader('X-Sort', 'created:asc'); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsResourceType($json); + } + } + + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function resourceTypeCollectionSortName(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['sort'=>'name:asc']); + + $response->assertStatus(200); + $response->assertHeader('X-Sort', 'name:asc'); + + foreach ($response->json() as $item) { + try { + $json = json_encode($item, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->fail('Unable to encode the JSON string'); + } + + $this->assertJsonIsResourceType($json); + } + } + /** @test */ public function resourceTypeShow(): void { diff --git a/public/api/schema/options/resource-type-collection.json b/public/api/schema/options/resource-type-collection.json index cc9f7268..188ba745 100644 --- a/public/api/schema/options/resource-type-collection.json +++ b/public/api/schema/options/resource-type-collection.json @@ -56,7 +56,6 @@ }, "filterable": { "type": [ - "object", "array" ] }, From 4210cd1f72f6de51ab70512dbe87f36393ca5585 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 17 Jun 2022 23:40:03 +0100 Subject: [PATCH 26/32] $id - Added $id to the schema files --- public/api/schema/assigned-category.json | 1 + public/api/schema/assigned-subcategory.json | 1 + public/api/schema/auth/options/create-password.json | 1 + public/api/schema/auth/options/register.json | 1 + public/api/schema/category.json | 1 + public/api/schema/currency.json | 1 + public/api/schema/error-log.json | 1 + public/api/schema/item-allocated-expense.json | 1 + public/api/schema/item-category.json | 1 + public/api/schema/item-game.json | 1 + public/api/schema/item-simple-expense.json | 1 + public/api/schema/item-simple-item.json | 1 + public/api/schema/item-subcategory.json | 1 + public/api/schema/item-subtype.json | 1 + public/api/schema/item-type.json | 1 + public/api/schema/partial-transfer.json | 1 + public/api/schema/permitted-user.json | 1 + public/api/schema/resource-type-item-allocated-expense.json | 1 + public/api/schema/resource-type-item-game.json | 1 + public/api/schema/resource-type-item-simple-expense.json | 1 + public/api/schema/resource-type-item-simple-item.json | 1 + public/api/schema/resource.json | 1 + public/api/schema/subcategory.json | 1 + public/api/schema/transfer.json | 1 + 24 files changed, 24 insertions(+) diff --git a/public/api/schema/assigned-category.json b/public/api/schema/assigned-category.json index b8ec66eb..8be281a5 100644 --- a/public/api/schema/assigned-category.json +++ b/public/api/schema/assigned-category.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/assigned-category.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/assigned-subcategory.json b/public/api/schema/assigned-subcategory.json index 727f08a6..d13a249a 100644 --- a/public/api/schema/assigned-subcategory.json +++ b/public/api/schema/assigned-subcategory.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/assigned-subcategory.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/auth/options/create-password.json b/public/api/schema/auth/options/create-password.json index 69d3166c..f08f72b7 100644 --- a/public/api/schema/auth/options/create-password.json +++ b/public/api/schema/auth/options/create-password.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/auth/options/create-password.json", "type": "object", "properties": { "POST": { diff --git a/public/api/schema/auth/options/register.json b/public/api/schema/auth/options/register.json index 045c08eb..c20052b9 100644 --- a/public/api/schema/auth/options/register.json +++ b/public/api/schema/auth/options/register.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/auth/options/register.json", "type": "object", "properties": { "POST": { diff --git a/public/api/schema/category.json b/public/api/schema/category.json index d089021b..2fa39b25 100644 --- a/public/api/schema/category.json +++ b/public/api/schema/category.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/category.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/currency.json b/public/api/schema/currency.json index 616f374c..0e85e6ca 100644 --- a/public/api/schema/currency.json +++ b/public/api/schema/currency.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/category.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/error-log.json b/public/api/schema/error-log.json index 10887a2c..3378639f 100644 --- a/public/api/schema/error-log.json +++ b/public/api/schema/error-log.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/error-log.json", "type": "object", "properties": { "method": { diff --git a/public/api/schema/item-allocated-expense.json b/public/api/schema/item-allocated-expense.json index 570c094d..9f4554cf 100644 --- a/public/api/schema/item-allocated-expense.json +++ b/public/api/schema/item-allocated-expense.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-allocated-expense.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-category.json b/public/api/schema/item-category.json index a3c13d60..59130e04 100644 --- a/public/api/schema/item-category.json +++ b/public/api/schema/item-category.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-category.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-game.json b/public/api/schema/item-game.json index e1636df6..6ae5744a 100644 --- a/public/api/schema/item-game.json +++ b/public/api/schema/item-game.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-game.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-simple-expense.json b/public/api/schema/item-simple-expense.json index 1a473c5d..98477587 100644 --- a/public/api/schema/item-simple-expense.json +++ b/public/api/schema/item-simple-expense.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-simple-expense.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-simple-item.json b/public/api/schema/item-simple-item.json index f5e0b29c..2e316977 100644 --- a/public/api/schema/item-simple-item.json +++ b/public/api/schema/item-simple-item.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-simple-item.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-subcategory.json b/public/api/schema/item-subcategory.json index b0bbfb7e..2d82d179 100644 --- a/public/api/schema/item-subcategory.json +++ b/public/api/schema/item-subcategory.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-subcategory.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-subtype.json b/public/api/schema/item-subtype.json index 991d0f42..b0512c2c 100644 --- a/public/api/schema/item-subtype.json +++ b/public/api/schema/item-subtype.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-subtype.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/item-type.json b/public/api/schema/item-type.json index 1a0b7254..98ab33e6 100644 --- a/public/api/schema/item-type.json +++ b/public/api/schema/item-type.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/item-type.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/partial-transfer.json b/public/api/schema/partial-transfer.json index 3f738095..5df17707 100644 --- a/public/api/schema/partial-transfer.json +++ b/public/api/schema/partial-transfer.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/partial-transfer.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/permitted-user.json b/public/api/schema/permitted-user.json index f43efe08..f4ce168e 100644 --- a/public/api/schema/permitted-user.json +++ b/public/api/schema/permitted-user.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/permitted-user.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/resource-type-item-allocated-expense.json b/public/api/schema/resource-type-item-allocated-expense.json index eebf66c4..fe585aed 100644 --- a/public/api/schema/resource-type-item-allocated-expense.json +++ b/public/api/schema/resource-type-item-allocated-expense.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type-item-allocated-expense.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/resource-type-item-game.json b/public/api/schema/resource-type-item-game.json index fa2e7574..33118d3b 100644 --- a/public/api/schema/resource-type-item-game.json +++ b/public/api/schema/resource-type-item-game.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type-item-game.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/resource-type-item-simple-expense.json b/public/api/schema/resource-type-item-simple-expense.json index a64bee98..5cf564eb 100644 --- a/public/api/schema/resource-type-item-simple-expense.json +++ b/public/api/schema/resource-type-item-simple-expense.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type-item-simple-expense.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/resource-type-item-simple-item.json b/public/api/schema/resource-type-item-simple-item.json index 6aae2ec6..083c31e6 100644 --- a/public/api/schema/resource-type-item-simple-item.json +++ b/public/api/schema/resource-type-item-simple-item.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource-type-item-simple-item.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/resource.json b/public/api/schema/resource.json index 5df75e57..c08229c0 100644 --- a/public/api/schema/resource.json +++ b/public/api/schema/resource.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/resource.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/subcategory.json b/public/api/schema/subcategory.json index 25a5c5f8..5b010163 100644 --- a/public/api/schema/subcategory.json +++ b/public/api/schema/subcategory.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/subcategory.json", "type": "object", "properties": { "id": { diff --git a/public/api/schema/transfer.json b/public/api/schema/transfer.json index 2052d4c5..f8217d7c 100644 --- a/public/api/schema/transfer.json +++ b/public/api/schema/transfer.json @@ -1,4 +1,5 @@ { + "$id": "https://api.costs-to-expect.com/v2/api/schema/transfer.json", "type": "object", "properties": { "id": { From dacc62ed9031d493939a60395152d72def3b7086 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Sat, 18 Jun 2022 00:08:51 +0100 Subject: [PATCH 27/32] Catch all - Added a catch all route for unmapped routes --- resources/lang/en/responses.php | 1 + routes/api.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/resources/lang/en/responses.php b/resources/lang/en/responses.php index cf9198fd..b5271a65 100644 --- a/resources/lang/en/responses.php +++ b/resources/lang/en/responses.php @@ -20,4 +20,5 @@ 'error' => 'Sorry, there has been an error, please try again later.', 'category-limit' => 'Unable to handle your request, the number of allowable category assignments reached', 'subcategory-limit' => 'Unable to handle your request, the number of allowable subcategory assignments reached', + 'invalid-route' => 'The requested route is invalid, please visit the index of the API to see all the valid routes https://api.costs-to-expect.com/v2' ]; diff --git a/routes/api.php b/routes/api.php index fffb3ed1..8a45f76e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -4,3 +4,9 @@ require('api/private-routes.php'); require('api/public-routes.php'); require('api/public-summary-routes.php'); + +Route::fallback(function () { + return response()->json( + ['message' => trans('responses.invalid-route')] + ); +}); From 6df7b9bf8e6abd19f0a59dfbfc397700acd04a85 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Sat, 18 Jun 2022 00:19:19 +0100 Subject: [PATCH 28/32] Category assignment - Added a specific category assignment response instead of generic foreign key error --- app/Http/Controllers/ItemManage.php | 8 ++++---- app/HttpResponse/Response.php | 16 ++++++++++++++++ resources/lang/en/responses.php | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ItemManage.php b/app/Http/Controllers/ItemManage.php index 2da53283..3f13c0b6 100644 --- a/app/Http/Controllers/ItemManage.php +++ b/app/Http/Controllers/ItemManage.php @@ -563,7 +563,7 @@ private function deleteAllocatedExpense( } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Response::foreignKeyConstraintError(); + return Response::foreignKeyConstraintCategory(); } try { @@ -609,7 +609,7 @@ private function deleteGame( } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Response::foreignKeyConstraintError(); + return Response::foreignKeyConstraintCategory(); } try { @@ -654,7 +654,7 @@ private function deleteSimpleExpense( } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Response::foreignKeyConstraintError(); + return Response::foreignKeyConstraintCategory(); } try { @@ -699,7 +699,7 @@ private function deleteSimpleItem( } if ($item_model->hasCategoryAssignments($item_id) === true) { - return Response::foreignKeyConstraintError(); + return Response::foreignKeyConstraintCategory(); } try { diff --git a/app/HttpResponse/Response.php b/app/HttpResponse/Response.php index 180893da..8ca7f83e 100644 --- a/app/HttpResponse/Response.php +++ b/app/HttpResponse/Response.php @@ -79,6 +79,22 @@ public static function foreignKeyConstraintError(?Throwable $e = null): JsonResp ); } + public static function foreignKeyConstraintCategory(?Throwable $e = null): JsonResponse + { + $response = [ + 'message' => trans('constraint-category') + ]; + + if ($e instanceOf Throwable && app()->environment() !== 'production') { + $response = self::addException($response, $e); + } + + return response()->json( + $response, + 409 + ); + } + public static function failedToSelectModelForUpdateOrDelete(?Throwable $e = null): JsonResponse { $response = [ diff --git a/resources/lang/en/responses.php b/resources/lang/en/responses.php index b5271a65..fc316a96 100644 --- a/resources/lang/en/responses.php +++ b/resources/lang/en/responses.php @@ -8,6 +8,7 @@ 'not-found-or-not-accessible-entity' => 'The requested `:type` does not exist or is not accessible with your permissions.', 'not-supported' => 'The requested route is not supported for the item type', 'constraint' => 'Unable to handle your request, dependent data exists or foreign key error.', + 'constraint-category' => 'Unable to handle your request, category data exists for the item, delete the category first.', 'model-select-failure' => 'Unable to handle your request, an error occurred when selecting the data to complete your request.', 'model-save-failure-update' => 'Unable to handle your request, an error occurred when processing your update request.', 'model-save-failure-create' => 'Unable to handle your request, an error occurred when processing your create request.', From 615b3ecde9ecfdd15aad8b3b551b41f43f554789 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Sun, 19 Jun 2022 16:30:08 +0100 Subject: [PATCH 29/32] Corrected descriptions - Updated item summary descriptions, all referred to TCO which is only accurate for one item-type --- app/HttpOptionResponse/Item/Summary/AllocatedExpense.php | 2 +- app/HttpOptionResponse/Item/Summary/Game.php | 2 +- app/HttpOptionResponse/Item/Summary/SimpleExpense.php | 2 +- app/HttpOptionResponse/Item/Summary/SimpleItem.php | 2 +- .../ResourceTypeItem/Summary/AllocatedExpense.php | 2 +- app/HttpOptionResponse/ResourceTypeItem/Summary/Game.php | 2 +- .../ResourceTypeItem/Summary/SimpleExpense.php | 2 +- .../ResourceTypeItem/Summary/SimpleItem.php | 2 +- resources/lang/en/route-descriptions.php | 5 ++--- 9 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/HttpOptionResponse/Item/Summary/AllocatedExpense.php b/app/HttpOptionResponse/Item/Summary/AllocatedExpense.php index a60ad7d0..d6b4b5ec 100644 --- a/app/HttpOptionResponse/Item/Summary/AllocatedExpense.php +++ b/app/HttpOptionResponse/Item/Summary/AllocatedExpense.php @@ -18,7 +18,7 @@ public function create() ->setSearchableParameters(LaravelConfig::get($base_path . '.summary-searchable', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary_GET_resource-type_resource_items') + ->setDescription('route-descriptions.summary_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/Item/Summary/Game.php b/app/HttpOptionResponse/Item/Summary/Game.php index 0cca3bae..5b778320 100644 --- a/app/HttpOptionResponse/Item/Summary/Game.php +++ b/app/HttpOptionResponse/Item/Summary/Game.php @@ -18,7 +18,7 @@ public function create() ->setSearchableParameters(LaravelConfig::get($base_path . '.summary-searchable', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary_GET_resource-type_resource_items') + ->setDescription('route-descriptions.summary_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/Item/Summary/SimpleExpense.php b/app/HttpOptionResponse/Item/Summary/SimpleExpense.php index 9a2f0f23..97a6736f 100644 --- a/app/HttpOptionResponse/Item/Summary/SimpleExpense.php +++ b/app/HttpOptionResponse/Item/Summary/SimpleExpense.php @@ -18,7 +18,7 @@ public function create() ->setSearchableParameters(LaravelConfig::get($base_path . '.summary-searchable', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary_GET_resource-type_resource_items') + ->setDescription('route-descriptions.summary_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/Item/Summary/SimpleItem.php b/app/HttpOptionResponse/Item/Summary/SimpleItem.php index 2dd3fd27..5f0a6991 100644 --- a/app/HttpOptionResponse/Item/Summary/SimpleItem.php +++ b/app/HttpOptionResponse/Item/Summary/SimpleItem.php @@ -18,7 +18,7 @@ public function create() ->setSearchableParameters(LaravelConfig::get($base_path . '.summary-searchable', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary_GET_resource-type_resource_items') + ->setDescription('route-descriptions.summary_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/ResourceTypeItem/Summary/AllocatedExpense.php b/app/HttpOptionResponse/ResourceTypeItem/Summary/AllocatedExpense.php index c419f51c..1c2795a0 100644 --- a/app/HttpOptionResponse/ResourceTypeItem/Summary/AllocatedExpense.php +++ b/app/HttpOptionResponse/ResourceTypeItem/Summary/AllocatedExpense.php @@ -17,7 +17,7 @@ public function create() ->setParameters(LaravelConfig::get($base_path . '.summary-parameters', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary-resource-type-item-GET-index') + ->setDescription('route-descriptions.summary_resource_type_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/ResourceTypeItem/Summary/Game.php b/app/HttpOptionResponse/ResourceTypeItem/Summary/Game.php index 3f28f39a..c4ad0fc4 100644 --- a/app/HttpOptionResponse/ResourceTypeItem/Summary/Game.php +++ b/app/HttpOptionResponse/ResourceTypeItem/Summary/Game.php @@ -17,7 +17,7 @@ public function create() ->setParameters(LaravelConfig::get($base_path . '.summary-parameters', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary-resource-type-item-GET-index') + ->setDescription('route-descriptions.summary_resource_type_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleExpense.php b/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleExpense.php index bd6adc56..a8a604b8 100644 --- a/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleExpense.php +++ b/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleExpense.php @@ -17,7 +17,7 @@ public function create() ->setParameters(LaravelConfig::get($base_path . '.summary-parameters', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary-resource-type-item-GET-index') + ->setDescription('route-descriptions.summary_resource_type_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleItem.php b/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleItem.php index bb3672e4..d0fc1497 100644 --- a/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleItem.php +++ b/app/HttpOptionResponse/ResourceTypeItem/Summary/SimpleItem.php @@ -17,7 +17,7 @@ public function create() ->setParameters(LaravelConfig::get($base_path . '.summary-parameters', [])) ->setFilterableParameters(LaravelConfig::get($base_path . '.summary-filterable', [])) ->setDynamicParameters($this->allowed_parameters) - ->setDescription('route-descriptions.summary-resource-type-item-GET-index') + ->setDescription('route-descriptions.summary_resource_type_items_GET_index') ->setAuthenticationStatus($this->permissions['view']) ->option(); diff --git a/resources/lang/en/route-descriptions.php b/resources/lang/en/route-descriptions.php index 12fe6d7e..25e0eaf7 100644 --- a/resources/lang/en/route-descriptions.php +++ b/resources/lang/en/route-descriptions.php @@ -107,7 +107,6 @@ 'summary-resource-type-GET-index' => 'Return a summary of the resource types', 'summary-resource-GET-index' => 'Return a summary of the resources', - 'summary_GET_resource-type_resource_items' => 'Return the TCO (Total cost of ownership, sum of items) for the selected resource', - - 'summary-resource-type-item-GET-index' => 'Return a summary of the items for all the resources matching this resource type', + 'summary_items_GET_index'=> 'Return the "item" summary for the selected resource, review summary filters for all summary options', + 'summary_resource_type_items_GET_index'=> 'Return the "item" summary for the selected resource type, items for all resources are summarised, review summary filters for all summary options', ]; From aaa484bb641d4be84e72584c040b2dd04749a702 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Mon, 20 Jun 2022 14:13:34 +0100 Subject: [PATCH 30/32] Clean up responses - Clean up the response description lang file, remove dashes and use underscore consistently --- app/HttpOptionResponse/ErrorLog.php | 2 +- .../ItemCategory/AllocatedExpenseCollection.php | 2 +- .../ItemCategory/SimpleExpenseCollection.php | 2 +- .../ItemSubcategory/AllocatedExpenseCollection.php | 2 +- .../ItemSubcategory/SimpleExpenseCollection.php | 2 +- .../SummaryResourceCollection.php | 2 +- .../SummaryResourceTypeCollection.php | 2 +- resources/lang/en/route-descriptions.php | 14 +++++++------- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/HttpOptionResponse/ErrorLog.php b/app/HttpOptionResponse/ErrorLog.php index 01452760..1109b772 100644 --- a/app/HttpOptionResponse/ErrorLog.php +++ b/app/HttpOptionResponse/ErrorLog.php @@ -10,7 +10,7 @@ class ErrorLog extends Response public function create() { $get = new \App\HttpVerb\Get(); - $this->verbs['GET'] = $get->setDescription('route-descriptions.request_GET_error-log')-> + $this->verbs['GET'] = $get->setDescription('route-descriptions.request_GET_error_log')-> setAuthenticationStatus($this->permissions['view'])-> option(); diff --git a/app/HttpOptionResponse/ItemCategory/AllocatedExpenseCollection.php b/app/HttpOptionResponse/ItemCategory/AllocatedExpenseCollection.php index 3f9e5126..aafb3b1e 100644 --- a/app/HttpOptionResponse/ItemCategory/AllocatedExpenseCollection.php +++ b/app/HttpOptionResponse/ItemCategory/AllocatedExpenseCollection.php @@ -21,7 +21,7 @@ public function create() setDynamicFields($this->allowed_fields)-> setAuthenticationRequirement(true)-> setAuthenticationStatus($this->permissions['manage'])-> - setDescription('route-descriptions.item_category_POST_allocated-expense')-> + setDescription('route-descriptions.item_category_POST_allocated_expense')-> option(); return $this; diff --git a/app/HttpOptionResponse/ItemCategory/SimpleExpenseCollection.php b/app/HttpOptionResponse/ItemCategory/SimpleExpenseCollection.php index 3342aa92..1ca2efed 100644 --- a/app/HttpOptionResponse/ItemCategory/SimpleExpenseCollection.php +++ b/app/HttpOptionResponse/ItemCategory/SimpleExpenseCollection.php @@ -21,7 +21,7 @@ public function create() setDynamicFields($this->allowed_fields)-> setAuthenticationRequirement(true)-> setAuthenticationStatus($this->permissions['manage'])-> - setDescription('route-descriptions.item_category_POST_simple-expense')-> + setDescription('route-descriptions.item_category_POST_simple_expense')-> option(); return $this; diff --git a/app/HttpOptionResponse/ItemSubcategory/AllocatedExpenseCollection.php b/app/HttpOptionResponse/ItemSubcategory/AllocatedExpenseCollection.php index b3549e13..a179633b 100644 --- a/app/HttpOptionResponse/ItemSubcategory/AllocatedExpenseCollection.php +++ b/app/HttpOptionResponse/ItemSubcategory/AllocatedExpenseCollection.php @@ -19,7 +19,7 @@ public function create() $post = new \App\HttpVerb\Post(); $this->verbs['POST'] = $post->setFields(Config::get('api.item-subcategory.fields-post'))-> setDynamicFields($this->allowed_fields)-> - setDescription('route-descriptions.item_sub_category_POST_allocated-expense')-> + setDescription('route-descriptions.item_sub_category_POST_allocated_expense')-> setAuthenticationStatus($this->permissions['manage'])-> setAuthenticationRequirement(true)-> option(); diff --git a/app/HttpOptionResponse/ItemSubcategory/SimpleExpenseCollection.php b/app/HttpOptionResponse/ItemSubcategory/SimpleExpenseCollection.php index b52dbbce..a07eaae5 100644 --- a/app/HttpOptionResponse/ItemSubcategory/SimpleExpenseCollection.php +++ b/app/HttpOptionResponse/ItemSubcategory/SimpleExpenseCollection.php @@ -19,7 +19,7 @@ public function create() $post = new \App\HttpVerb\Post(); $this->verbs['POST'] = $post->setFields(Config::get('api.item-subcategory.fields-post'))-> setDynamicFields($this->allowed_fields)-> - setDescription('route-descriptions.item_sub_category_POST_simple-expense')-> + setDescription('route-descriptions.item_sub_category_POST_simple_expense')-> setAuthenticationStatus($this->permissions['manage'])-> setAuthenticationRequirement(true)-> option(); diff --git a/app/HttpOptionResponse/SummaryResourceCollection.php b/app/HttpOptionResponse/SummaryResourceCollection.php index 0dbf5550..3520aae7 100644 --- a/app/HttpOptionResponse/SummaryResourceCollection.php +++ b/app/HttpOptionResponse/SummaryResourceCollection.php @@ -11,7 +11,7 @@ public function create() { $get = new \App\HttpVerb\Get(); $this->verbs['GET'] = $get->setParameters(Config::get('api.resource.summary-parameters'))-> - setDescription('route-descriptions.summary-resource-GET-index')-> + setDescription('route-descriptions.summary_resource_GET_index')-> setAuthenticationStatus($this->permissions['view'])-> setSearchableParameters(Config::get('api.resource.summary-searchable'))-> option(); diff --git a/app/HttpOptionResponse/SummaryResourceTypeCollection.php b/app/HttpOptionResponse/SummaryResourceTypeCollection.php index d2c1d844..da4709cb 100644 --- a/app/HttpOptionResponse/SummaryResourceTypeCollection.php +++ b/app/HttpOptionResponse/SummaryResourceTypeCollection.php @@ -11,7 +11,7 @@ public function create() { $get = new \App\HttpVerb\Get(); $this->verbs['GET'] = $get->setParameters(Config::get('api.resource-type.summary-parameters'))-> - setDescription('route-descriptions.summary-resource-type-GET-index')-> + setDescription('route-descriptions.summary_resource_type_GET_index')-> setAuthenticationStatus($this->permissions['view'])-> setSearchableParameters(Config::get('api.resource-type.summary-searchable'))-> option(); diff --git a/resources/lang/en/route-descriptions.php b/resources/lang/en/route-descriptions.php index 25e0eaf7..27eb9055 100644 --- a/resources/lang/en/route-descriptions.php +++ b/resources/lang/en/route-descriptions.php @@ -66,8 +66,8 @@ 'item_category_GET_index' => 'Return the category assigned to the selected item', 'item_category_GET_show' => 'Return the category assigned to the selected item', - 'item_category_POST_allocated-expense' => 'Assign a maximum of one category to the selected allocated-expense', - 'item_category_POST_simple-expense' => 'Assign a maximum of one category to the selected simple-expense', + 'item_category_POST_allocated_expense' => 'Assign a maximum of one category to the selected allocated-expense', + 'item_category_POST_simple_expense' => 'Assign a maximum of one category to the selected simple-expense', 'item_category_POST_game' => 'Assign the categories (players) to the selected game', 'item_category_PATCH' => 'Update the category assigned to the selected item', @@ -76,8 +76,8 @@ 'item_sub_category_GET_index' => 'Return the subcategory assigned to the selected item', 'item_sub_category_GET_show' => 'Return the subcategory assigned to the selected item', - 'item_sub_category_POST_allocated-expense' => 'Assign a maximum of one subcategory to the selected allocated-expense', - 'item_sub_category_POST_simple-expense' => 'Assign a maximum of one subcategory to the selected simple-expense', + 'item_sub_category_POST_allocated_expense' => 'Assign a maximum of one subcategory to the selected allocated-expense', + 'item_sub_category_POST_simple_expense' => 'Assign a maximum of one subcategory to the selected simple-expense', 'item_sub_category_PATCH' => 'Update the subcategory assigned to the selected item', 'item_sub_category_DELETE' => 'Delete the subcategory assigned to the selected item', @@ -96,7 +96,7 @@ 'permitted_user_POST' => 'Assign a permitted user', 'permitted_user_DELETE' => 'Delete the selected permitted user', - 'request_GET_error-log' => 'Return the error log', + 'request_GET_error_log' => 'Return the error log', 'request_GET_cache' => 'Return the number of cached keys for the authenticated user', 'request_DELETE_cache' => 'Attempt to delete the cached keys for the authenticated user', 'request_POST' => 'Create an error log report', @@ -104,8 +104,8 @@ 'summary_category_GET_index' => 'Return a summary of the categories', 'summary_subcategory_GET_index' => 'Return a summary of the subcategories', - 'summary-resource-type-GET-index' => 'Return a summary of the resource types', - 'summary-resource-GET-index' => 'Return a summary of the resources', + 'summary_resource_type_GET_index' => 'Return a summary of the resource types', + 'summary_resource_GET_index' => 'Return a summary of the resources', 'summary_items_GET_index'=> 'Return the "item" summary for the selected resource, review summary filters for all summary options', 'summary_resource_type_items_GET_index'=> 'Return the "item" summary for the selected resource type, items for all resources are summarised, review summary filters for all summary options', From f0107e47ef8300c0cf4a8b93e9c979154d34d886 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Mon, 20 Jun 2022 14:36:53 +0100 Subject: [PATCH 31/32] Allowed values - Allowed values corrected for game item type, the winner needs to be an assigned category, not one of all categories --- app/Http/Controllers/ItemView.php | 3 ++- app/ItemType/Game/AllowedValue.php | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ItemView.php b/app/Http/Controllers/ItemView.php index 7d21cc13..a8ae341c 100644 --- a/app/Http/Controllers/ItemView.php +++ b/app/Http/Controllers/ItemView.php @@ -299,7 +299,8 @@ private function optionsGameShow( $allowed_values = new GameAllowedValue( $this->viewable_resource_types, $resource_type_id, - $resource_id + $resource_id, + $item_id ); return (new \App\HttpOptionResponse\Item\Game($this->permissions((int) $resource_type_id))) diff --git a/app/ItemType/Game/AllowedValue.php b/app/ItemType/Game/AllowedValue.php index 33d91ae3..29b508a0 100644 --- a/app/ItemType/Game/AllowedValue.php +++ b/app/ItemType/Game/AllowedValue.php @@ -4,7 +4,7 @@ namespace App\ItemType\Game; use App\HttpRequest\Hash; -use App\Models\Category; +use App\Models\ItemCategory; use JetBrains\PhpStorm\ArrayShape; class AllowedValue @@ -12,18 +12,21 @@ class AllowedValue protected Hash $hash; protected int $resource_type_id; protected ?int $resource_id; + protected ?int $item_id; protected array $viewable_resource_types; public function __construct( array $viewable_resource_types, int $resource_type_id, - ?int $resource_id = null + ?int $resource_id = null, + ?int $item_id = null ) { $this->hash = new Hash(); $this->resource_type_id = $resource_type_id; $this->resource_id = $resource_id; + $this->item_id = $item_id; $this->viewable_resource_types = $viewable_resource_types; } @@ -72,22 +75,23 @@ private function assignAllowedValuesForWinner(): array { $allowed_values = []; - $winners = (new Category())->paginatedCollection( + $winners = (new ItemCategory())->paginatedCollection( $this->resource_type_id, - $this->viewable_resource_types, + $this->resource_id, + $this->item_id, 0, 100 ); foreach ($winners as $winner) { - $winner_id = $this->hash->encode('category', $winner['category_id']); + $winner_id = $this->hash->encode('category', $winner['item_category_category_id']); $allowed_values[$winner_id] = [ 'uri' => route('category.show', ['resource_type_id' => $this->resource_type_id, 'category_id' => $winner_id], false), 'value' => $winner_id, - 'name' => $winner['category_name'], + 'name' => $winner['item_category_category_name'], 'description' => trans('item-type-game/allowed-values.description-prefix-winner_id') . - $winner['category_name'] . + $winner['item_category_category_name'] . trans('item-type-game/allowed-values.description-suffix-winner_id') ]; } From 76c04cc6da99b75d87d5293e35b848d53259cc2b Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Mon, 20 Jun 2022 15:10:56 +0100 Subject: [PATCH 32/32] Release - Set the release date, version and updated the changelog --- CHANGELOG.md | 25 +++++++++++++++++++ app/Http/Controllers/Controller.php | 2 ++ config/api/app/version.php | 4 +-- resources/views/welcome.blade.php | 38 ++++++++++++++--------------- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ed430a7..63babf3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,31 @@ 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.25.0] - 2022-06-20 +## Added +- We allow the `collection` parameter for `simple-item` item-type collections. +- We have added tests for subcategory management, found another bug, whoopee! +- We have added tests for item type responses. +- We have added an option response tests for the resource types collection and a resource type. +- We have added additional resource type tests and created/updated the json-schema files as necessary. +- We have added a catch-all route for non-matching routes. + +## Changed +- We have renamed the tests directory and corrected the namespaces. +- We are continuing to update out routes to named routes. +- We have moved additional responses to the response class. +- We have updated more response, if a collection is included in a response a `uri` field will contain the relative URI to the relevant collection. +- We have adjusted the layout of the test section in the README and added a note explaining the meaning of 'Non yet'. +- We have updated the response when attempting to delete an item with category assignments, rather than return a generic foreign key error, we specifically mention that there are category assignments that need to be removed first. +- We have cleaned up the response description lang file. + +## Fixed +- Removed an output in a test. +- Updated the route middleware, invalid decodes should return a 403 for the route. +- Added a unique validation rule for emails, don't leave the check to the database. +- Corrected the descriptions in the OPTIONS requests for `item` summaries. +- The allowed values for `winner_id` should be a category assigned to the item, not all the categories assigned to the resource type. + ## [v2.24.0] - 2022-06-13 ## Added - We have added our first schema files for OPTIONS responses and started working on the tests. diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index e5d1c1d9..d99e8ac0 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -9,6 +9,7 @@ use App\HttpRequest\Hash; use App\HttpRequest\Validate\Boolean; use Illuminate\Routing\Controller as BaseController; +use JetBrains\PhpStorm\ArrayShape; class Controller extends BaseController { @@ -127,6 +128,7 @@ protected function hasViewAccessToResourceType(int $resource_type_id): bool return in_array($resource_type_id, $this->viewable_resource_types, true) === true; } + #[ArrayShape(['view' => "bool", 'manage' => "bool"])] protected function permissions(int $resource_type_id): array { return [ diff --git a/config/api/app/version.php b/config/api/app/version.php index 2149b412..d2aaf1bd 100644 --- a/config/api/app/version.php +++ b/config/api/app/version.php @@ -3,9 +3,9 @@ declare(strict_types=1); return [ - 'version'=> 'v2.24.0', + 'version'=> 'v2.25.0', 'prefix' => 'v2', - 'release_date' => '2022-06-13', + 'release_date' => '2022-06-20', 'changelog' => [ 'api' => '/v2/changelog', 'markdown' => 'https://github.com/costs-to-expect/api/blob/master/CHANGELOG.md' diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 0ab15b7a..fb35665c 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -214,7 +214,7 @@ function gtag(){dataLayer.push(arguments);}
-

Latest release {{ $version }}

+

{{ $version }}

The latest release of the Costs to Expect API is {{ $version }}; we released it on the {{ date('jS M Y', strtotime($date)) }}.

@@ -225,34 +225,34 @@ function gtag(){dataLayer.push(arguments);}

Added

    -
  • We have added our first schema files for OPTIONS responses and started working on the tests.
  • -
  • We have added tests for category management, found one bug when creating the tests.
  • +
  • We allow the `collection` parameter for `simple-item` item-type collections.
  • +
  • We have added tests for subcategory management, found another bug, whoopee!
  • +
  • We have added tests for item type responses.
  • +
  • We have added an option response tests for the resource types collection and a resource type.
  • +
  • We have added additional resource type tests and created/updated the json-schema files as necessary.
  • +
  • We have added a catch-all route for non-matching routes.

Changed

    -
  • We have updated our response class for OPTIONS responses, we now allow parameters to be defined for POST requests. One example of where we need this is the create password POST request, `password` and `password_confirmation` are required fields, however, `token` and `email` are required parameters. Before this update, you had to parse the returned error of read the OPTIONS request description.
  • -
  • We have started splitting config files, a config file should be for one purpose.
  • -
  • We have spent quite a bit of time reviewing the API structure and refactoring. We have removed unnecessary complexity, renamed classes and methods to describe intent more clearly and removed pointless base classes.
  • -
  • We have reworked how allowed values are generated for the different item types, allowed values for fields and parameters have been split, and we have removed all abstraction.
  • -
  • We have removed some route validation files which didn't do anything useful after all the item type work.
  • -
  • We have reworked the responses class, removed exception parameters when not necessary, pass in an exception if thrown and now delegated responsibility to the responses class to decide if the exception should be returned in the response.
  • -
  • We have upgraded the API to Laravel 9 and PHP 8.1.
  • +
  • We have renamed the tests directory and corrected the namespaces.
  • +
  • We are continuing to update out routes to named routes.
  • +
  • We have moved additional responses to the response class.
  • +
  • We have updated more response, if a collection is included in a response a `uri` field will contain the relative URI to the relevant collection.
  • +
  • We have adjusted the layout of the test section in the README and added a note explaining the meaning of 'Non yet'.
  • +
  • We have updated the response when attempting to delete an item with category assignments, rather than return a generic foreign key error, we specifically mention that there are category assignments that need to be removed first.
  • +
  • We have cleaned up the response description lang file.

Fixed

    -
  • Options request incorrect for the `auth.register` endpoint (Test added).
  • -
  • Options requests returning response twice.
  • -
  • Type corrected in OPTIONS response, authentication status/requirements now a boolean, not a string.
  • -
  • Minor correction to the description of two POST endpoints.
  • -
  • Corrected a type in the OPTIONS response for the month parameter.
  • -
  • Corrected the `partial-transfer` JSON schema file.
  • -
  • Allowed values not showing for `category` on GET endpoints.
  • -
  • Inconsistent usage of the responses helper.
  • -
  • Category validator allowed duplicate names due to incorrect params, caught by model.
  • +
  • Removed an output in a test.
  • +
  • Updated the route middleware, invalid decodes should return a 403 for the route.
  • +
  • Added a unique validation rule for emails, don't leave the check to the database.
  • +
  • Corrected the descriptions in the OPTIONS requests for `item` summaries.
  • +
  • The allowed values for `winner_id` should be a category assigned to the item, not all the categories assigned to the resource type.

Removed