Skip to content

Commit

Permalink
Merge pull request #17 from WendellAdriel/dto-as-request
Browse files Browse the repository at this point in the history
Update to use DTOs directly as request
  • Loading branch information
WendellAdriel authored Apr 29, 2024
2 parents b6c7941 + 683ae8d commit 89a8d32
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
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

0 comments on commit 89a8d32

Please sign in to comment.