2502cbbda2
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)
219 lines
8.4 KiB
C#
219 lines
8.4 KiB
C#
using System.Linq;
|
|
using CMSMicroservice.Protobuf.Protos.SitePage;
|
|
using CMSMicroservice.WebApi.Common.Services;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePage;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.DeleteSitePage;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePage;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.CreateSitePageSection;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.UpdateSitePageSection;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.DeleteSitePageSection;
|
|
using CMSMicroservice.Application.SitePageCQ.Commands.ReorderSitePageSections;
|
|
using CMSMicroservice.Application.SitePageCQ.Queries.GetSitePage;
|
|
using CMSMicroservice.Application.SitePageCQ.Queries.GetSitePageByKey;
|
|
using CMSMicroservice.Application.SitePageCQ.Queries.GetAllSitePages;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Grpc.Core;
|
|
using MediatR;
|
|
|
|
namespace CMSMicroservice.WebApi.Services;
|
|
|
|
public class SitePageService : SitePageContract.SitePageContractBase
|
|
{
|
|
private readonly ISender _sender;
|
|
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
|
|
|
public SitePageService(ISender sender, IDispatchRequestToCQRS dispatchRequestToCQRS)
|
|
{
|
|
_sender = sender;
|
|
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
|
}
|
|
|
|
public override async Task<GetSitePageResponse> GetSitePage(GetSitePageRequest request, ServerCallContext context)
|
|
{
|
|
var query = new GetSitePageQuery { Id = request.Id };
|
|
var result = await _sender.Send(query, context.CancellationToken);
|
|
return MapToResponse(result);
|
|
}
|
|
|
|
public override async Task<GetSitePageResponse> GetSitePageByKey(GetSitePageByKeyRequest request, ServerCallContext context)
|
|
{
|
|
var query = new GetSitePageByKeyQuery { PageKey = request.PageKey };
|
|
var result = await _sender.Send(query, context.CancellationToken);
|
|
return MapToResponse(result);
|
|
}
|
|
|
|
public override async Task<Empty> UpdateSitePage(UpdateSitePageRequest request, ServerCallContext context)
|
|
{
|
|
var command = new UpdateSitePageCommand
|
|
{
|
|
Id = request.Id,
|
|
Title = request.Title,
|
|
MetaDescription = request.MetaDescription,
|
|
HeroTitle = request.HeroTitle,
|
|
HeroSubtitle = request.HeroSubtitle,
|
|
HeroImagePath = request.HeroImagePath,
|
|
IsActive = request.IsActive,
|
|
ImageFileBytes = request.ImageFile?.File?.ToByteArray(),
|
|
ImageFileMime = request.ImageFile?.Mime,
|
|
ImageFileName = request.ImageFile?.FileName
|
|
};
|
|
|
|
await _sender.Send(command, context.CancellationToken);
|
|
return new Empty();
|
|
}
|
|
|
|
public override async Task<CreateSitePageResponse> CreateSitePage(CreateSitePageRequest request, ServerCallContext context)
|
|
{
|
|
var command = new CreateSitePageCommand
|
|
{
|
|
PageKey = request.PageKey,
|
|
Title = request.Title,
|
|
MetaDescription = request.MetaDescription,
|
|
HeroTitle = request.HeroTitle,
|
|
HeroSubtitle = request.HeroSubtitle,
|
|
IsActive = request.IsActive,
|
|
ImageFileBytes = request.ImageFile?.File?.ToByteArray(),
|
|
ImageFileMime = request.ImageFile?.Mime,
|
|
ImageFileName = request.ImageFile?.FileName
|
|
};
|
|
|
|
var id = await _sender.Send(command, context.CancellationToken);
|
|
return new CreateSitePageResponse { Id = id };
|
|
}
|
|
|
|
public override async Task<Empty> DeleteSitePage(DeleteSitePageRequest request, ServerCallContext context)
|
|
{
|
|
var command = new DeleteSitePageCommand { Id = request.Id };
|
|
await _sender.Send(command, context.CancellationToken);
|
|
return new Empty();
|
|
}
|
|
|
|
public override async Task<GetAllSitePagesResponse> GetAllSitePages(GetAllSitePagesRequest request, ServerCallContext context)
|
|
{
|
|
var query = new GetAllSitePagesQuery();
|
|
var result = await _sender.Send(query, context.CancellationToken);
|
|
|
|
var response = new GetAllSitePagesResponse();
|
|
foreach (var item in result)
|
|
{
|
|
response.Pages.Add(new SitePageSummary
|
|
{
|
|
Id = item.Id,
|
|
PageKey = item.PageKey ?? string.Empty,
|
|
Title = item.Title ?? string.Empty,
|
|
IsActive = item.IsActive,
|
|
SectionCount = item.SectionCount,
|
|
LastModified = item.LastModified.HasValue
|
|
? Timestamp.FromDateTime(DateTime.SpecifyKind(item.LastModified.Value, DateTimeKind.Utc))
|
|
: null
|
|
});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
public override async Task<CreateSitePageSectionResponse> CreateSitePageSection(CreateSitePageSectionRequest request, ServerCallContext context)
|
|
{
|
|
var command = new CreateSitePageSectionCommand
|
|
{
|
|
SitePageId = request.SitePageId,
|
|
SectionKey = request.SectionKey,
|
|
Title = request.Title,
|
|
Subtitle = request.Subtitle,
|
|
HtmlContent = request.HtmlContent,
|
|
IconName = request.IconName,
|
|
ImagePath = request.ImagePath,
|
|
IsActive = true,
|
|
ExtraData = request.ExtraData,
|
|
ImageFileBytes = request.ImageFile?.File?.ToByteArray(),
|
|
ImageFileMime = request.ImageFile?.Mime,
|
|
ImageFileName = request.ImageFile?.FileName
|
|
};
|
|
|
|
var result = await _sender.Send(command, context.CancellationToken);
|
|
return new CreateSitePageSectionResponse { Id = result };
|
|
}
|
|
|
|
public override async Task<Empty> UpdateSitePageSection(UpdateSitePageSectionRequest request, ServerCallContext context)
|
|
{
|
|
var command = new UpdateSitePageSectionCommand
|
|
{
|
|
Id = request.Id,
|
|
SectionKey = request.SectionKey,
|
|
Title = request.Title,
|
|
Subtitle = request.Subtitle,
|
|
HtmlContent = request.HtmlContent,
|
|
IconName = request.IconName,
|
|
ImagePath = request.ImagePath,
|
|
SortOrder = request.SortOrder,
|
|
IsActive = request.IsActive,
|
|
ExtraData = request.ExtraData,
|
|
ImageFileBytes = request.ImageFile?.File?.ToByteArray(),
|
|
ImageFileMime = request.ImageFile?.Mime,
|
|
ImageFileName = request.ImageFile?.FileName
|
|
};
|
|
|
|
await _sender.Send(command, context.CancellationToken);
|
|
return new Empty();
|
|
}
|
|
|
|
public override async Task<Empty> DeleteSitePageSection(DeleteSitePageSectionRequest request, ServerCallContext context)
|
|
{
|
|
return await _dispatchRequestToCQRS.Handle<DeleteSitePageSectionRequest, DeleteSitePageSectionCommand>(request, context);
|
|
}
|
|
|
|
public override async Task<Empty> ReorderSitePageSections(ReorderSitePageSectionsRequest request, ServerCallContext context)
|
|
{
|
|
var command = new ReorderSitePageSectionsCommand
|
|
{
|
|
Items = request.Items.Select(x => new Application.SitePageCQ.Commands.ReorderSitePageSections.SectionSortItem
|
|
{
|
|
Id = x.Id,
|
|
SortOrder = x.SortOrder
|
|
}).ToList()
|
|
};
|
|
|
|
await _sender.Send(command, context.CancellationToken);
|
|
return new Empty();
|
|
}
|
|
|
|
// ── Private Mapping Helpers ──
|
|
|
|
private static GetSitePageResponse MapToResponse(SitePageDto dto)
|
|
{
|
|
var response = new GetSitePageResponse
|
|
{
|
|
Id = dto.Id,
|
|
PageKey = dto.PageKey ?? string.Empty,
|
|
Title = dto.Title ?? string.Empty,
|
|
MetaDescription = dto.MetaDescription,
|
|
HeroTitle = dto.HeroTitle,
|
|
HeroSubtitle = dto.HeroSubtitle,
|
|
HeroImagePath = dto.HeroImagePath,
|
|
IsActive = dto.IsActive
|
|
};
|
|
|
|
if (dto.Sections != null)
|
|
{
|
|
foreach (var s in dto.Sections)
|
|
{
|
|
response.Sections.Add(new SitePageSectionItem
|
|
{
|
|
Id = s.Id,
|
|
SectionKey = s.SectionKey ?? string.Empty,
|
|
Title = s.Title ?? string.Empty,
|
|
Subtitle = s.Subtitle,
|
|
HtmlContent = s.HtmlContent,
|
|
IconName = s.IconName,
|
|
ImagePath = s.ImagePath,
|
|
SortOrder = s.SortOrder,
|
|
IsActive = s.IsActive,
|
|
ExtraData = s.ExtraData
|
|
});
|
|
}
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|