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/README.md b/README.md index 15b2ee48..2ccb703a 100644 --- a/README.md +++ b/README.md @@ -260,23 +260,27 @@ 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) | Not started | -| ToolManage (Actions) | Not started | -| Summaries (Responses) | Not started | -| Total | In Progress (84 Tests) | +| 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) | 11 Tests | +| SubcategoryManage (Actions) | 12 Tests | +| ToolManage (Actions) | Non yet* | +| Summaries (Responses) | Non yet* | +| **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/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 87% rename from tests/Feature/Http/Controllers/AuthenticationTest.php rename to Tests/Feature/Http/Controllers/AuthenticationTest.php index cde2bd98..009629d5 100644 --- a/tests/Feature/Http/Controllers/AuthenticationTest.php +++ b/Tests/Feature/Http/Controllers/AuthenticationTest.php @@ -5,10 +5,10 @@ use App\User; use Tests\TestCase; -class AuthenticationTest extends TestCase +final 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); @@ -158,8 +156,6 @@ public function create_new_password_errors_with_invalid_token_and_email(): 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]), [ @@ -172,7 +168,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 +215,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 +265,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 +291,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 +317,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 +328,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 +354,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 +382,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 +411,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 +424,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 +473,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 +512,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 +551,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 +590,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 +603,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 +616,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 +628,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 +642,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 +655,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 +668,33 @@ public function registration_errors_with_no_name(): void } /** @test */ - public function registration_errors_with_no_payload(): void + 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 { $response = $this->post( route('auth.register'), @@ -683,7 +705,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 +719,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 +735,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 +749,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 +767,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 +782,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 +795,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 +810,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 similarity index 83% rename from tests/Feature/Http/Controllers/CategoryManageTest.php rename to Tests/Feature/Http/Controllers/CategoryManageTest.php index c0045368..ba72cf51 100644 --- a/tests/Feature/Http/Controllers/CategoryManageTest.php +++ b/Tests/Feature/Http/Controllers/CategoryManageTest.php @@ -7,10 +7,10 @@ use App\User; use Tests\TestCase; -class CategoryManageTest extends TestCase +final 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,16 +151,16 @@ 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)); $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 updateCategoryFailsNoPayload(): 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, [] ); @@ -187,7 +187,7 @@ public function update_category_fails_non_payload(): void } /** @test */ - public function update_category_fails_non_unique_name(): void + public function updateCategoryFailsNonUniqueName(): void { $this->actingAs(User::find(1)); @@ -226,22 +226,20 @@ public function update_category_fails_non_unique_name(): void ] ); - echo $response->content(); - $response->assertStatus(422); } /** @test */ - public function update_category_success(): void + public function updateCategorySuccess(): 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/PermittedUserManageTest.php b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php similarity index 84% rename from tests/Feature/Http/Controllers/PermittedUserManageTest.php rename to Tests/Feature/Http/Controllers/PermittedUserManageTest.php index 9c4f855c..d06afb3c 100644 --- a/tests/Feature/Http/Controllers/PermittedUserManageTest.php +++ b/Tests/Feature/Http/Controllers/PermittedUserManageTest.php @@ -5,10 +5,10 @@ use App\User; use Tests\TestCase; -class PermittedUserManageTest extends TestCase +final 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 similarity index 88% rename from tests/Feature/Http/Controllers/ResourceManageTest.php rename to Tests/Feature/Http/Controllers/ResourceManageTest.php index 98bb5cd3..188d9736 100644 --- a/tests/Feature/Http/Controllers/ResourceManageTest.php +++ b/Tests/Feature/Http/Controllers/ResourceManageTest.php @@ -7,10 +7,10 @@ use App\User; use Tests\TestCase; -class ResourceManageTest extends TestCase +final 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 similarity index 87% rename from tests/Feature/Http/Controllers/ResourceTypeManageTest.php rename to Tests/Feature/Http/Controllers/ResourceTypeManageTest.php index 14e4b6c7..cf49daa0 100644 --- a/tests/Feature/Http/Controllers/ResourceTypeManageTest.php +++ b/Tests/Feature/Http/Controllers/ResourceTypeManageTest.php @@ -5,10 +5,10 @@ use App\User; use Tests\TestCase; -class ResourceTypeManageTest extends TestCase +final 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/SubcategoryManageTest.php b/Tests/Feature/Http/Controllers/SubcategoryManageTest.php new file mode 100644 index 00000000..134645f6 --- /dev/null +++ b/Tests/Feature/Http/Controllers/SubcategoryManageTest.php @@ -0,0 +1,287 @@ +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 createSubcategoryFailsNoPayload(): 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 createSubcategoryFailsNonUniqueName(): 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 createSubcategoryForbiddenWhenCategoryIdInvalid(): 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); + } + + /** @test */ + public function createSubcategorySuccess(): 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 deleteSubcategorySuccess(): 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 updateSubcategoryFailsExtraFieldsInPayload(): 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 updateSubcategoryFailsNoPayload(): 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 updateSubcategoryFailsNonUniqueName(): 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 updateSubcategoryDescriptionSuccess(): 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 updateSubcategoryNameSuccess(): 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 updateSubcategorySuccess(): 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 similarity index 71% rename from tests/TestCase.php rename to Tests/TestCase.php index 16aa13a4..eb40bc85 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 @@ -38,6 +43,16 @@ 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'); + } + protected function assertJsonMatchesSchema($content, $schema_file): void { $schema = Schema::fromJsonString(file_get_contents(public_path($schema_file))); @@ -101,6 +116,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,14 +162,34 @@ 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(); } - 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 @@ -159,6 +212,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( @@ -195,6 +253,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); @@ -205,6 +283,16 @@ 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); + } + protected function optionsRoute(string $route, array $parameters = []): TestResponse { return $this->options(route($route, $parameters)); @@ -239,6 +327,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/tests/View/Http/Controllers/AuthenticationTest.php b/Tests/View/Http/Controllers/AuthenticationTest.php similarity index 92% rename from tests/View/Http/Controllers/AuthenticationTest.php rename to 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/ItemTypeViewTest.php b/Tests/View/Http/Controllers/ItemTypeViewTest.php new file mode 100644 index 00000000..d82ba427 --- /dev/null +++ b/Tests/View/Http/Controllers/ItemTypeViewTest.php @@ -0,0 +1,188 @@ +actingAs(User::find(1)); + + $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 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function itemTypeCollectionPagination(): void + { + $this->actingAs(User::find(1)); + + $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 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function itemTypeCollectionSearchDescription(): void + { + $this->actingAs(User::find(1)); + + $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 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function itemTypeCollectionSearchName(): void + { + $this->actingAs(User::find(1)); + + $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 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function itemTypeCollectionSearchNameNoResults(): void + { + $this->actingAs(User::find(1)); + + $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 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function itemTypeCollectionSortName(): void + { + $this->actingAs(User::find(1)); + + $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 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function itemTypeShow(): void + { + $this->actingAs(User::find(1)); + + $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/PermittedUserViewTest.php b/Tests/View/Http/Controllers/PermittedUserViewTest.php similarity index 91% rename from tests/View/Http/Controllers/PermittedUserViewTest.php rename to Tests/View/Http/Controllers/PermittedUserViewTest.php index 128c00f3..5bd4ce80 100644 --- a/tests/View/Http/Controllers/PermittedUserViewTest.php +++ b/Tests/View/Http/Controllers/PermittedUserViewTest.php @@ -5,10 +5,10 @@ use App\User; use Tests\TestCase; -class PermittedUserViewTest extends TestCase +final 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 new file mode 100644 index 00000000..6b78945e --- /dev/null +++ b/Tests/View/Http/Controllers/ResourceTypeViewTest.php @@ -0,0 +1,228 @@ +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 + { + $response = $this->optionsResourceTypeCollection(); + $response->assertStatus(200); + + $this->assertJsonMatchesSchema($response->content(), 'api/schema/options/resource-type-collection.json'); + } + + /** @test */ + public function resourceTypeCollection(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(); + + $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->assertJsonIsResourceType($json); + } + } + + /** @test */ + public function resourceTypeCollectionPagination(): void + { + $this->actingAs(User::find(1)); + + $response = $this->getResourceTypes(['offset'=>1, 'limit'=> 1]); + + $response->assertStatus(200); + $response->assertHeader('X-Offset', 1); + $response->assertHeader('X-Limit', 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->assertJsonIsResourceType($json); + } + } + + /** + * @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 + { + $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]); + $response->assertStatus(200); + + $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 + { + $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/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/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 c8280d52..088ceeb9 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; @@ -20,9 +20,9 @@ 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; class Authentication extends \Illuminate\Routing\Controller { @@ -105,7 +105,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 +176,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 +230,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); } @@ -323,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 @@ -349,7 +346,11 @@ public function register(Request $request): Http\JsonResponse $request->all(), [ 'name' => 'required', - 'email' => 'required|email', + 'email' => [ + 'required', + 'email', + Rule::unique(User::class, 'email') + ] ] ); @@ -389,8 +390,7 @@ 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); + return Response::unableToCreateAccount($e); } return response()->json( @@ -452,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 @@ -510,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 { @@ -521,14 +521,13 @@ 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); } 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 @@ -609,10 +608,10 @@ 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); + return Response::authenticationFailed(); } public function deleteToken($token_id): Http\JsonResponse @@ -634,13 +633,13 @@ 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); + return Response::authenticationFailed(); } public function optionsUser(): Http\JsonResponse 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/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/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..3f13c0b6 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::foreignKeyConstraintCategory(); } 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::foreignKeyConstraintCategory(); } 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::foreignKeyConstraintCategory(); } 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::foreignKeyConstraintCategory(); } 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..a8ae341c 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,19 +287,20 @@ 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( $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))) @@ -315,13 +316,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 +344,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 +356,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 a1575978..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,8 +80,7 @@ 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); + return \App\HttpResponse\Response::failedToSaveModelForCreate($e); } return response()->json( @@ -96,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); @@ -137,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(); } } @@ -154,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([ @@ -173,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( @@ -184,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) { @@ -205,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 74b27ecd..4bd34d3b 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\Response; 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..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; @@ -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 Response::notFoundOrNotAccessible($route_params[$param]); + } + + if (is_int($id) === false) { + return Response::notFoundOrNotAccessible($route_params[$param]); + } + + $request->route()->setParameter($param, $id); } } 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/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/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/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/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/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/app/HttpResponse/Responses.php b/app/HttpResponse/Response.php similarity index 83% rename from app/HttpResponse/Responses.php rename to app/HttpResponse/Response.php index 41239a4e..8ca7f83e 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 { @@ -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 = [ @@ -127,6 +143,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 +196,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( 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/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') ]; } 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/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/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..7675762e 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; @@ -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, @@ -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] = [ 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/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": { 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" } 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/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/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 @@ - + 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 50adc08f..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": { @@ -18,14 +19,14 @@ }, "created": { "type": "string" - }, - "required": [ - "id", - "name", - "friendly_name", - "description", - "example", - "created" - ] - } + } + }, + "required": [ + "id", + "name", + "friendly_name", + "description", + "example", + "created" + ] } 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..188ba745 --- /dev/null +++ b/public/api/schema/options/resource-type-collection.json @@ -0,0 +1,537 @@ +{ + "$id": "https://api.costs-to-expect.com/v2/api/schema/options/resource-type-collection.json", + "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", + "items": { + "type": "string" + } + }, + "searchable": { + "type": "object", + "properties": { + "name": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + } + }, + "description": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + } + } + }, + "required": [ + "name", + "description" + ] + }, + "filterable": { + "type": [ + "array" + ] + }, + "parameters": { + "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": [ + "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" + }, + "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": [ + "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" + ] +} diff --git a/public/api/schema/options/resource-type.json b/public/api/schema/options/resource-type.json new file mode 100644 index 00000000..f8d0a28a --- /dev/null +++ b/public/api/schema/options/resource-type.json @@ -0,0 +1,299 @@ +{ + "$id": "https://api.costs-to-expect.com/v2/api/schema/options/resource-type-collection.json", + "type": "object", + "properties": { + "DELETE": { + "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", + "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", + "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 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-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" + ] +} 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/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-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": [ diff --git a/public/api/schema/resource.json b/public/api/schema/resource.json index fafe26ed..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": { @@ -13,25 +14,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 +23,6 @@ "name", "description", "data", - "item_subtype", "created" ] } 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": { diff --git a/resources/lang/en/responses.php b/resources/lang/en/responses.php index cf9198fd..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.', @@ -20,4 +21,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/resources/lang/en/route-descriptions.php b/resources/lang/en/route-descriptions.php index 12fe6d7e..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,10 +104,9 @@ '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_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', ]; 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

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')] + ); +}); 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}', diff --git a/routes/api/public-routes.php b/routes/api/public-routes.php index 31d5c2c8..b8cd4bda 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', @@ -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}', diff --git a/tests/View/Http/Controllers/ResourceTypeViewTest.php b/tests/View/Http/Controllers/ResourceTypeViewTest.php deleted file mode 100644 index aeed0597..00000000 --- a/tests/View/Http/Controllers/ResourceTypeViewTest.php +++ /dev/null @@ -1,67 +0,0 @@ -actingAs(User::find(1)); - - $response = $this->getResourceTypes(); - - $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->assertJsonIsResourceType($json); - } - } - - /** @test */ - public function collection_pagination(): void - { - $this->actingAs(User::find(1)); - - $response = $this->getResourceTypes(['offset'=>1, 'limit'=> 1]); - - $response->assertStatus(200); - $response->assertHeader('X-Offset', 1); - $response->assertHeader('X-Limit', 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->assertJsonIsResourceType($json); - } - } - - /** @test */ - public function item(): 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]); - $response->assertStatus(200); - - $this->assertJsonIsResourceType($response->content()); - } -}