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.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user