feat: integrate PYMS payment gateway, add blog/sitepage/image services, local file manager
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m44s

Payment Gateway:
- Add PYMSPaymentService: IPaymentGatewayService via gRPC to PYMS microservice
- Add ZarinPalPaymentService: direct ZarinPal integration (backup)
- Register 'pyms' payment provider in DI ConfigureServices
- Add PYMS proto files (pyms_transaction.proto, pyms_public_messages.proto)
- Fix VerifyDiscountWalletCharge: pass 'OK' as status instead of Authority
- Update appsettings: PaymentProvider=pyms, sandbox mode, merchant ID

Blog System:
- Add BlogCategory, BlogPost, BlogPostImage entities and CQRS
- Add proto files and gRPC services for blog management
- Add Mapster profiles for blog responses

Content Management:
- Add SitePage entity and CQRS for static pages
- Add proto and gRPC service for site pages

Image/File Management:
- Add LocalFileManager with disk storage + base64 serving + FMS fallback
- Add ImagePathResolverInterceptor for gRPC responses
- Add ImageResolverService for explicit image resolution
- Add UploadsController for public file serving with FMS fallback
- Add PaymentCallbackController for discount order payment callbacks

Database:
- Add blog and content entity migrations
- Remove ImagePath MaxLength constraints
- Remove old FileManagementService (replaced by LocalFileManager)
This commit is contained in:
masoodafar-web
2026-02-15 23:01:16 +03:30
parent 5a4e4a960d
commit 2502cbbda2
177 changed files with 16632 additions and 487 deletions
@@ -0,0 +1,18 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePage;
public class CreateSitePageCommand : IRequest<long>
{
public string PageKey { get; set; } = default!;
public string Title { get; set; } = default!;
public string? MetaDescription { get; set; }
public string? HeroTitle { get; set; }
public string? HeroSubtitle { get; set; }
public bool IsActive { get; set; } = true;
// Image upload properties
public byte[]? ImageFileBytes { get; set; }
public string? ImageFileMime { get; set; }
public string? ImageFileName { get; set; }
}
@@ -0,0 +1,49 @@
using CMSMicroservice.Application.Common.FileManager;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePage;
public class CreateSitePageCommandHandler : IRequestHandler<CreateSitePageCommand, long>
{
private readonly IApplicationDbContext _context;
private readonly IFileManager _fileManager;
public CreateSitePageCommandHandler(IApplicationDbContext context, IFileManager fileManager)
{
_context = context;
_fileManager = fileManager;
}
public async Task<long> Handle(CreateSitePageCommand request, CancellationToken cancellationToken)
{
var entity = new SitePage
{
PageKey = request.PageKey,
Title = request.Title,
MetaDescription = request.MetaDescription,
HeroTitle = request.HeroTitle,
HeroSubtitle = request.HeroSubtitle,
IsActive = request.IsActive
};
// آپلود تصویر هیرو (اگر فایل ارسال شده باشد)
if (request.ImageFileBytes is { Length: > 0 })
{
var result = await _fileManager.UploadImageAsync(
"Images/SitePages",
request.ImageFileBytes,
request.ImageFileMime ?? "image/jpeg",
request.ImageFileName,
cancellationToken);
entity.HeroImagePath = result.Main.Path;
}
_context.SitePages.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return entity.Id;
}
}
@@ -0,0 +1,21 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePageSection;
public class CreateSitePageSectionCommand : IRequest<long>
{
public long SitePageId { get; set; }
public string SectionKey { get; set; } = default!;
public string? Title { get; set; }
public string? Subtitle { get; set; }
public string? HtmlContent { get; set; }
public string? IconName { get; set; }
public string? ImagePath { get; set; }
public bool IsActive { get; set; } = true;
public string? ExtraData { get; set; }
// Image upload properties
public byte[]? ImageFileBytes { get; set; }
public string? ImageFileMime { get; set; }
public string? ImageFileName { get; set; }
}
@@ -0,0 +1,68 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.FileManager;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePageSection;
public class CreateSitePageSectionCommandHandler : IRequestHandler<CreateSitePageSectionCommand, long>
{
private readonly IApplicationDbContext _context;
private readonly IFileManager _fileManager;
public CreateSitePageSectionCommandHandler(IApplicationDbContext context, IFileManager fileManager)
{
_context = context;
_fileManager = fileManager;
}
public async Task<long> Handle(CreateSitePageSectionCommand request, CancellationToken cancellationToken)
{
var page = await _context.SitePages.FirstOrDefaultAsync(x => x.Id == request.SitePageId && !x.IsDeleted, cancellationToken);
if (page == null)
throw new NotFoundException(nameof(SitePage), request.SitePageId);
var maxSortOrder = await _context.SitePageSections
.Where(x => x.SitePageId == request.SitePageId && !x.IsDeleted)
.MaxAsync(x => (int?)x.SortOrder, cancellationToken) ?? 0;
var sectionKey = string.IsNullOrWhiteSpace(request.SectionKey)
? $"section-{Guid.NewGuid():N}"[..20]
: request.SectionKey.Trim().ToLower();
var entity = new SitePageSection
{
SitePageId = request.SitePageId,
SectionKey = sectionKey,
Title = request.Title,
Subtitle = request.Subtitle,
HtmlContent = request.HtmlContent,
IconName = request.IconName,
ImagePath = request.ImagePath,
SortOrder = maxSortOrder + 1,
IsActive = request.IsActive,
ExtraData = request.ExtraData
};
// آپلود تصویر بخش (اگر فایل ارسال شده باشد)
if (request.ImageFileBytes is { Length: > 0 })
{
var result = await _fileManager.UploadImageAsync(
"Images/SitePageSections",
request.ImageFileBytes,
request.ImageFileMime ?? "image/jpeg",
request.ImageFileName,
cancellationToken);
entity.ImagePath = result.Main.Path;
entity.ImageThumbnailPath = result.Thumbnail.Path;
}
_context.SitePageSections.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return entity.Id;
}
}
@@ -0,0 +1,26 @@
using FluentValidation;
namespace CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePageSection;
public class CreateSitePageSectionCommandValidator : AbstractValidator<CreateSitePageSectionCommand>
{
public CreateSitePageSectionCommandValidator()
{
RuleFor(x => x.SitePageId)
.GreaterThan(0).WithMessage("شناسه صفحه نامعتبر است");
RuleFor(x => x.SectionKey)
.MaximumLength(100).WithMessage("کلید بخش حداکثر ۱۰۰ کاراکتر")
.Matches(@"^[a-z0-9\-_]*$").WithMessage("کلید بخش فقط شامل حروف کوچک، اعداد، خط تیره و زیرخط")
.When(x => !string.IsNullOrWhiteSpace(x.SectionKey));
RuleFor(x => x.Title)
.MaximumLength(300).WithMessage("عنوان بخش حداکثر ۳۰۰ کاراکتر");
RuleFor(x => x.Subtitle)
.MaximumLength(500).WithMessage("زیرعنوان بخش حداکثر ۵۰۰ کاراکتر");
RuleFor(x => x.IconName)
.MaximumLength(100).WithMessage("نام آیکون حداکثر ۱۰۰ کاراکتر");
}
}
@@ -0,0 +1,8 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.DeleteSitePage;
public class DeleteSitePageCommand : IRequest<Unit>
{
public long Id { get; set; }
}
@@ -0,0 +1,35 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.DeleteSitePage;
public class DeleteSitePageCommandHandler : IRequestHandler<DeleteSitePageCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteSitePageCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteSitePageCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SitePages.FindAsync(new object[] { request.Id }, cancellationToken);
if (entity == null || entity.IsDeleted)
throw new NotFoundException(nameof(SitePage), request.Id);
entity.IsDeleted = true;
// حذف نرم بخش‌های وابسته
foreach (var section in entity.Sections.Where(s => !s.IsDeleted))
{
section.IsDeleted = true;
}
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,8 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.DeleteSitePageSection;
public class DeleteSitePageSectionCommand : IRequest<Unit>
{
public long Id { get; set; }
}
@@ -0,0 +1,29 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.DeleteSitePageSection;
public class DeleteSitePageSectionCommandHandler : IRequestHandler<DeleteSitePageSectionCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteSitePageSectionCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteSitePageSectionCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SitePageSections.FindAsync(new object[] { request.Id }, cancellationToken);
if (entity == null || entity.IsDeleted)
throw new NotFoundException(nameof(SitePageSection), request.Id);
entity.IsDeleted = true;
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,14 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.ReorderSitePageSections;
public class ReorderSitePageSectionsCommand : IRequest<Unit>
{
public List<SectionSortItem> Items { get; set; } = new();
}
public class SectionSortItem
{
public long Id { get; set; }
public int SortOrder { get; set; }
}
@@ -0,0 +1,34 @@
using CMSMicroservice.Application.Common.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.SitePageCQ.Commands.ReorderSitePageSections;
public class ReorderSitePageSectionsCommandHandler : IRequestHandler<ReorderSitePageSectionsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public ReorderSitePageSectionsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(ReorderSitePageSectionsCommand request, CancellationToken cancellationToken)
{
var ids = request.Items.Select(x => x.Id).ToList();
var sections = await _context.SitePageSections
.Where(x => ids.Contains(x.Id) && !x.IsDeleted)
.ToListAsync(cancellationToken);
foreach (var item in request.Items)
{
var section = sections.FirstOrDefault(x => x.Id == item.Id);
if (section != null)
section.SortOrder = item.SortOrder;
}
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,19 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePage;
public class UpdateSitePageCommand : IRequest<Unit>
{
public long Id { get; set; }
public string Title { get; set; } = default!;
public string? MetaDescription { get; set; }
public string? HeroTitle { get; set; }
public string? HeroSubtitle { get; set; }
public string? HeroImagePath { get; set; }
public bool IsActive { get; set; }
// Image upload properties
public byte[]? ImageFileBytes { get; set; }
public string? ImageFileMime { get; set; }
public string? ImageFileName { get; set; }
}
@@ -0,0 +1,50 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.FileManager;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePage;
public class UpdateSitePageCommandHandler : IRequestHandler<UpdateSitePageCommand, Unit>
{
private readonly IApplicationDbContext _context;
private readonly IFileManager _fileManager;
public UpdateSitePageCommandHandler(IApplicationDbContext context, IFileManager fileManager)
{
_context = context;
_fileManager = fileManager;
}
public async Task<Unit> Handle(UpdateSitePageCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SitePages.FindAsync(new object[] { request.Id }, cancellationToken);
if (entity == null || entity.IsDeleted)
throw new NotFoundException(nameof(SitePage), request.Id);
entity.Title = request.Title;
entity.MetaDescription = request.MetaDescription;
entity.HeroTitle = request.HeroTitle;
entity.HeroSubtitle = request.HeroSubtitle;
entity.HeroImagePath = request.HeroImagePath;
entity.IsActive = request.IsActive;
// آپلود تصویر هیرو (اگر فایل ارسال شده باشد)
if (request.ImageFileBytes is { Length: > 0 })
{
var result = await _fileManager.UploadImageAsync(
"Images/SitePages",
request.ImageFileBytes,
request.ImageFileMime ?? "image/jpeg",
request.ImageFileName,
cancellationToken);
entity.HeroImagePath = result.Main.Path;
}
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,25 @@
using FluentValidation;
namespace CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePage;
public class UpdateSitePageCommandValidator : AbstractValidator<UpdateSitePageCommand>
{
public UpdateSitePageCommandValidator()
{
RuleFor(x => x.Id)
.GreaterThan(0).WithMessage("شناسه صفحه نامعتبر است");
RuleFor(x => x.Title)
.NotEmpty().WithMessage("عنوان صفحه الزامی است")
.MaximumLength(200).WithMessage("عنوان صفحه حداکثر ۲۰۰ کاراکتر");
RuleFor(x => x.MetaDescription)
.MaximumLength(500).WithMessage("توضیحات متا حداکثر ۵۰۰ کاراکتر");
RuleFor(x => x.HeroTitle)
.MaximumLength(300).WithMessage("عنوان هیرو حداکثر ۳۰۰ کاراکتر");
RuleFor(x => x.HeroSubtitle)
.MaximumLength(500).WithMessage("زیرعنوان هیرو حداکثر ۵۰۰ کاراکتر");
}
}
@@ -0,0 +1,22 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePageSection;
public class UpdateSitePageSectionCommand : IRequest<Unit>
{
public long Id { get; set; }
public string SectionKey { get; set; } = default!;
public string? Title { get; set; }
public string? Subtitle { get; set; }
public string? HtmlContent { get; set; }
public string? IconName { get; set; }
public string? ImagePath { get; set; }
public int SortOrder { get; set; }
public bool IsActive { get; set; }
public string? ExtraData { get; set; }
// Image upload properties
public byte[]? ImageFileBytes { get; set; }
public string? ImageFileMime { get; set; }
public string? ImageFileName { get; set; }
}
@@ -0,0 +1,54 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.FileManager;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePageSection;
public class UpdateSitePageSectionCommandHandler : IRequestHandler<UpdateSitePageSectionCommand, Unit>
{
private readonly IApplicationDbContext _context;
private readonly IFileManager _fileManager;
public UpdateSitePageSectionCommandHandler(IApplicationDbContext context, IFileManager fileManager)
{
_context = context;
_fileManager = fileManager;
}
public async Task<Unit> Handle(UpdateSitePageSectionCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SitePageSections.FindAsync(new object[] { request.Id }, cancellationToken);
if (entity == null || entity.IsDeleted)
throw new NotFoundException(nameof(SitePageSection), request.Id);
entity.SectionKey = request.SectionKey;
entity.Title = request.Title;
entity.Subtitle = request.Subtitle;
entity.HtmlContent = request.HtmlContent;
entity.IconName = request.IconName;
entity.ImagePath = request.ImagePath;
entity.SortOrder = request.SortOrder;
entity.IsActive = request.IsActive;
entity.ExtraData = request.ExtraData;
// آپلود تصویر بخش (اگر فایل جدید ارسال شده باشد)
if (request.ImageFileBytes is { Length: > 0 })
{
var result = await _fileManager.UploadImageAsync(
"Images/SitePageSections",
request.ImageFileBytes,
request.ImageFileMime ?? "image/jpeg",
request.ImageFileName,
cancellationToken);
entity.ImagePath = result.Main.Path;
entity.ImageThumbnailPath = result.Thumbnail.Path;
}
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,26 @@
using FluentValidation;
namespace CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePageSection;
public class UpdateSitePageSectionCommandValidator : AbstractValidator<UpdateSitePageSectionCommand>
{
public UpdateSitePageSectionCommandValidator()
{
RuleFor(x => x.Id)
.GreaterThan(0).WithMessage("شناسه بخش نامعتبر است");
RuleFor(x => x.SectionKey)
.NotEmpty().WithMessage("کلید بخش الزامی است")
.MaximumLength(100).WithMessage("کلید بخش حداکثر ۱۰۰ کاراکتر")
.Matches(@"^[a-z0-9\-_]+$").WithMessage("کلید بخش فقط شامل حروف کوچک، اعداد، خط تیره و زیرخط");
RuleFor(x => x.Title)
.MaximumLength(300).WithMessage("عنوان بخش حداکثر ۳۰۰ کاراکتر");
RuleFor(x => x.Subtitle)
.MaximumLength(500).WithMessage("زیرعنوان بخش حداکثر ۵۰۰ کاراکتر");
RuleFor(x => x.IconName)
.MaximumLength(100).WithMessage("نام آیکون حداکثر ۱۰۰ کاراکتر");
}
}
@@ -0,0 +1,51 @@
using CMSMicroservice.Application.Common.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.SitePageCQ.Queries.GetAllSitePages;
public class GetAllSitePagesQuery : IRequest<List<SitePageListItemDto>>
{
}
public class SitePageListItemDto
{
public long Id { get; set; }
public string PageKey { get; set; } = default!;
public string Title { get; set; } = default!;
public bool IsActive { get; set; }
public int SectionCount { get; set; }
public DateTime Created { get; set; }
public DateTime? LastModified { get; set; }
}
public class GetAllSitePagesQueryHandler : IRequestHandler<GetAllSitePagesQuery, List<SitePageListItemDto>>
{
private readonly IApplicationDbContext _context;
public GetAllSitePagesQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<List<SitePageListItemDto>> Handle(GetAllSitePagesQuery request, CancellationToken cancellationToken)
{
var pages = await _context.SitePages
.Include(x => x.Sections)
.Where(x => !x.IsDeleted)
.OrderBy(x => x.PageKey)
.Select(x => new SitePageListItemDto
{
Id = x.Id,
PageKey = x.PageKey,
Title = x.Title,
IsActive = x.IsActive,
SectionCount = x.Sections.Count(s => !s.IsDeleted),
Created = x.Created,
LastModified = x.LastModified
})
.ToListAsync(cancellationToken);
return pages;
}
}
@@ -0,0 +1,8 @@
using MediatR;
namespace CMSMicroservice.Application.SitePageCQ.Queries.GetSitePage;
public class GetSitePageQuery : IRequest<SitePageDto>
{
public long Id { get; set; }
}
@@ -0,0 +1,59 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.SitePageCQ.Queries.GetSitePage;
public class GetSitePageQueryHandler : IRequestHandler<GetSitePageQuery, SitePageDto>
{
private readonly IApplicationDbContext _context;
public GetSitePageQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<SitePageDto> Handle(GetSitePageQuery request, CancellationToken cancellationToken)
{
var entity = await _context.SitePages
.Include(x => x.Sections.Where(s => !s.IsDeleted).OrderBy(s => s.SortOrder))
.FirstOrDefaultAsync(x => x.Id == request.Id && !x.IsDeleted, cancellationToken);
if (entity == null)
throw new NotFoundException(nameof(SitePage), request.Id);
return MapToDto(entity);
}
internal static SitePageDto MapToDto(SitePage entity)
{
return new SitePageDto
{
Id = entity.Id,
PageKey = entity.PageKey,
Title = entity.Title,
MetaDescription = entity.MetaDescription,
HeroTitle = entity.HeroTitle,
HeroSubtitle = entity.HeroSubtitle,
HeroImagePath = entity.HeroImagePath,
IsActive = entity.IsActive,
Created = entity.Created,
LastModified = entity.LastModified,
Sections = entity.Sections.Select(s => new SitePageSectionDto
{
Id = s.Id,
SectionKey = s.SectionKey,
Title = s.Title,
Subtitle = s.Subtitle,
HtmlContent = s.HtmlContent,
IconName = s.IconName,
ImagePath = s.ImagePath,
SortOrder = s.SortOrder,
IsActive = s.IsActive,
ExtraData = s.ExtraData
}).ToList()
};
}
}
@@ -0,0 +1,30 @@
namespace CMSMicroservice.Application.SitePageCQ.Queries.GetSitePage;
public class SitePageDto
{
public long Id { get; set; }
public string PageKey { get; set; } = default!;
public string Title { get; set; } = default!;
public string? MetaDescription { get; set; }
public string? HeroTitle { get; set; }
public string? HeroSubtitle { get; set; }
public string? HeroImagePath { get; set; }
public bool IsActive { get; set; }
public DateTime Created { get; set; }
public DateTime? LastModified { get; set; }
public List<SitePageSectionDto> Sections { get; set; } = new();
}
public class SitePageSectionDto
{
public long Id { get; set; }
public string SectionKey { get; set; } = default!;
public string? Title { get; set; }
public string? Subtitle { get; set; }
public string? HtmlContent { get; set; }
public string? IconName { get; set; }
public string? ImagePath { get; set; }
public int SortOrder { get; set; }
public bool IsActive { get; set; }
public string? ExtraData { get; set; }
}
@@ -0,0 +1,34 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities.Content;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.SitePageCQ.Queries.GetSitePageByKey;
public class GetSitePageByKeyQuery : IRequest<GetSitePage.SitePageDto>
{
public string PageKey { get; set; } = default!;
}
public class GetSitePageByKeyQueryHandler : IRequestHandler<GetSitePageByKeyQuery, GetSitePage.SitePageDto>
{
private readonly IApplicationDbContext _context;
public GetSitePageByKeyQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetSitePage.SitePageDto> Handle(GetSitePageByKeyQuery request, CancellationToken cancellationToken)
{
var entity = await _context.SitePages
.Include(x => x.Sections.Where(s => !s.IsDeleted).OrderBy(s => s.SortOrder))
.FirstOrDefaultAsync(x => x.PageKey == request.PageKey && !x.IsDeleted, cancellationToken);
if (entity == null)
throw new NotFoundException(nameof(SitePage), request.PageKey);
return GetSitePage.GetSitePageQueryHandler.MapToDto(entity);
}
}