Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use DTOs directly as request #17

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions modules/Auth/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Http\Controllers\Controller;
use Exa\Http\Responses\ApiSuccessResponse;
use Exa\Http\Responses\NoContentResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Modules\Auth\Actions\Login;
use Modules\Auth\DTOs\LoginDTO;
Expand Down Expand Up @@ -38,11 +37,9 @@ final class AuthController extends Controller
#[OA\Response(response: '403', description: 'Forbidden')]
#[OA\Response(response: '422', description: 'Invalid Data')]
#[OA\Response(response: '500', description: 'Server Error')]
public function login(Request $request, Login $action): ApiSuccessResponse
public function login(LoginDTO $dto, Login $action): ApiSuccessResponse
{
return new ApiSuccessResponse(
new LoginResource($action->handle(LoginDTO::fromRequest($request)))
);
return new ApiSuccessResponse(new LoginResource($action->handle($dto)));
}

#[OA\Post(
Expand Down
15 changes: 6 additions & 9 deletions modules/Auth/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Exa\Http\Responses\ApiSuccessResponse;
use Exa\Http\Responses\NoContentResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Auth\Actions\CreateUser;
use Modules\Auth\Actions\DeleteUser;
Expand Down Expand Up @@ -48,9 +47,9 @@ final class UserController extends Controller
#[OA\Response(response: '401', description: 'Unauthorized')]
#[OA\Response(response: '403', description: 'Forbidden')]
#[OA\Response(response: '500', description: 'Server Error')]
public function index(Request $request, FetchUsersList $action): JsonResponse
public function index(DatatableDTO $dto, FetchUsersList $action): JsonResponse
{
return UserResource::collection($action->handle(DatatableDTO::fromRequest($request)))->response();
return UserResource::collection($action->handle($dto))->response();
}

#[OA\Get(
Expand Down Expand Up @@ -98,10 +97,10 @@ public function show(string $uuid, FetchUser $action): ApiSuccessResponse
#[OA\Response(response: '403', description: 'Forbidden')]
#[OA\Response(response: '422', description: 'Invalid Data')]
#[OA\Response(response: '500', description: 'Server Error')]
public function store(Request $request, CreateUser $action): ApiSuccessResponse
public function store(CreateUserDTO $dto, CreateUser $action): ApiSuccessResponse
{
return new ApiSuccessResponse(
new UserResource($action->handle(CreateUserDTO::fromRequest($request))),
new UserResource($action->handle($dto)),
Response::HTTP_CREATED
);
}
Expand Down Expand Up @@ -131,11 +130,9 @@ public function store(Request $request, CreateUser $action): ApiSuccessResponse
#[OA\Response(response: '404', description: 'Not Found')]
#[OA\Response(response: '422', description: 'Invalid Data')]
#[OA\Response(response: '500', description: 'Server Error')]
public function update(Request $request, string $uuid, UpdateUser $action): ApiSuccessResponse
public function update(UpdateUserDTO $dto, string $uuid, UpdateUser $action): ApiSuccessResponse
{
return new ApiSuccessResponse(
new UserResource($action->handle($uuid, UpdateUserDTO::fromRequest($request)))
);
return new ApiSuccessResponse(new UserResource($action->handle($uuid, $dto)));
}

#[OA\Delete(
Expand Down