From 3ef57dc25b3595b6491d97e3a73822e2add5939f Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Wed, 5 Jan 2022 11:51:07 -0500 Subject: [PATCH] feat: manage contact information type (monicahq/chandler#15) --- ...nalizeContatInformationTypesController.php | 72 +++++ ...eContactInformationTypeIndexViewHelper.php | 48 ++++ .../PersonalizeIndexViewHelper.php | 1 + app/Models/ContactInformationType.php | 2 +- .../Personalize/AddressTypes/Index.vue | 4 +- .../ContactInformationTypes/Index.vue | 270 ++++++++++++++++++ .../Settings/Personalize/Genders/Index.vue | 2 +- .../js/Pages/Settings/Personalize/Index.vue | 1 + .../Personalize/PetCategories/Index.vue | 2 +- .../Settings/Personalize/Pronouns/Index.vue | 4 +- resources/js/Shared/TextInput.vue | 2 +- routes/web.php | 7 + ...sonalizeAddressTypeIndexViewHelperTest.php | 8 +- ...tactInformationTypeIndexViewHelperTest.php | 54 ++++ .../PersonalizeGenderIndexViewHelperTest.php | 8 +- .../PersonalizeLabelIndexViewHelperTest.php | 8 +- ...nalizePetCategoriesIndexViewHelperTest.php | 8 +- .../PersonalizePronounIndexViewHelperTest.php | 8 +- .../PersonalizeIndexViewHelperTest.php | 1 + 19 files changed, 472 insertions(+), 38 deletions(-) create mode 100644 app/Http/Controllers/Settings/Personalize/ContactInformationTypes/PersonalizeContatInformationTypesController.php create mode 100644 app/Http/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelper.php create mode 100644 resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue create mode 100644 tests/Unit/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelperTest.php diff --git a/app/Http/Controllers/Settings/Personalize/ContactInformationTypes/PersonalizeContatInformationTypesController.php b/app/Http/Controllers/Settings/Personalize/ContactInformationTypes/PersonalizeContatInformationTypesController.php new file mode 100644 index 00000000000..6970161977b --- /dev/null +++ b/app/Http/Controllers/Settings/Personalize/ContactInformationTypes/PersonalizeContatInformationTypesController.php @@ -0,0 +1,72 @@ + VaultIndexViewHelper::layoutData(), + 'data' => PersonalizeContactInformationTypeIndexViewHelper::data(Auth::user()->account), + ]); + } + + public function store(Request $request) + { + $data = [ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'name' => $request->input('name'), + 'protocol' => $request->input('protocol'), + ]; + + $contactInformationType = (new CreateContactInformationType)->execute($data); + + return response()->json([ + 'data' => PersonalizeContactInformationTypeIndexViewHelper::dtoContactInformationType($contactInformationType), + ], 201); + } + + public function update(Request $request, int $contactInformationTypeId) + { + $data = [ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'contact_information_type_id' => $contactInformationTypeId, + 'name' => $request->input('name'), + 'protocol' => $request->input('protocol'), + ]; + + $contactInformationType = (new UpdateContactInformationType)->execute($data); + + return response()->json([ + 'data' => PersonalizeContactInformationTypeIndexViewHelper::dtoContactInformationType($contactInformationType), + ], 200); + } + + public function destroy(Request $request, int $contactInformationTypeId) + { + $data = [ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'contact_information_type_id' => $contactInformationTypeId, + ]; + + (new DestroyContactInformationType)->execute($data); + + return response()->json([ + 'data' => true, + ], 200); + } +} diff --git a/app/Http/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelper.php b/app/Http/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelper.php new file mode 100644 index 00000000000..6f1eab95458 --- /dev/null +++ b/app/Http/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelper.php @@ -0,0 +1,48 @@ +contactInformationTypes() + ->orderBy('name', 'asc') + ->get(); + + $collection = collect(); + foreach ($types as $type) { + $collection->push(self::dtoContactInformationType($type)); + } + + return [ + 'contact_information_types' => $collection, + 'url' => [ + 'settings' => route('settings.index'), + 'personalize' => route('settings.personalize.index'), + 'contact_information_type_store' => route('settings.personalize.contact_information_type.store'), + ], + ]; + } + + public static function dtoContactInformationType(ContactInformationType $type): array + { + return [ + 'id' => $type->id, + 'name' => $type->name, + 'protocol' => $type->protocol, + 'can_be_deleted' => $type->can_be_deleted, + 'url' => [ + 'update' => route('settings.personalize.contact_information_type.update', [ + 'type' => $type->id, + ]), + 'destroy' => route('settings.personalize.contact_information_type.destroy', [ + 'type' => $type->id, + ]), + ], + ]; + } +} diff --git a/app/Http/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelper.php b/app/Http/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelper.php index 92c9ce29c32..ae146eda688 100644 --- a/app/Http/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelper.php +++ b/app/Http/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelper.php @@ -16,6 +16,7 @@ public static function data(): array 'manage_pronouns' => route('settings.personalize.pronoun.index'), 'manage_address_types' => route('settings.personalize.address_type.index'), 'manage_pet_categories' => route('settings.personalize.pet_category.index'), + 'manage_contact_information_types' => route('settings.personalize.contact_information_type.index'), ], ]; } diff --git a/app/Models/ContactInformationType.php b/app/Models/ContactInformationType.php index 249aa4be80c..237d4dd73cf 100644 --- a/app/Models/ContactInformationType.php +++ b/app/Models/ContactInformationType.php @@ -19,7 +19,7 @@ class ContactInformationType extends Model 'account_id', 'name', 'protocol', - 'type', // used to make sure phone and email fields can't be deleted + 'type', // used to make sure phone and email fields can't be deleted, and also to find the email address of the contact quickly ]; /** diff --git a/resources/js/Pages/Settings/Personalize/AddressTypes/Index.vue b/resources/js/Pages/Settings/Personalize/AddressTypes/Index.vue index 97fc3285897..a22692e625e 100644 --- a/resources/js/Pages/Settings/Personalize/AddressTypes/Index.vue +++ b/resources/js/Pages/Settings/Personalize/AddressTypes/Index.vue @@ -53,7 +53,7 @@ 🏖 All the address types - + @@ -75,7 +75,7 @@
- +
diff --git a/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue b/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue new file mode 100644 index 00000000000..f30d0140cac --- /dev/null +++ b/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue @@ -0,0 +1,270 @@ + + + + + diff --git a/resources/js/Pages/Settings/Personalize/Genders/Index.vue b/resources/js/Pages/Settings/Personalize/Genders/Index.vue index 1fe7aac0040..a367c6b0588 100644 --- a/resources/js/Pages/Settings/Personalize/Genders/Index.vue +++ b/resources/js/Pages/Settings/Personalize/Genders/Index.vue @@ -75,7 +75,7 @@
- +
diff --git a/resources/js/Pages/Settings/Personalize/Index.vue b/resources/js/Pages/Settings/Personalize/Index.vue index 6c0fa57966e..04605666b56 100644 --- a/resources/js/Pages/Settings/Personalize/Index.vue +++ b/resources/js/Pages/Settings/Personalize/Index.vue @@ -39,6 +39,7 @@
  • 👩‍🔬 Manage pronouns
  • 🚻 Manage genders
  • 🏖 Manage address types
  • +
  • ☎️ Manage contact information types
  • 🐱 Manage pet categories
  • diff --git a/resources/js/Pages/Settings/Personalize/PetCategories/Index.vue b/resources/js/Pages/Settings/Personalize/PetCategories/Index.vue index d1107196502..c6d23540e15 100644 --- a/resources/js/Pages/Settings/Personalize/PetCategories/Index.vue +++ b/resources/js/Pages/Settings/Personalize/PetCategories/Index.vue @@ -75,7 +75,7 @@
    - +
    diff --git a/resources/js/Pages/Settings/Personalize/Pronouns/Index.vue b/resources/js/Pages/Settings/Personalize/Pronouns/Index.vue index 0362f592b4b..96b19bcb30a 100644 --- a/resources/js/Pages/Settings/Personalize/Pronouns/Index.vue +++ b/resources/js/Pages/Settings/Personalize/Pronouns/Index.vue @@ -53,7 +53,7 @@ 🚻 All the pronouns - + @@ -75,7 +75,7 @@
    - +
    diff --git a/resources/js/Shared/TextInput.vue b/resources/js/Shared/TextInput.vue index ff7bce51016..fdcbb78f226 100644 --- a/resources/js/Shared/TextInput.vue +++ b/resources/js/Shared/TextInput.vue @@ -49,7 +49,7 @@ -

    +

    {{ help }}

    diff --git a/routes/web.php b/routes/web.php index 22c4ea8b66f..d8adb55fd94 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,6 +17,7 @@ use App\Http\Controllers\Settings\Personalize\Relationships\PersonalizeRelationshipController; use App\Http\Controllers\Settings\Personalize\PetCategories\PersonalizePetCategoriesController; use App\Http\Controllers\Settings\Personalize\Relationships\PersonalizeRelationshipTypeController; +use App\Http\Controllers\Settings\Personalize\ContactInformationTypes\PersonalizeContatInformationTypesController; Route::get('/', function () { return Inertia::render('Welcome', [ @@ -108,6 +109,12 @@ Route::post('petCategories', [PersonalizePetCategoriesController::class, 'store'])->name('settings.personalize.pet_category.store'); Route::put('petCategories/{petCategory}', [PersonalizePetCategoriesController::class, 'update'])->name('settings.personalize.pet_category.update'); Route::delete('petCategories/{petCategory}', [PersonalizePetCategoriesController::class, 'destroy'])->name('settings.personalize.pet_category.destroy'); + + // contact information + Route::get('contactInformationType', [PersonalizeContatInformationTypesController::class, 'index'])->name('settings.personalize.contact_information_type.index'); + Route::post('contactInformationType', [PersonalizeContatInformationTypesController::class, 'store'])->name('settings.personalize.contact_information_type.store'); + Route::put('contactInformationType/{type}', [PersonalizeContatInformationTypesController::class, 'update'])->name('settings.personalize.contact_information_type.update'); + Route::delete('contactInformationType/{type}', [PersonalizeContatInformationTypesController::class, 'destroy'])->name('settings.personalize.contact_information_type.destroy'); }); // cancel diff --git a/tests/Unit/Controllers/Settings/Personalize/AddressTypes/ViewHelpers/PersonalizeAddressTypeIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/AddressTypes/ViewHelpers/PersonalizeAddressTypeIndexViewHelperTest.php index 16a988d22c7..d88c78aca1f 100644 --- a/tests/Unit/Controllers/Settings/Personalize/AddressTypes/ViewHelpers/PersonalizeAddressTypeIndexViewHelperTest.php +++ b/tests/Unit/Controllers/Settings/Personalize/AddressTypes/ViewHelpers/PersonalizeAddressTypeIndexViewHelperTest.php @@ -42,12 +42,8 @@ public function it_gets_the_data_needed_for_the_data_transfer_object(): void 'id' => $addressType->id, 'name' => $addressType->name, 'url' => [ - 'update' => route('settings.personalize.address_type.update', [ - 'addressType' => $addressType->id, - ]), - 'destroy' => route('settings.personalize.address_type.destroy', [ - 'addressType' => $addressType->id, - ]), + 'update' => env('APP_URL').'/settings/personalize/addressTypes/'.$addressType->id, + 'destroy' => env('APP_URL').'/settings/personalize/addressTypes/'.$addressType->id, ], ], $array diff --git a/tests/Unit/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelperTest.php new file mode 100644 index 00000000000..7c998376e05 --- /dev/null +++ b/tests/Unit/Controllers/Settings/Personalize/ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelperTest.php @@ -0,0 +1,54 @@ +create(); + $array = PersonalizeContactInformationTypeIndexViewHelper::data($contactInformationType->account); + $this->assertEquals( + 2, + count($array) + ); + $this->assertArrayHasKey('contact_information_types', $array); + $this->assertEquals( + [ + 'settings' => env('APP_URL').'/settings', + 'personalize' => env('APP_URL').'/settings/personalize', + 'contact_information_type_store' => env('APP_URL').'/settings/personalize/contactInformationType', + ], + $array['url'] + ); + } + + /** @test */ + public function it_gets_the_data_needed_for_the_data_transfer_object(): void + { + $contactInformationType = ContactInformationType::factory()->create(); + $array = PersonalizeContactInformationTypeIndexViewHelper::dtoContactInformationType($contactInformationType); + $this->assertEquals( + [ + 'id' => $contactInformationType->id, + 'name' => $contactInformationType->name, + 'protocol' => $contactInformationType->protocol, + 'can_be_deleted' => $contactInformationType->can_be_deleted, + 'url' => [ + 'update' => env('APP_URL').'/settings/personalize/contactInformationType/'.$contactInformationType->id, + 'destroy' => env('APP_URL').'/settings/personalize/contactInformationType/'.$contactInformationType->id, + ], + ], + $array + ); + } +} diff --git a/tests/Unit/Controllers/Settings/Personalize/Genders/ViewHelpers/PersonalizeGenderIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/Genders/ViewHelpers/PersonalizeGenderIndexViewHelperTest.php index b4144eb2934..5efd2c93b20 100644 --- a/tests/Unit/Controllers/Settings/Personalize/Genders/ViewHelpers/PersonalizeGenderIndexViewHelperTest.php +++ b/tests/Unit/Controllers/Settings/Personalize/Genders/ViewHelpers/PersonalizeGenderIndexViewHelperTest.php @@ -42,12 +42,8 @@ public function it_gets_the_data_needed_for_the_data_transfer_object(): void 'id' => $gender->id, 'name' => $gender->name, 'url' => [ - 'update' => route('settings.personalize.gender.update', [ - 'gender' => $gender->id, - ]), - 'destroy' => route('settings.personalize.gender.destroy', [ - 'gender' => $gender->id, - ]), + 'update' => env('APP_URL').'/settings/personalize/genders/'.$gender->id, + 'destroy' => env('APP_URL').'/settings/personalize/genders/'.$gender->id, ], ], $array diff --git a/tests/Unit/Controllers/Settings/Personalize/Labels/ViewHelpers/PersonalizeLabelIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/Labels/ViewHelpers/PersonalizeLabelIndexViewHelperTest.php index cd0497bb7f7..99f265e8a5e 100644 --- a/tests/Unit/Controllers/Settings/Personalize/Labels/ViewHelpers/PersonalizeLabelIndexViewHelperTest.php +++ b/tests/Unit/Controllers/Settings/Personalize/Labels/ViewHelpers/PersonalizeLabelIndexViewHelperTest.php @@ -43,12 +43,8 @@ public function it_gets_the_data_needed_for_the_data_transfer_object(): void 'name' => $label->name, 'count' => 0, 'url' => [ - 'update' => route('settings.personalize.label.update', [ - 'label' => $label->id, - ]), - 'destroy' => route('settings.personalize.label.destroy', [ - 'label' => $label->id, - ]), + 'update' => env('APP_URL').'/settings/personalize/labels/'.$label->id, + 'destroy' => env('APP_URL').'/settings/personalize/labels/'.$label->id, ], ], $array diff --git a/tests/Unit/Controllers/Settings/Personalize/PetCategories/ViewHelpers/PersonalizePetCategoriesIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/PetCategories/ViewHelpers/PersonalizePetCategoriesIndexViewHelperTest.php index 2f140a7f5ce..4dac5223c1d 100644 --- a/tests/Unit/Controllers/Settings/Personalize/PetCategories/ViewHelpers/PersonalizePetCategoriesIndexViewHelperTest.php +++ b/tests/Unit/Controllers/Settings/Personalize/PetCategories/ViewHelpers/PersonalizePetCategoriesIndexViewHelperTest.php @@ -42,12 +42,8 @@ public function it_gets_the_data_needed_for_the_data_transfer_object(): void 'id' => $petCategory->id, 'name' => $petCategory->name, 'url' => [ - 'update' => route('settings.personalize.pet_category.update', [ - 'petCategory' => $petCategory->id, - ]), - 'destroy' => route('settings.personalize.pet_category.destroy', [ - 'petCategory' => $petCategory->id, - ]), + 'update' => env('APP_URL').'/settings/personalize/petCategories/'.$petCategory->id, + 'destroy' => env('APP_URL').'/settings/personalize/petCategories/'.$petCategory->id, ], ], $array diff --git a/tests/Unit/Controllers/Settings/Personalize/Pronouns/ViewHelpers/PersonalizePronounIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/Pronouns/ViewHelpers/PersonalizePronounIndexViewHelperTest.php index 8e31e93d61d..d92947c164c 100644 --- a/tests/Unit/Controllers/Settings/Personalize/Pronouns/ViewHelpers/PersonalizePronounIndexViewHelperTest.php +++ b/tests/Unit/Controllers/Settings/Personalize/Pronouns/ViewHelpers/PersonalizePronounIndexViewHelperTest.php @@ -42,12 +42,8 @@ public function it_gets_the_data_needed_for_the_data_transfer_object(): void 'id' => $pronoun->id, 'name' => $pronoun->name, 'url' => [ - 'update' => route('settings.personalize.pronoun.update', [ - 'pronoun' => $pronoun->id, - ]), - 'destroy' => route('settings.personalize.pronoun.destroy', [ - 'pronoun' => $pronoun->id, - ]), + 'update' => env('APP_URL').'/settings/personalize/pronouns/'.$pronoun->id, + 'destroy' => env('APP_URL').'/settings/personalize/pronouns/'.$pronoun->id, ], ], $array diff --git a/tests/Unit/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelperTest.php b/tests/Unit/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelperTest.php index 4306b0ae820..4ea4ed22acc 100644 --- a/tests/Unit/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelperTest.php +++ b/tests/Unit/Controllers/Settings/Personalize/ViewHelpers/PersonalizeIndexViewHelperTest.php @@ -26,6 +26,7 @@ public function it_gets_the_data_needed_for_the_view(): void 'manage_pronouns' => env('APP_URL').'/settings/personalize/pronouns', 'manage_address_types' => env('APP_URL').'/settings/personalize/addressTypes', 'manage_pet_categories' => env('APP_URL').'/settings/personalize/petCategories', + 'manage_contact_information_types' => env('APP_URL').'/settings/personalize/contactInformationType', ], ], $array