Add Search action for contribution search
This commit is contained in:
parent
2cb04ee142
commit
188429af55
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Member\Actions;
|
||||
|
||||
use App\Member\FilterScope;
|
||||
use App\Member\Member;
|
||||
use App\Member\MemberResource;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
@ -16,25 +17,16 @@ class SearchAction
|
|||
/**
|
||||
* @return Collection<int, Member>
|
||||
*/
|
||||
public function handle(string $search): Collection
|
||||
public function handle(FilterScope $filter): Collection
|
||||
{
|
||||
return Member::search($search)->query(fn ($query) => $query->ordered())->get();
|
||||
return Member::search($filter->search)->query(fn ($q) => $q->select('*')
|
||||
->withFilter($filter)
|
||||
->ordered()
|
||||
)->get();
|
||||
}
|
||||
|
||||
public function asController(ActionRequest $request): AnonymousResourceCollection
|
||||
{
|
||||
if (null !== $request->input('minLength') && strlen($request->input('search', '')) < $request->input('minLength')) {
|
||||
return MemberResource::collection($this->empty());
|
||||
}
|
||||
|
||||
return MemberResource::collection($this->handle($request->input('search', '')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Member>
|
||||
*/
|
||||
private function empty(): Collection
|
||||
{
|
||||
return Member::where('id', -1)->get();
|
||||
return MemberResource::collection($this->handle(FilterScope::fromRequest($request->input('filter', ''))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,11 @@ export default {
|
|||
set: debounce(async function (event) {
|
||||
this.search.s = event;
|
||||
|
||||
var response = await this.axios.post('/api/member/search', {search: event, minLength: 3});
|
||||
var response = await this.axios.post('/api/member/search', {
|
||||
filter: {
|
||||
search: event,
|
||||
},
|
||||
});
|
||||
|
||||
this.search.results = response.data.data;
|
||||
}, 300),
|
||||
|
|
Loading…
Reference in New Issue