using Application.Abstractions.Data; using SharedKernel.Storage; using MediatR; using Microsoft.EntityFrameworkCore; namespace Application.Features.Faq.Item.Create { public sealed class Handler(IAppDbContext db, IEditorImageService editorImage) : IRequestHandler { public async Task Handle(Command request, CancellationToken ct) { if (await db.FaqItem.AnyAsync(c => c.Question == request.Question)) { throw new Exception("ÀÌ¹Ì µî·ÏµÈ FAQÀÔ´Ï´Ù."); } var faq = Domain.Entities.Page.Faq.FaqItem.Create( request.CategoryID, request.Question, null, request.Order, request.IsActive ); await db.FaqItem.AddAsync(faq, ct); int affectedRows = await db.SaveChangesAsync(); if (affectedRows <= 0) { throw new Exception("FAQ µî·Ï Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù."); } var path = new FileStoragePath(UploadTarget.Editor, UploadFolder.Faq, faq.ID); var html = await editorImage.UploadAsync(request.Answer, path, ct); faq.SetContent(html); await db.SaveChangesAsync(); } } }