2026-06-23 10:10:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Modules\Client\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Modules\Client\Actions\CreateClientAction;
|
|
|
|
|
use App\Modules\Client\Actions\GetClientAction;
|
|
|
|
|
use App\Modules\Client\Actions\UpdateClientAction;
|
|
|
|
|
use App\Modules\Client\DTOs\ClientData;
|
|
|
|
|
use App\Modules\Client\Models\Client;
|
|
|
|
|
use App\Modules\Client\Requests\CreateClientRequest;
|
|
|
|
|
use App\Modules\Client\Requests\UpdateClientRequest;
|
|
|
|
|
use App\Modules\Client\Resources\ClientResource;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
|
|
|
|
|
|
|
|
class ClientController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(GetClientAction $action): AnonymousResourceCollection
|
|
|
|
|
{
|
|
|
|
|
$this->authorize('viewAny', Client::class);
|
|
|
|
|
return ClientResource::collection($action->list());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(CreateClientRequest $request, CreateClientAction $action): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$this->authorize('create', Client::class);
|
|
|
|
|
$client = $action->handle(ClientData::fromCreateRequest($request));
|
|
|
|
|
return ClientResource::make($client)->response()->setStatusCode(201);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(int $id, GetClientAction $action): ClientResource
|
|
|
|
|
{
|
|
|
|
|
$client = $action->find($id);
|
|
|
|
|
$this->authorize('view', $client);
|
|
|
|
|
return ClientResource::make($client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(UpdateClientRequest $request, Client $client, UpdateClientAction $action): ClientResource
|
|
|
|
|
{
|
|
|
|
|
$this->authorize('update', $client);
|
|
|
|
|
$updated = $action->handle($client, ClientData::fromUpdateRequest($request));
|
|
|
|
|
return ClientResource::make($updated);
|
|
|
|
|
}
|
2026-07-18 09:34:18 +00:00
|
|
|
|
|
|
|
|
public function destroy(Client $client): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$this->authorize('delete', $client);
|
|
|
|
|
$client->delete();
|
|
|
|
|
return response()->json(null, 204);
|
|
|
|
|
}
|
2026-06-23 10:10:28 +00:00
|
|
|
}
|