38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
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<CreatePostCommand, Result<NewsPostDto>>
|
|
{
|
|
public async Task<Result<NewsPostDto>> 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));
|
|
}
|
|
}
|