-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manage contact information type (monicahq/chandler#15)
- Loading branch information
Showing
19 changed files
with
472 additions
and
38 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...tings/Personalize/ContactInformationTypes/PersonalizeContatInformationTypesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings\Personalize\ContactInformationTypes; | ||
|
||
use Inertia\Inertia; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Http\Controllers\Vault\ViewHelpers\VaultIndexViewHelper; | ||
use App\Services\Account\ManageContactInformationTypes\CreateContactInformationType; | ||
use App\Services\Account\ManageContactInformationTypes\UpdateContactInformationType; | ||
use App\Services\Account\ManageContactInformationTypes\DestroyContactInformationType; | ||
use App\Http\Controllers\Settings\Personalize\ContactInformationTypes\ViewHelpers\PersonalizeContactInformationTypeIndexViewHelper; | ||
|
||
class PersonalizeContatInformationTypesController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return Inertia::render('Settings/Personalize/ContactInformationTypes/Index', [ | ||
'layoutData' => 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); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../ContactInformationTypes/ViewHelpers/PersonalizeContactInformationTypeIndexViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings\Personalize\ContactInformationTypes\ViewHelpers; | ||
|
||
use App\Models\Account; | ||
use App\Models\ContactInformationType; | ||
|
||
class PersonalizeContactInformationTypeIndexViewHelper | ||
{ | ||
public static function data(Account $account): array | ||
{ | ||
$types = $account->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, | ||
]), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.