33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Nashel.Modules.Identity.Application.Queries;
|
|
using Nashel.Modules.Identity.Infrastructure.Persistence;
|
|
|
|
namespace Nashel.Modules.Identity.Infrastructure.QueryHandlers;
|
|
|
|
public class SearchCompetenciesQueryHandler : IRequestHandler<SearchCompetenciesQuery, List<string>>
|
|
{
|
|
private readonly IdentityDbContext _context;
|
|
|
|
public SearchCompetenciesQueryHandler(IdentityDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<List<string>> Handle(SearchCompetenciesQuery request, CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Query))
|
|
return new List<string>();
|
|
|
|
var query = request.Query.ToLower();
|
|
|
|
var competencies = await _context.Competencies
|
|
.Where(c => c.Name.ToLower().Contains(query))
|
|
.Select(c => c.Name)
|
|
.Take(10) // Ограничиваем результаты
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return competencies;
|
|
}
|
|
}
|