Files
PnvPanel/backend/src/PnvPanel.Application/Admin/News/CreatePostCommandHandler.cs
T
mrleo1nidandClaude Opus 5.5 0dcbd4e2b8
CI / Backend (build + test) (push) Failing after 1m26s
CI / Frontend (lint + typecheck + build) (push) Successful in 37s
Include news text preview in Telegram notification
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 17:25:36 +03:00

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));
}
}