adrema/app/Remote/Actions/SearchAction.php

31 lines
987 B
PHP
Raw Normal View History

2024-02-22 00:40:19 +01:00
<?php
namespace App\Remote\Actions;
use App\Initialize\Actions\NamiSearchAction;
2024-02-23 00:35:29 +01:00
use Illuminate\Pagination\LengthAwarePaginator;
2024-02-22 00:40:19 +01:00
use Illuminate\Support\Facades\Crypt;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
use Zoomyboy\LaravelNami\Nami;
class SearchAction
{
use AsAction;
2024-02-23 00:35:29 +01:00
/**
* @return LengthAwarePaginator<array<string, mixed>>
*/
public function handle(ActionRequest $request): LengthAwarePaginator
2024-02-22 00:40:19 +01:00
{
$token = str($request->header('Authorization'))->replace('Bearer ', '')->toString();
$credentials = json_decode(Crypt::decryptString($token));
$api = Nami::login($credentials->mglnr, $credentials->password);
2024-05-26 01:17:05 +02:00
$results = NamiSearchAction::run($api, $request->input('page', 1), $request->except(['page', '_url']), 50);
2024-02-29 20:35:08 +01:00
$results->transform(fn ($member) => ['id' => $member->memberId, 'name' => $member->firstname . ' ' . $member->lastname]);
return $results;
2024-02-22 00:40:19 +01:00
}
}