diff --git a/app/Domains/Tenant/Controllers/AdminApp/WebsiteExtraController.php b/app/Domains/Tenant/Controllers/AdminApp/WebsiteExtraController.php index 835329b..083e725 100644 --- a/app/Domains/Tenant/Controllers/AdminApp/WebsiteExtraController.php +++ b/app/Domains/Tenant/Controllers/AdminApp/WebsiteExtraController.php @@ -5,7 +5,6 @@ namespace App\Domains\Tenant\Controllers\AdminApp; use App\Domains\Auth\Models\User; use App\Domains\Tenant\Models\Tenant; use App\Domains\Tenant\Requests\AdminApp\UpdateWebsiteExtraRequest; -use App\Domains\Tenant\Resources\AdminApp\WebsiteExtraResource; use App\Domains\Tenant\Resources\AdminApp\WebsiteExtrasResource; use App\Domains\Tenant\Services\TenantInformationService; use App\Domains\Tenant\Services\WebsiteExtraService; @@ -26,20 +25,6 @@ class WebsiteExtraController extends Controller ); } - public function showExtra(Request $request, string $websiteExtraCode): WebsiteExtraResource - { - $tenant = $this->loadTenant($request->user()); - $definition = $this->websiteExtraService->definitionForTenant($tenant, $websiteExtraCode); - $websiteExtra = $tenant->websiteExtras - ->firstWhere('website_type_extra_id', $definition->id); - - if (! $websiteExtra) { - abort(404); - } - - return WebsiteExtraResource::make($websiteExtra); - } - public function update( UpdateWebsiteExtraRequest $request, string $websiteExtraCode diff --git a/app/Domains/Tenant/Resources/AdminApp/WebsiteExtraResource.php b/app/Domains/Tenant/Resources/AdminApp/WebsiteExtraResource.php deleted file mode 100644 index 49222a9..0000000 --- a/app/Domains/Tenant/Resources/AdminApp/WebsiteExtraResource.php +++ /dev/null @@ -1,86 +0,0 @@ - - */ - public function toArray(Request $request): array - { - return [ - 'codigo' => $this->websiteTypeExtra->codigo, - 'nombre' => $this->websiteTypeExtra->nombre, - 'descripcion' => $this->websiteTypeExtra->descripcion, - 'is_required' => $this->websiteTypeExtra->is_required, - 'is_enabled' => $this->is_enabled, - 'request_rules' => $this->websiteTypeExtra->config_schema['request_rules'] ?? [], - 'config' => $this->formatConfig( - $this->resolvedConfig(), - fn (Attachment $attachment): string => $attachment->key - ), - 'resolved_config' => $this->formatConfig( - $this->resolvedAdminConfig(), - fn (Attachment $attachment): string => $attachment->getTemporaryUrl(1440) - ), - ]; - } - - private function resolvedAdminConfig(): mixed - { - $config = $this->resolvedConfig(); - - if ( - $this->websiteTypeExtra->codigo !== 'heroConfig' - || ! is_array($config) - || ! ($config['background_image_id'] ?? null) instanceof Attachment - ) { - return $config; - } - - $attachment = $config['background_image_id']; - $fullRange = ['start_percentage' => 0.0, 'end_percentage' => 100.0]; - $crops = $attachment->cropVariants->keyBy('variant'); - $config['background_image_id'] = [ - 'url' => $attachment->getTemporaryUrl(1440), - 'crops' => collect(AttachmentCrop::VARIANTS)->mapWithKeys( - function (string $variant) use ($crops, $fullRange): array { - $crop = $crops->get($variant); - - return [$variant => [ - 'crop_horizontal' => $crop?->crop_horizontal ?? $fullRange, - 'crop_vertical' => $crop?->crop_vertical ?? $fullRange, - ]]; - } - )->all(), - ]; - - return $config; - } - - private function formatConfig(mixed $value, callable $formatAttachment): mixed - { - if ($value instanceof Attachment) { - return $formatAttachment($value); - } - - if (! is_array($value)) { - return $value; - } - - return array_map( - fn (mixed $item): mixed => $this->formatConfig($item, $formatAttachment), - $value - ); - } -} diff --git a/app/Domains/Tenant/routes/adminapp.php b/app/Domains/Tenant/routes/adminapp.php index 0dcc615..1e59054 100644 --- a/app/Domains/Tenant/routes/adminapp.php +++ b/app/Domains/Tenant/routes/adminapp.php @@ -7,7 +7,6 @@ Route::prefix('v1/adminapp/tenant') ->middleware(['auth:sanctum', 'adminapp.tenant']) ->group(function (): void { Route::get('website-extras', [WebsiteExtraController::class, 'show']); - Route::get('website-extras/{websiteExtraCode}', [WebsiteExtraController::class, 'showExtra']); Route::put('website-extras/{websiteExtraCode}', [WebsiteExtraController::class, 'update']); Route::patch('website-extras/{websiteExtraCode}/toggle', [WebsiteExtraController::class, 'toggle']); }); diff --git a/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php b/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php index 2cb8b83..6d97045 100644 --- a/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php +++ b/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php @@ -88,36 +88,6 @@ class AdminAppWebsiteExtraControllerTest extends TestCase ->assertJsonPath('data.resolved_extras.contactConfig.phone', '+54 341 555 0101'); } - public function test_adminapp_user_can_read_one_website_extra(): void - { - $tenant = $this->createTenant('acme'); - $definition = $this->websiteType->extras()->firstOrFail(); - $tenant->websiteExtras()->create([ - 'website_type_extra_id' => $definition->id, - 'config' => ['phone' => '+54 341 555 0101'], - 'is_enabled' => true, - ]); - - Sanctum::actingAs($this->createAdminAppUser($tenant)); - - $this->getJson('/api/v1/adminapp/tenant/website-extras/contactConfig') - ->assertOk() - ->assertJsonPath('data.codigo', 'contactConfig') - ->assertJsonPath('data.nombre', 'Configuración de contacto') - ->assertJsonPath('data.is_enabled', true) - ->assertJsonPath('data.config.phone', '+54 341 555 0101') - ->assertJsonPath('data.resolved_config.phone', '+54 341 555 0101'); - } - - public function test_reading_an_unconfigured_website_extra_returns_not_found(): void - { - $tenant = $this->createTenant('acme'); - Sanctum::actingAs($this->createAdminAppUser($tenant)); - - $this->getJson('/api/v1/adminapp/tenant/website-extras/contactConfig') - ->assertNotFound(); - } - public function test_adminapp_user_updates_one_extra_without_touching_other_tenants(): void { $tenant = $this->createTenant('acme');