.NET 10 solution for Ping, a Discord style chat app: Domain, Application and Infrastructure projects plus the Api host. SignalR for chat and presence, LiveKit for call tokens, EF Core on Postgres, S3 compatible storage for attachments, and OIDC auth shared with the Musify Zitadel instance. Includes the Compose stack for local development.
29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
using Mediator;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Ping.Application.Contracts;
|
|
using Ping.Application.Users.Responses;
|
|
|
|
namespace Ping.Application.Users
|
|
{
|
|
public record SearchUsersQuery(string UsernameQuery, long ExcludingUserId) : IQuery<IReadOnlyList<UserResponse>>;
|
|
|
|
public class SearchUsersQueryHandler(IDatabase database)
|
|
: IQueryHandler<SearchUsersQuery, IReadOnlyList<UserResponse>>
|
|
{
|
|
public async ValueTask<IReadOnlyList<UserResponse>> Handle(SearchUsersQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var normalizedQuery = request.UsernameQuery.Trim().ToUpperInvariant();
|
|
if (normalizedQuery.Length == 0)
|
|
return [];
|
|
|
|
var users = await database.Users.AsNoTracking()
|
|
.Where(u => u.Id != request.ExcludingUserId && u.NormalizedUsername.Contains(normalizedQuery))
|
|
.OrderBy(u => u.Username)
|
|
.Take(20)
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return users.Select(UserResponse.FromEntity).ToList();
|
|
}
|
|
}
|
|
}
|