using PnvPanel.Application.Common.Interfaces; using LiteCqrs; using PnvPanel.Application.Common.Models; using PnvPanel.Application.News; using PnvPanel.Domain.News; namespace PnvPanel.Application.Admin.News; public sealed class CreatePostCommandHandler( IAppDbContext dbContext, IRealtimeNotifier notifier, ITelegramNotifier telegramNotifier ) : ICommandHandler> { public async Task> Handle( CreatePostCommand command, CancellationToken cancellationToken ) { var post = NewsPost.Create(command.Title, command.Body); dbContext.NewsPosts.Add(post); await notifier.NotifyNewsPublishedAsync( post.Id, post.Title, post.CreatedAt, cancellationToken ); await telegramNotifier.NotifyUsersNewsPublishedAsync( post.Title, post.Body, cancellationToken ); return Result.Success(NewsPostDto.FromDomain(post)); } }