implement SearchUsers use case

This commit is contained in:
Yisroel Baum 2026-05-06 22:34:08 +03:00
parent 31a807f0ae
commit d917e76f1b
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 93 additions and 0 deletions

View file

@ -43,6 +43,25 @@ class EloquentUserRepository implements UserRepository
return $model === null ? null : $this->toDomain($model);
}
/**
* @return User[]
*/
public function search(string $query): array
{
$like = strtolower($query).'%';
$models = UserModel::query()
->whereRaw('LOWER(display_name) LIKE ?', [$like])
->orWhereRaw('LOWER(email) LIKE ?', [$like])
->orderBy('display_name')
->get();
return $models->map(
function (UserModel $model) {
return $this->toDomain($model);
},
)->all();
}
/**
* @throws RuntimeException
*/