adrema/app/Initialize/Actions/NamiSearchAction.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2023-05-07 21:15:17 +02:00
<?php
namespace App\Initialize\Actions;
2023-05-08 15:11:16 +02:00
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
2023-05-07 21:15:17 +02:00
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
use Zoomyboy\LaravelNami\Api;
2023-05-08 15:11:16 +02:00
use Zoomyboy\LaravelNami\Data\MemberEntry;
2023-05-07 21:15:17 +02:00
use Zoomyboy\LaravelNami\Nami;
class NamiSearchAction
{
use AsAction;
2023-05-08 15:11:16 +02:00
/**
* @param array<string, mixed> $params
*
* @return LengthAwarePaginator<MemberEntry>
*/
public function handle(Api $api, int $page, array $params): LengthAwarePaginator
2023-05-07 21:15:17 +02:00
{
2023-05-08 15:11:16 +02:00
return $api->pageSearch($params, $page, 10);
2023-05-07 21:15:17 +02:00
}
2023-05-08 15:11:16 +02:00
/**
* @return array<string, string>
*/
2023-05-07 21:15:17 +02:00
public function rules(): array
{
return [
'mglnr' => 'required|numeric|min:0',
'password' => 'required|string',
'params' => 'array',
];
}
2023-05-08 15:11:16 +02:00
/**
* @return LengthAwarePaginator<MemberEntry>
*/
public function asController(ActionRequest $request): LengthAwarePaginator
2023-05-07 21:15:17 +02:00
{
$api = Nami::login($request->input('mglnr'), $request->input('password'));
2023-05-08 15:11:16 +02:00
return $this->handle($api, $request->input('page', 1), $request->input('params'));
2023-05-07 21:15:17 +02:00
}
}