Files
Ping/backend/Core/Ping.Application/Channels/GetServerChannels.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 ErrorOr;
using Mediator;
using Microsoft.EntityFrameworkCore;
using Ping.Application.Channels.Responses;
using Ping.Application.Contracts;
namespace Ping.Application.Channels
{
public record GetServerChannelsQuery(long CurrentUserId, Guid ServerId) : IQuery<ErrorOr<List<ChannelResponse>>>;
public class GetServerChannelsQueryHandler(IDatabase database)
: IQueryHandler<GetServerChannelsQuery, ErrorOr<List<ChannelResponse>>>
{
public async ValueTask<ErrorOr<List<ChannelResponse>>> Handle(GetServerChannelsQuery request, CancellationToken cancellationToken)
{
var isMember = await database.ServerMembers.AnyAsync(
m => m.ServerId == request.ServerId && m.UserId == request.CurrentUserId, cancellationToken);
if (!isMember)
return Error.NotFound(description: $"Server {request.ServerId} not found");
var channels = await database.Channels.AsNoTracking()
.Where(c => c.ServerId == request.ServerId)
.OrderBy(c => c.Position)
.ToListAsync(cancellationToken);
return channels.Select(ChannelResponse.FromEntity).ToList();
}
}
}