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;
|
||||
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin array{website_type: WebsiteType, social_media: Collection} */
|
||||
/** @mixin array{website_type: WebsiteType} */
|
||||
class AdminAppBootstrapResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
@@ -31,14 +30,6 @@ class AdminAppBootstrapResource extends JsonResource
|
||||
'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']
|
||||
),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
namespace App\Domains\Bootstrap\Services;
|
||||
|
||||
use App\Domains\Tenant\Models\SocialMedia;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class AdminAppBootstrapService
|
||||
{
|
||||
/** @return array{website_type: WebsiteType, social_media: Collection<int, SocialMedia>} */
|
||||
/** @return array{website_type: WebsiteType} */
|
||||
public function get(string $domain): array
|
||||
{
|
||||
return [
|
||||
@@ -16,7 +14,6 @@ class AdminAppBootstrapService
|
||||
->with(['siteLogo', 'footerLogo'])
|
||||
->where('dominio', $domain)
|
||||
->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
|
||||
|
||||
namespace App\Domains\Bootstrap\Resources;
|
||||
namespace App\Domains\Forms\Resources;
|
||||
|
||||
use App\Domains\Tenant\Models\SocialMedia;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -16,6 +16,7 @@ class SocialMediaOptionResource extends JsonResource
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'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';
|
||||
Reference in New Issue
Block a user