From 12697c22686ba62623a87536ad8f5e0effb268ce Mon Sep 17 00:00:00 2001 From: ncoronel Date: Mon, 3 Aug 2026 13:37:37 -0300 Subject: [PATCH] feat: Refactor bootstrap functionality by adding AdminApp and Tenant controllers, requests, resources, and services; remove deprecated event form components --- .../AdminAppBootstrapController.php | 20 ++++++ .../Controllers/TenantBootstrapController.php | 20 ++++++ .../Requests/AdminAppBootstrapRequest.php | 5 ++ .../Requests/TenantBootstrapRequest.php} | 12 ++-- .../Resources/AdminAppBootstrapResource.php | 44 +++++++++++++ .../Resources/SocialMediaOptionResource.php | 2 +- .../Services/AdminAppBootstrapService.php | 22 +++++++ .../Services/TenantBootstrapService.php | 26 ++++++++ app/Domains/Bootstrap/routes/adminapp.php | 9 +++ app/Domains/Bootstrap/routes/api.php | 9 +++ .../AdminApp/EventFormController.php | 19 ------ .../Forms/Resources/EventFormResource.php | 19 ------ .../Forms/Services/EventFormService.php | 17 ----- app/Domains/Forms/routes/adminapp.php | 10 --- app/Domains/Forms/routes/api.php | 3 - .../AdminApp/BootstrapAdminAppController.php | 25 ------- .../Controllers/BootstrapTenantController.php | 38 ----------- .../Requests/BootstrapAdminAppRequest.php | 5 -- .../AdminApp/BootstrapAdminAppResource.php | 36 ---------- app/Domains/Tenant/routes/adminapp.php | 6 -- app/Domains/Tenant/routes/api.php | 4 -- routes/api.php | 2 +- .../Forms/AdminAppEventFormControllerTest.php | 66 ------------------- .../BootstrapAdminAppControllerTest.php | 6 ++ .../AdminAppBootstrapResourceTest.php | 40 +++++++++++ .../Tenant/BootstrapAdminAppResourceTest.php | 25 ------- 26 files changed, 207 insertions(+), 283 deletions(-) create mode 100644 app/Domains/Bootstrap/Controllers/AdminAppBootstrapController.php create mode 100644 app/Domains/Bootstrap/Controllers/TenantBootstrapController.php create mode 100644 app/Domains/Bootstrap/Requests/AdminAppBootstrapRequest.php rename app/Domains/{Tenant/Requests/BootstrapTenantRequest.php => Bootstrap/Requests/TenantBootstrapRequest.php} (82%) create mode 100644 app/Domains/Bootstrap/Resources/AdminAppBootstrapResource.php rename app/Domains/{Forms => Bootstrap}/Resources/SocialMediaOptionResource.php (91%) create mode 100644 app/Domains/Bootstrap/Services/AdminAppBootstrapService.php create mode 100644 app/Domains/Bootstrap/Services/TenantBootstrapService.php create mode 100644 app/Domains/Bootstrap/routes/adminapp.php create mode 100644 app/Domains/Bootstrap/routes/api.php delete mode 100644 app/Domains/Forms/Controllers/AdminApp/EventFormController.php delete mode 100644 app/Domains/Forms/Resources/EventFormResource.php delete mode 100644 app/Domains/Forms/Services/EventFormService.php delete mode 100644 app/Domains/Forms/routes/adminapp.php delete mode 100644 app/Domains/Forms/routes/api.php delete mode 100644 app/Domains/Tenant/Controllers/AdminApp/BootstrapAdminAppController.php delete mode 100644 app/Domains/Tenant/Controllers/BootstrapTenantController.php delete mode 100644 app/Domains/Tenant/Requests/BootstrapAdminAppRequest.php delete mode 100644 app/Domains/Tenant/Resources/AdminApp/BootstrapAdminAppResource.php delete mode 100644 tests/Feature/Forms/AdminAppEventFormControllerTest.php create mode 100644 tests/Unit/Bootstrap/AdminAppBootstrapResourceTest.php delete mode 100644 tests/Unit/Tenant/BootstrapAdminAppResourceTest.php diff --git a/app/Domains/Bootstrap/Controllers/AdminAppBootstrapController.php b/app/Domains/Bootstrap/Controllers/AdminAppBootstrapController.php new file mode 100644 index 0000000..3cc7bef --- /dev/null +++ b/app/Domains/Bootstrap/Controllers/AdminAppBootstrapController.php @@ -0,0 +1,20 @@ +bootstrapService->get((string) $request->validated('dominio')) + ); + } +} diff --git a/app/Domains/Bootstrap/Controllers/TenantBootstrapController.php b/app/Domains/Bootstrap/Controllers/TenantBootstrapController.php new file mode 100644 index 0000000..001bc30 --- /dev/null +++ b/app/Domains/Bootstrap/Controllers/TenantBootstrapController.php @@ -0,0 +1,20 @@ +bootstrapService->get((string) $request->validated('dominio')) + ); + } +} diff --git a/app/Domains/Bootstrap/Requests/AdminAppBootstrapRequest.php b/app/Domains/Bootstrap/Requests/AdminAppBootstrapRequest.php new file mode 100644 index 0000000..282dad9 --- /dev/null +++ b/app/Domains/Bootstrap/Requests/AdminAppBootstrapRequest.php @@ -0,0 +1,5 @@ +hasInvalidDomain = TenantDomainNormalizer::hasValue($rawDomain) && $normalizedDomain === null; - $this->merge([ - 'dominio' => $normalizedDomain, - ]); + $this->merge(['dominio' => $normalizedDomain]); } - /** - * @return array - */ + /** @return array */ public function rules(): array { return [ diff --git a/app/Domains/Bootstrap/Resources/AdminAppBootstrapResource.php b/app/Domains/Bootstrap/Resources/AdminAppBootstrapResource.php new file mode 100644 index 0000000..0fe9dd1 --- /dev/null +++ b/app/Domains/Bootstrap/Resources/AdminAppBootstrapResource.php @@ -0,0 +1,44 @@ + */ + public function toArray(Request $request): array + { + /** @var WebsiteType $websiteType */ + $websiteType = $this->resource['website_type']; + + return [ + 'website_type_code' => $websiteType->codigo, + 'primary_color' => $websiteType->primary_color, + 'secondary_color' => $websiteType->secondary_color, + 'danger_color' => $websiteType->danger_color, + 'success_color' => $websiteType->success_color, + 'warning_color' => $websiteType->warning_color, + 'body_color' => $websiteType->body_color, + 'darker_body_color' => $websiteType->darker_body_color, + 'surface_color' => $websiteType->surface_color, + 'background_color' => $websiteType->background_color, + 'border_color' => $websiteType->border_color, + 'login_header_footer_color' => $websiteType->login_header_footer_color, + 'site_logo' => $websiteType->siteLogo?->getTemporaryUrl(1440), + 'footer_logo' => $websiteType->footerLogo?->getTemporaryUrl(1440), + 'forms' => [ + [ + 'code' => 'event', + 'social_media' => SocialMediaOptionResource::collection( + $this->resource['social_media'] + ), + ], + ], + ]; + } +} diff --git a/app/Domains/Forms/Resources/SocialMediaOptionResource.php b/app/Domains/Bootstrap/Resources/SocialMediaOptionResource.php similarity index 91% rename from app/Domains/Forms/Resources/SocialMediaOptionResource.php rename to app/Domains/Bootstrap/Resources/SocialMediaOptionResource.php index 7dcf582..97f3500 100644 --- a/app/Domains/Forms/Resources/SocialMediaOptionResource.php +++ b/app/Domains/Bootstrap/Resources/SocialMediaOptionResource.php @@ -1,6 +1,6 @@ } */ + public function get(string $domain): array + { + return [ + 'website_type' => WebsiteType::query() + ->with(['siteLogo', 'footerLogo']) + ->where('dominio', $domain) + ->firstOrFail(), + 'social_media' => SocialMedia::query()->orderBy('id')->get(), + ]; + } +} diff --git a/app/Domains/Bootstrap/Services/TenantBootstrapService.php b/app/Domains/Bootstrap/Services/TenantBootstrapService.php new file mode 100644 index 0000000..8dd6862 --- /dev/null +++ b/app/Domains/Bootstrap/Services/TenantBootstrapService.php @@ -0,0 +1,26 @@ +tenantInformationService->load( + Tenant::query()->where('dominio', $domain)->firstOrFail(), + [ + 'menues' => fn ($query) => $query->whereHas( + 'roles', + fn ($query) => $query->where('codigo', RoleCode::User->value) + ), + 'categories' => fn ($query) => $query->orderBy('nombre'), + ] + ); + } +} diff --git a/app/Domains/Bootstrap/routes/adminapp.php b/app/Domains/Bootstrap/routes/adminapp.php new file mode 100644 index 0000000..3cf6c66 --- /dev/null +++ b/app/Domains/Bootstrap/routes/adminapp.php @@ -0,0 +1,9 @@ +where('dominio', '.*'); + +require __DIR__.'/adminapp.php'; diff --git a/app/Domains/Forms/Controllers/AdminApp/EventFormController.php b/app/Domains/Forms/Controllers/AdminApp/EventFormController.php deleted file mode 100644 index ad4d7a9..0000000 --- a/app/Domains/Forms/Controllers/AdminApp/EventFormController.php +++ /dev/null @@ -1,19 +0,0 @@ -eventFormService->get() - ); - } -} diff --git a/app/Domains/Forms/Resources/EventFormResource.php b/app/Domains/Forms/Resources/EventFormResource.php deleted file mode 100644 index 0cfd51d..0000000 --- a/app/Domains/Forms/Resources/EventFormResource.php +++ /dev/null @@ -1,19 +0,0 @@ - */ - public function toArray(Request $request): array - { - return [ - 'social_media' => SocialMediaOptionResource::collection( - $this->resource['social_media'] - ), - ]; - } -} diff --git a/app/Domains/Forms/Services/EventFormService.php b/app/Domains/Forms/Services/EventFormService.php deleted file mode 100644 index fe7ee65..0000000 --- a/app/Domains/Forms/Services/EventFormService.php +++ /dev/null @@ -1,17 +0,0 @@ -} */ - public function get(): array - { - return [ - 'social_media' => SocialMedia::query()->orderBy('id')->get(), - ]; - } -} diff --git a/app/Domains/Forms/routes/adminapp.php b/app/Domains/Forms/routes/adminapp.php deleted file mode 100644 index da1e7e9..0000000 --- a/app/Domains/Forms/routes/adminapp.php +++ /dev/null @@ -1,10 +0,0 @@ -middleware(['auth:sanctum', 'adminapp.tenant']) - ->group(function (): void { - Route::get('event', EventFormController::class); - }); diff --git a/app/Domains/Forms/routes/api.php b/app/Domains/Forms/routes/api.php deleted file mode 100644 index 062e0fe..0000000 --- a/app/Domains/Forms/routes/api.php +++ /dev/null @@ -1,3 +0,0 @@ -validated('dominio'); - - return BootstrapAdminAppResource::make( - WebsiteType::query() - ->with(['siteLogo', 'footerLogo']) - ->where('dominio', $domain) - ->firstOrFail() - ); - } -} diff --git a/app/Domains/Tenant/Controllers/BootstrapTenantController.php b/app/Domains/Tenant/Controllers/BootstrapTenantController.php deleted file mode 100644 index 53bfb0e..0000000 --- a/app/Domains/Tenant/Controllers/BootstrapTenantController.php +++ /dev/null @@ -1,38 +0,0 @@ -validated('dominio'); - - return TenantResource::make( - $this->tenantInformationService->load( - Tenant::query() - ->where('dominio', $dominio) - ->firstOrFail(), - [ - 'menues' => fn ($query) => $query->whereHas( - 'roles', - fn ($query) => $query->where('codigo', RoleCode::User->value) - ), - 'categories' => fn ($query) => $query->orderBy('nombre'), - ] - ) - ); - } -} diff --git a/app/Domains/Tenant/Requests/BootstrapAdminAppRequest.php b/app/Domains/Tenant/Requests/BootstrapAdminAppRequest.php deleted file mode 100644 index c07bf9f..0000000 --- a/app/Domains/Tenant/Requests/BootstrapAdminAppRequest.php +++ /dev/null @@ -1,5 +0,0 @@ - - */ - public function toArray(Request $request): array - { - return [ - 'website_type_code' => $this->codigo, - 'primary_color' => $this->primary_color, - 'secondary_color' => $this->secondary_color, - 'danger_color' => $this->danger_color, - 'success_color' => $this->success_color, - 'warning_color' => $this->warning_color, - 'body_color' => $this->body_color, - 'darker_body_color' => $this->darker_body_color, - 'surface_color' => $this->surface_color, - 'background_color' => $this->background_color, - 'border_color' => $this->border_color, - 'login_header_footer_color' => $this->login_header_footer_color, - 'site_logo' => $this->siteLogo?->getTemporaryUrl(1440), - 'footer_logo' => $this->footerLogo?->getTemporaryUrl(1440), - ]; - } -} diff --git a/app/Domains/Tenant/routes/adminapp.php b/app/Domains/Tenant/routes/adminapp.php index 01396ba..0dcc615 100644 --- a/app/Domains/Tenant/routes/adminapp.php +++ b/app/Domains/Tenant/routes/adminapp.php @@ -1,14 +1,8 @@ middleware(['auth:sanctum', 'adminapp.tenant']) ->group(function (): void { diff --git a/app/Domains/Tenant/routes/api.php b/app/Domains/Tenant/routes/api.php index cc12f08..1deb043 100644 --- a/app/Domains/Tenant/routes/api.php +++ b/app/Domains/Tenant/routes/api.php @@ -1,12 +1,8 @@ where('dominio', '.*'); - Route::apiResource('tenants', TenantController::class); require __DIR__.'/adminapp.php'; diff --git a/routes/api.php b/routes/api.php index 15af2fd..8abcbcc 100644 --- a/routes/api.php +++ b/routes/api.php @@ -11,4 +11,4 @@ require __DIR__.'/../app/Domains/Integration/routes/api.php'; require __DIR__.'/../app/Domains/Menu/routes/api.php'; require __DIR__.'/../app/Domains/Ticket/routes/api.php'; require __DIR__.'/../app/Domains/Event/routes/api.php'; -require __DIR__.'/../app/Domains/Forms/routes/api.php'; +require __DIR__.'/../app/Domains/Bootstrap/routes/api.php'; diff --git a/tests/Feature/Forms/AdminAppEventFormControllerTest.php b/tests/Feature/Forms/AdminAppEventFormControllerTest.php deleted file mode 100644 index a7d469e..0000000 --- a/tests/Feature/Forms/AdminAppEventFormControllerTest.php +++ /dev/null @@ -1,66 +0,0 @@ -seed([AuthorizationSeeder::class, SocialMediaSeeder::class]); - WebsiteType::query()->create([ - 'codigo' => 'onticket', - 'nombre' => 'OnTicket', - ]); - } - - public function test_authentication_is_required(): void - { - $this->getJson('/api/v1/adminapp/forms/event')->assertUnauthorized(); - } - - public function test_an_adminapp_user_can_get_the_event_form(): void - { - $tenant = Tenant::query()->create([ - 'codigo' => 'acme', - 'nombre' => 'Acme', - 'dominio' => 'acme.test', - 'website_type_code' => 'onticket', - ]); - Sanctum::actingAs(User::factory()->create([ - 'rol_codigo' => RoleCode::AdminApp->value, - 'tenant_codigo' => $tenant->codigo, - ])); - - $this->getJson('/api/v1/adminapp/forms/event') - ->assertOk() - ->assertJsonCount(4, 'data.social_media') - ->assertJsonPath('data.social_media.0.code', 'facebook') - ->assertJsonPath('data.social_media.0.name', 'Facebook') - ->assertJsonPath('data.social_media.0.icon', 'fa-brands fa-facebook') - ->assertJsonPath('data.social_media.3.code', 'linkedin'); - } - - public function test_a_customer_cannot_get_the_event_form(): void - { - Sanctum::actingAs(User::factory()->create([ - 'rol_codigo' => RoleCode::User->value, - 'tenant_codigo' => null, - ])); - - $this->getJson('/api/v1/adminapp/forms/event')->assertForbidden(); - } -} diff --git a/tests/Feature/Tenant/BootstrapAdminAppControllerTest.php b/tests/Feature/Tenant/BootstrapAdminAppControllerTest.php index ba4e20b..c43dd0b 100644 --- a/tests/Feature/Tenant/BootstrapAdminAppControllerTest.php +++ b/tests/Feature/Tenant/BootstrapAdminAppControllerTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Tenant; use App\Domains\Attachable\Models\Attachment; use App\Domains\Tenant\Models\WebsiteType; +use Database\Seeders\SocialMediaSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -13,6 +14,7 @@ class BootstrapAdminAppControllerTest extends TestCase public function test_it_publicly_bootstraps_the_admin_app_by_domain(): void { + $this->seed(SocialMediaSeeder::class); $footerLogo = Attachment::factory()->create(); WebsiteType::query()->create([ @@ -41,6 +43,10 @@ class BootstrapAdminAppControllerTest extends TestCase ->assertJsonPath('data.login_header_footer_color', '#313131') ->assertJsonPath('data.site_logo', null) ->assertJsonPath('data.footer_logo', $footerLogo->getTemporaryUrl(1440)) + ->assertJsonPath('data.forms.0.code', 'event') + ->assertJsonCount(4, 'data.forms.0.social_media') + ->assertJsonPath('data.forms.0.social_media.0.code', 'facebook') + ->assertJsonPath('data.forms.0.social_media.3.code', 'linkedin') ->assertJsonMissingPath('data.codigo') ->assertJsonMissingPath('data.nombre') ->assertJsonMissingPath('data.dominio'); diff --git a/tests/Unit/Bootstrap/AdminAppBootstrapResourceTest.php b/tests/Unit/Bootstrap/AdminAppBootstrapResourceTest.php new file mode 100644 index 0000000..9d2a846 --- /dev/null +++ b/tests/Unit/Bootstrap/AdminAppBootstrapResourceTest.php @@ -0,0 +1,40 @@ + 'shopit', + 'nombre' => 'ShopIt', + 'dominio' => 'admin.shopit.test', + ]); + $websiteType->setRelation('siteLogo', null); + $websiteType->setRelation('footerLogo', null); + $socialMedia = new SocialMedia([ + 'code' => 'instagram', + 'name' => 'Instagram', + 'icon' => 'fa-brands fa-instagram', + ]); + + $data = AdminAppBootstrapResource::make([ + 'website_type' => $websiteType, + 'social_media' => new Collection([$socialMedia]), + ])->resolve(request()); + + $this->assertSame('shopit', $data['website_type_code']); + $this->assertSame('event', $data['forms'][0]['code']); + $this->assertSame( + 'instagram', + $data['forms'][0]['social_media']->resolve(request())[0]['code'] + ); + } +} diff --git a/tests/Unit/Tenant/BootstrapAdminAppResourceTest.php b/tests/Unit/Tenant/BootstrapAdminAppResourceTest.php deleted file mode 100644 index f9dfdb6..0000000 --- a/tests/Unit/Tenant/BootstrapAdminAppResourceTest.php +++ /dev/null @@ -1,25 +0,0 @@ - 'shopit', - 'nombre' => 'ShopIt', - 'dominio' => 'admin.shopit.test', - ]); - $websiteType->setRelation('siteLogo', null); - - $data = BootstrapAdminAppResource::make($websiteType)->resolve(request()); - - $this->assertSame('shopit', $data['codigo']); - $this->assertSame('shopit', $data['website_type_code']); - } -}