Files
Ping/backend/Core/Ping.Application/Friends/GetFriends.cs
T
Admin 0623875dfa Add Ping backend
.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.
2026-09-21 19:32:55 +02:00

31 lines
1.2 KiB
C#

using Mediator;
using Microsoft.EntityFrameworkCore;
using Ping.Application.Contracts;
using Ping.Application.Friends.Responses;
using Ping.Domain.ValueObjects;
namespace Ping.Application.Friends
{
public record GetFriendsQuery(long UserId) : IQuery<IReadOnlyList<FriendshipResponse>>;
public class GetFriendsQueryHandler(IDatabase database, IPresenceTracker presence)
: IQueryHandler<GetFriendsQuery, IReadOnlyList<FriendshipResponse>>
{
public async ValueTask<IReadOnlyList<FriendshipResponse>> Handle(GetFriendsQuery request, CancellationToken cancellationToken)
{
var friendships = await database.Friendships.AsNoTracking()
.Include(f => f.Requester)
.Include(f => f.Addressee)
.Where(f => f.Status == FriendshipStatus.Accepted &&
(f.RequesterId == request.UserId || f.AddresseeId == request.UserId))
.ToListAsync(cancellationToken);
return friendships.Select(f =>
{
var otherUserId = f.RequesterId == request.UserId ? f.AddresseeId : f.RequesterId;
return FriendshipResponse.FromEntity(f, request.UserId, presence.GetStatus(otherUserId));
}).ToList();
}
}
}