Files
nashel-backend/src/Modules/Identity/Infrastructure/QueryHandlers/SearchCompetenciesQueryHandler.cs
Халимов Рустам 1e72d006c4 Страница профиля
2026-02-13 14:24:01 +03:00

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;
}
}