public async Task <Result <SubscriptionDto> > Handle(GetSubscriptionByIdQuery request, CancellationToken cancellationToken) { var subscription = await _context.Subscriptions .Include(x => x.ChannelSubscriptions).ThenInclude(x => x.GuildChannel).ThenInclude(x => x.Guild).ThenInclude(x => x.GuildSetting) .Include(x => x.Subreddit) .FirstOrDefaultAsync(subscription => subscription.Id == request.SubscriptionId, cancellationToken); if (subscription == null) { return(await Result <SubscriptionDto> .FailAsync("Subscription not found")); } var dto = new SubscriptionDto { Id = subscription.Id, LastPostId = subscription.LastPostId, Sort = subscription.Sort, SubredditName = subscription.Subreddit.Name, Channels = subscription.ChannelSubscriptions.Select(x => new ChannelSubscriptionDto { Id = x.GuildChannelId, GuildId = x.GuildChannel.Guild.Id, DiscordChannelId = x.GuildChannel.DiscordChannelId, IsEnabled = x.GuildChannel.Guild.GuildSetting.IsEnabled, IsShowNsfw = x.GuildChannel.Guild.GuildSetting.AllowNsfw }).ToList() }; return(await Result <SubscriptionDto> .SuccessAsync(dto)); }
public async Task TestAsync(GetSubscriptionByIdQuery query) { query.Subscription = await GetSubscriptionAsync(query.SubscriptionId); }