feat: Refactor event form functionality by removing social media data from AdminAppBootstrapResource and AdminAppBootstrapService; add EventFormController, EventFormResource, and EventFormService; implement routes and tests for event form
This commit is contained in:
@@ -3,11 +3,10 @@
|
|||||||
namespace App\Domains\Bootstrap\Resources;
|
namespace App\Domains\Bootstrap\Resources;
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
/** @mixin array{website_type: WebsiteType, social_media: Collection} */
|
/** @mixin array{website_type: WebsiteType} */
|
||||||
class AdminAppBootstrapResource extends JsonResource
|
class AdminAppBootstrapResource extends JsonResource
|
||||||
{
|
{
|
||||||
/** @return array<string, mixed> */
|
/** @return array<string, mixed> */
|
||||||
@@ -31,14 +30,6 @@ class AdminAppBootstrapResource extends JsonResource
|
|||||||
'login_header_footer_color' => $websiteType->login_header_footer_color,
|
'login_header_footer_color' => $websiteType->login_header_footer_color,
|
||||||
'site_logo' => $websiteType->siteLogo?->getTemporaryUrl(1440),
|
'site_logo' => $websiteType->siteLogo?->getTemporaryUrl(1440),
|
||||||
'footer_logo' => $websiteType->footerLogo?->getTemporaryUrl(1440),
|
'footer_logo' => $websiteType->footerLogo?->getTemporaryUrl(1440),
|
||||||
'forms' => [
|
|
||||||
[
|
|
||||||
'code' => 'event',
|
|
||||||
'social_media' => SocialMediaOptionResource::collection(
|
|
||||||
$this->resource['social_media']
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Domains\Bootstrap\Services;
|
namespace App\Domains\Bootstrap\Services;
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\SocialMedia;
|
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
|
|
||||||
class AdminAppBootstrapService
|
class AdminAppBootstrapService
|
||||||
{
|
{
|
||||||
/** @return array{website_type: WebsiteType, social_media: Collection<int, SocialMedia>} */
|
/** @return array{website_type: WebsiteType} */
|
||||||
public function get(string $domain): array
|
public function get(string $domain): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@@ -16,7 +14,6 @@ class AdminAppBootstrapService
|
|||||||
->with(['siteLogo', 'footerLogo'])
|
->with(['siteLogo', 'footerLogo'])
|
||||||
->where('dominio', $domain)
|
->where('dominio', $domain)
|
||||||
->firstOrFail(),
|
->firstOrFail(),
|
||||||
'social_media' => SocialMedia::query()->orderBy('id')->get(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Forms\Resources\EventFormResource;
|
||||||
|
use App\Domains\Forms\Services\EventFormService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class EventFormController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(protected EventFormService $eventFormService) {}
|
||||||
|
|
||||||
|
public function __invoke(Request $request): EventFormResource
|
||||||
|
{
|
||||||
|
return EventFormResource::make(
|
||||||
|
$this->eventFormService->get(
|
||||||
|
$request->user('sanctum')->tenant()->firstOrFail()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Domains/Forms/Resources/EventFormResource.php
Normal file
19
app/Domains/Forms/Resources/EventFormResource.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class EventFormResource extends JsonResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'social_media' => SocialMediaOptionResource::collection(
|
||||||
|
$this->resource['social_media']
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Domains\Bootstrap\Resources;
|
namespace App\Domains\Forms\Resources;
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\SocialMedia;
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -16,6 +16,7 @@ class SocialMediaOptionResource extends JsonResource
|
|||||||
'code' => $this->code,
|
'code' => $this->code,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'icon' => $this->icon,
|
'icon' => $this->icon,
|
||||||
|
'url' => $this->url,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
27
app/Domains/Forms/Services/EventFormService.php
Normal file
27
app/Domains/Forms/Services/EventFormService.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Services;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
|
class EventFormService
|
||||||
|
{
|
||||||
|
/** @return array{social_media: Collection<int, SocialMedia>} */
|
||||||
|
public function get(Tenant $tenant): array
|
||||||
|
{
|
||||||
|
$urls = $tenant->socialMedia()
|
||||||
|
->pluck('tenant_social_media.url', 'social_media.code');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'social_media' => SocialMedia::query()
|
||||||
|
->orderBy('id')
|
||||||
|
->get()
|
||||||
|
->each(fn (SocialMedia $item) => $item->setAttribute(
|
||||||
|
'url',
|
||||||
|
$urls->get($item->code)
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
10
app/Domains/Forms/routes/adminapp.php
Normal file
10
app/Domains/Forms/routes/adminapp.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Forms\Controllers\AdminApp\EventFormController;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::prefix('v1/adminapp/forms')
|
||||||
|
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||||
|
->group(function (): void {
|
||||||
|
Route::get('event', EventFormController::class);
|
||||||
|
});
|
||||||
3
app/Domains/Forms/routes/api.php
Normal file
3
app/Domains/Forms/routes/api.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require __DIR__.'/adminapp.php';
|
||||||
@@ -12,3 +12,4 @@ require __DIR__.'/../app/Domains/Menu/routes/api.php';
|
|||||||
require __DIR__.'/../app/Domains/Ticket/routes/api.php';
|
require __DIR__.'/../app/Domains/Ticket/routes/api.php';
|
||||||
require __DIR__.'/../app/Domains/Event/routes/api.php';
|
require __DIR__.'/../app/Domains/Event/routes/api.php';
|
||||||
require __DIR__.'/../app/Domains/Bootstrap/routes/api.php';
|
require __DIR__.'/../app/Domains/Bootstrap/routes/api.php';
|
||||||
|
require __DIR__.'/../app/Domains/Forms/routes/api.php';
|
||||||
|
|||||||
73
tests/Feature/Forms/AdminAppEventFormControllerTest.php
Normal file
73
tests/Feature/Forms/AdminAppEventFormControllerTest.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Forms;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Database\Seeders\SocialMediaSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminAppEventFormControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->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',
|
||||||
|
]);
|
||||||
|
$tenant->socialMedia()->attach('instagram', [
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
'orden' => 1,
|
||||||
|
]);
|
||||||
|
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.0.url', null)
|
||||||
|
->assertJsonPath('data.social_media.1.code', 'instagram')
|
||||||
|
->assertJsonPath('data.social_media.1.url', 'https://instagram.com/acme')
|
||||||
|
->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ namespace Tests\Feature\Tenant;
|
|||||||
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
use Database\Seeders\SocialMediaSeeder;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -14,7 +13,6 @@ class BootstrapAdminAppControllerTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_publicly_bootstraps_the_admin_app_by_domain(): void
|
public function test_it_publicly_bootstraps_the_admin_app_by_domain(): void
|
||||||
{
|
{
|
||||||
$this->seed(SocialMediaSeeder::class);
|
|
||||||
$footerLogo = Attachment::factory()->create();
|
$footerLogo = Attachment::factory()->create();
|
||||||
|
|
||||||
WebsiteType::query()->create([
|
WebsiteType::query()->create([
|
||||||
@@ -43,10 +41,7 @@ class BootstrapAdminAppControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.login_header_footer_color', '#313131')
|
->assertJsonPath('data.login_header_footer_color', '#313131')
|
||||||
->assertJsonPath('data.site_logo', null)
|
->assertJsonPath('data.site_logo', null)
|
||||||
->assertJsonPath('data.footer_logo', $footerLogo->getTemporaryUrl(1440))
|
->assertJsonPath('data.footer_logo', $footerLogo->getTemporaryUrl(1440))
|
||||||
->assertJsonPath('data.forms.0.code', 'event')
|
->assertJsonMissingPath('data.forms')
|
||||||
->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.codigo')
|
||||||
->assertJsonMissingPath('data.nombre')
|
->assertJsonMissingPath('data.nombre')
|
||||||
->assertJsonMissingPath('data.dominio');
|
->assertJsonMissingPath('data.dominio');
|
||||||
|
|||||||
@@ -3,14 +3,12 @@
|
|||||||
namespace Tests\Unit\Bootstrap;
|
namespace Tests\Unit\Bootstrap;
|
||||||
|
|
||||||
use App\Domains\Bootstrap\Resources\AdminAppBootstrapResource;
|
use App\Domains\Bootstrap\Resources\AdminAppBootstrapResource;
|
||||||
use App\Domains\Tenant\Models\SocialMedia;
|
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AdminAppBootstrapResourceTest extends TestCase
|
class AdminAppBootstrapResourceTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test_it_exposes_the_website_type_and_forms(): void
|
public function test_it_exposes_the_website_type(): void
|
||||||
{
|
{
|
||||||
$websiteType = new WebsiteType([
|
$websiteType = new WebsiteType([
|
||||||
'codigo' => 'shopit',
|
'codigo' => 'shopit',
|
||||||
@@ -19,22 +17,11 @@ class AdminAppBootstrapResourceTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$websiteType->setRelation('siteLogo', null);
|
$websiteType->setRelation('siteLogo', null);
|
||||||
$websiteType->setRelation('footerLogo', null);
|
$websiteType->setRelation('footerLogo', null);
|
||||||
$socialMedia = new SocialMedia([
|
|
||||||
'code' => 'instagram',
|
|
||||||
'name' => 'Instagram',
|
|
||||||
'icon' => 'fa-brands fa-instagram',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$data = AdminAppBootstrapResource::make([
|
$data = AdminAppBootstrapResource::make([
|
||||||
'website_type' => $websiteType,
|
'website_type' => $websiteType,
|
||||||
'social_media' => new Collection([$socialMedia]),
|
|
||||||
])->resolve(request());
|
])->resolve(request());
|
||||||
|
|
||||||
$this->assertSame('shopit', $data['website_type_code']);
|
$this->assertSame('shopit', $data['website_type_code']);
|
||||||
$this->assertSame('event', $data['forms'][0]['code']);
|
$this->assertArrayNotHasKey('forms', $data);
|
||||||
$this->assertSame(
|
|
||||||
'instagram',
|
|
||||||
$data['forms'][0]['social_media']->resolve(request())[0]['code']
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user