Skeleton is ready
This commit is contained in:
23
app/Feature/Example/Http/Controller/User.php
Normal file
23
app/Feature/Example/Http/Controller/User.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Feature\Example\Http\Controller;
|
||||
|
||||
use App\Feature\Example\Dto\SearchUsers;
|
||||
use App\Feature\Example\Http\Request\Index;
|
||||
use App\Feature\Example\Http\Resource\Users;
|
||||
use App\Feature\Example\Service\UsersRepository;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct(
|
||||
private UsersRepository $users,
|
||||
) {}
|
||||
|
||||
public function index(Index $request): Users
|
||||
{
|
||||
$dto = SearchUsers::fromArray($request->validated());
|
||||
return Users::make($this->users->search($dto));
|
||||
}
|
||||
}
|
||||
22
app/Feature/Example/Http/Request/Index.php
Normal file
22
app/Feature/Example/Http/Request/Index.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Feature\Example\Http\Request;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @property int|null $page
|
||||
* @property int|null $per_page
|
||||
*/
|
||||
class Index extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'page' => ['sometimes', 'integer', 'min:1'],
|
||||
'per_page' => ['sometimes', 'integer', 'min:1', 'max:200'],
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/Feature/Example/Http/Resource/User.php
Normal file
24
app/Feature/Example/Http/Resource/User.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Feature\Example\Http\Resource;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @property \App\Models\User\User $resource
|
||||
*/
|
||||
class User extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->resource->getKey(),
|
||||
'login' => $this->resource->login,
|
||||
'created_at' => $this->resource->created_at,
|
||||
'updated_at' => $this->resource->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Feature/Example/Http/Resource/Users.php
Normal file
21
app/Feature/Example/Http/Resource/Users.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Feature\Example\Http\Resource;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
/**
|
||||
* @property \Illuminate\Pagination\LengthAwarePaginator<\App\Models\User\User> $collection
|
||||
*/
|
||||
class Users extends ResourceCollection
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'data' => User::collection($this->collection)
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user