diff --git a/Netina.Api/Controllers/PageController.cs b/Netina.Api/Controllers/PageController.cs index 2eef4cf..0fb4d6e 100644 --- a/Netina.Api/Controllers/PageController.cs +++ b/Netina.Api/Controllers/PageController.cs @@ -38,6 +38,11 @@ public class PageController : ICarterModule .HasApiVersion(1.0) .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManagePages)); + group.MapPost("", UpdatePageAsync) + .WithDisplayName("Update Page") + .HasApiVersion(1.0) + .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManagePages)); + group.MapDelete("{id}", DeletePageByIdAsync) .WithDisplayName("Delete Page") .HasApiVersion(1.0) @@ -55,27 +60,25 @@ public class PageController : ICarterModule => TypedResults.Ok(await pageService.DeletePageAsync(id, cancellationToken)); public async Task GetPagesAsync([FromServices] IPageService pageService, CancellationToken cancellationToken) - { - return TypedResults.Ok(await pageService.GetPagesAsync(cancellationToken)); - } + => TypedResults.Ok(await pageService.GetPagesAsync(cancellationToken)); public async Task GetPageByIdAsync(Guid id ,[FromServices] IPageService pageService, CancellationToken cancellationToken) - { - return TypedResults.Ok(await pageService.GetPageAsync(id: id,cancellationToken: cancellationToken)); - } + => TypedResults.Ok(await pageService.GetPageAsync(id: id, cancellationToken: cancellationToken)); public async Task GetPageByTypeAsync(string type, [FromServices] IPageService pageService, CancellationToken cancellationToken) - { - return TypedResults.Ok(await pageService.GetPageAsync(type: type, cancellationToken: cancellationToken)); - } + => TypedResults.Ok(await pageService.GetPageAsync(type: type, cancellationToken: cancellationToken)); public async Task GetPageAsync(string pageSlug, [FromServices] IPageService pageService, CancellationToken cancellationToken) - { - return TypedResults.Ok(await pageService.GetPageAsync(pageSlug: pageSlug,cancellationToken: cancellationToken)); - } + => TypedResults.Ok(await pageService.GetPageAsync(pageSlug: pageSlug, cancellationToken: cancellationToken)); public async Task PostPageAsync([FromBody] PageActionRequestDto page, [FromServices] IPageService pageService, CancellationToken cancellationToken) { await pageService.CreatePageAsync(page, cancellationToken); return TypedResults.Ok(); } + + public async Task UpdatePageAsync([FromBody] PageActionRequestDto page, [FromServices] IPageService pageService, CancellationToken cancellationToken) + { + await pageService.UpdatePageAsync(page, cancellationToken); + return TypedResults.Ok(); + } } \ No newline at end of file diff --git a/Netina.Core/BaseServices/Abstracts/IPageService.cs b/Netina.Core/BaseServices/Abstracts/IPageService.cs index 0937123..f881bab 100644 --- a/Netina.Core/BaseServices/Abstracts/IPageService.cs +++ b/Netina.Core/BaseServices/Abstracts/IPageService.cs @@ -2,9 +2,10 @@ public interface IPageService : IScopedDependency { - Task GetPageAsync(Guid? id = null, string? pageName = null, string? pageSlug = null, string? type = null, CancellationToken cancellationToken = default); + Task GetPageAsync(Guid? id = null, string? pageName = null, string? pageSlug = null, string? type = null, CancellationToken cancellationToken = default); Task> GetPagesAsync(CancellationToken cancellationToken = default); Task CreatePageAsync(PageActionRequestDto entity, CancellationToken cancellationToken = default); + Task UpdatePageAsync(PageActionRequestDto entity, CancellationToken cancellationToken = default); Task DeletePageAsync(Guid id, CancellationToken cancellationToken = default); Task CheckRedirectAsync(string oldUrl, CancellationToken cancellationToken); diff --git a/Netina.Core/BaseServices/PageService.cs b/Netina.Core/BaseServices/PageService.cs index a5801f2..c157633 100644 --- a/Netina.Core/BaseServices/PageService.cs +++ b/Netina.Core/BaseServices/PageService.cs @@ -1,5 +1,4 @@ -using Netina.Core.BaseServices.Abstracts; -using Netina.Domain.MartenEntities.Pages; +using Netina.Domain.MartenEntities.Pages; namespace Netina.Core.BaseServices; @@ -9,7 +8,11 @@ public class PageService( ISettingService settingService) : IPageService { - public async Task GetPageAsync(Guid? id = null, string? pageName = null, string? pageSlug = null, string? type = null, CancellationToken cancellationToken = default) + public async Task GetPageAsync(Guid? id = null, + string? pageName = null, + string? pageSlug = null, + string? type = null, + CancellationToken cancellationToken = default) { BasePage? page = null; if (id != null) @@ -24,17 +27,7 @@ public class PageService( throw new AppException("Page not found", ApiResultStatusCode.NotFound); var entityType = Assembly.GetAssembly(typeof(DomainConfig))?.GetType(page.Type); - var dto = new BasePageSDto - { - Content = page.Content, - Description = page.Description, - Id = page.Id, - IsCustomPage = page.IsCustomPage, - IsHtmlBasePage = page.IsHtmlBasePage, - Title = page.Title, - Slug = page.Slug, - Data = page.Data - }; + var dto = page.Adapt(); return dto; } @@ -45,19 +38,7 @@ public class PageService( var pages = await martenRepositoryWrapperWrapper.SetRepository().GetEntitiesAsync(cancellationToken); foreach (var page in pages) { - var dto = new BasePageSDto - { - Content = page.Content, - Description = page.Description, - Id = page.Id, - IsCustomPage = page.IsCustomPage, - IsHtmlBasePage = page.IsHtmlBasePage, - Title = page.Title, - Slug = page.Slug, - Data = page.Data, - CreatedAt = page.CreatedAt, - ModifiedAt = page.ModifiedAt - }; + var dto = page.Adapt(); sDtos.Add(dto); } return sDtos; @@ -124,4 +105,11 @@ public class PageService( } throw new BaseApiException(ApiResultStatusCode.NotFound, "PageSetting not found"); } + + public async Task UpdatePageAsync(PageActionRequestDto entity, CancellationToken cancellationToken = default) + { + var basePage = entity.Adapt(); + await martenRepositoryWrapperWrapper.SetRepository().AddOrUpdateEntityAsync(basePage, cancellationToken); + return true; + } } \ No newline at end of file diff --git a/Netina.Core/BaseServices/SiteMapService.cs b/Netina.Core/BaseServices/SiteMapService.cs index d12b1f5..3045aa7 100644 --- a/Netina.Core/BaseServices/SiteMapService.cs +++ b/Netina.Core/BaseServices/SiteMapService.cs @@ -123,7 +123,7 @@ public class SiteMapService( root.SetAttribute("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1"); doc.AppendChild(root); - foreach (var page in pages) + foreach (var page in pages.Where(p=>p.Indexing)) { string slugHtml = page.Slug; if (slugHtml.Contains(' ')) diff --git a/Netina.Core/EntityServices/OrderBagHandlers/AddToOrderBagCommandHandler.cs b/Netina.Core/EntityServices/OrderBagHandlers/AddToOrderBagCommandHandler.cs index 0479c74..60a87b2 100644 --- a/Netina.Core/EntityServices/OrderBagHandlers/AddToOrderBagCommandHandler.cs +++ b/Netina.Core/EntityServices/OrderBagHandlers/AddToOrderBagCommandHandler.cs @@ -31,7 +31,7 @@ public class AddToOrderBagCommandHandler( await mediator.Send(new CalculateProductDiscountCommand(productSDto), cancellationToken); orderBag.AddToOrderBag(productSDto.Id, productSDto.Cost, productSDto.CostWithDiscount, - productSDto.HasDiscount, productSDto.PackingCost, productSDto.CategoryId, requestDto.Count); + productSDto.HasDiscount, productSDto.PackingCost, productSDto.CategoryId,productSDto.BrandId, requestDto.Count); } repositoryWrapper.SetRepository().Update(orderBag); diff --git a/Netina.Core/EntityServices/OrderBagHandlers/SubmitOrderBagCommandHandler.cs b/Netina.Core/EntityServices/OrderBagHandlers/SubmitOrderBagCommandHandler.cs index 8386ca8..c816907 100644 --- a/Netina.Core/EntityServices/OrderBagHandlers/SubmitOrderBagCommandHandler.cs +++ b/Netina.Core/EntityServices/OrderBagHandlers/SubmitOrderBagCommandHandler.cs @@ -31,7 +31,7 @@ public class SubmitOrderBagCommandHandler( await mediator.Send(new CalculateProductDiscountCommand(productSDto), cancellationToken); orderBag.ChangeOrderBag(productSDto.Id, productSDto.Cost, productSDto.CostWithDiscount, - productSDto.HasDiscount, productSDto.PackingCost, productSDto.CategoryId, requestDto.Count); + productSDto.HasDiscount, productSDto.PackingCost, productSDto.CategoryId,productSDto.BrandId, requestDto.Count); } foreach (var orderProduct in orderBag.OrderProducts.ToList()) { diff --git a/Netina.Domain/Dtos/LargDtos/BasePageLDto.cs b/Netina.Domain/Dtos/LargDtos/BasePageLDto.cs new file mode 100644 index 0000000..32073f4 --- /dev/null +++ b/Netina.Domain/Dtos/LargDtos/BasePageLDto.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Netina.Domain.Dtos.LargDtos; +public class BasePageLDto : BaseDto +{ + public string Title { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string Content { get; set; } = string.Empty; + public bool IsCustomPage { get; set; } + public bool IsHtmlBasePage { get; set; } + public string Slug { get; set; } = string.Empty; + public string Data { get; set; } = string.Empty; + public DateTime ModifiedAt { get; set; } + public bool Indexing { get; set; } + public List Sections { get; set; } = new(); +} \ No newline at end of file diff --git a/Netina.Domain/Dtos/RequestDtos/PageActionRequestDto.cs b/Netina.Domain/Dtos/RequestDtos/PageActionRequestDto.cs index 8b0ca97..f4e7865 100644 --- a/Netina.Domain/Dtos/RequestDtos/PageActionRequestDto.cs +++ b/Netina.Domain/Dtos/RequestDtos/PageActionRequestDto.cs @@ -1,4 +1,6 @@ -namespace Netina.Domain.Dtos.RequestDtos; +using Netina.Domain.MartenEntities.Pages; + +namespace Netina.Domain.Dtos.RequestDtos; public class PageActionRequestDto { @@ -11,4 +13,6 @@ public class PageActionRequestDto public string Slug { get; set; } = string.Empty; public string Type { get; set; } = string.Empty; public object? Data { get; set; } + public bool Indexing { get; set; } + public List Sections { get; set; } = new(); } \ No newline at end of file diff --git a/Netina.Domain/Dtos/SmallDtos/BasePageSDto.cs b/Netina.Domain/Dtos/SmallDtos/BasePageSDto.cs index 994be04..6e098b6 100644 --- a/Netina.Domain/Dtos/SmallDtos/BasePageSDto.cs +++ b/Netina.Domain/Dtos/SmallDtos/BasePageSDto.cs @@ -1,5 +1,4 @@ -using Netina.Domain.MartenEntities.Pages; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Netina.Domain.Dtos.SmallDtos; @@ -13,6 +12,7 @@ public class BasePageSDto : BaseDto public string Slug { get; set; } = string.Empty; public string Data { get; set; } = string.Empty; public DateTime ModifiedAt { get; set; } + public bool Indexing { get; set; } = true; public T GetData() => JsonConvert.DeserializeObject(Data); } \ No newline at end of file diff --git a/Netina.Domain/Entities/Orders/Order.Aggregate.cs b/Netina.Domain/Entities/Orders/Order.Aggregate.cs index 2f35dfe..1b81c85 100644 --- a/Netina.Domain/Entities/Orders/Order.Aggregate.cs +++ b/Netina.Domain/Entities/Orders/Order.Aggregate.cs @@ -12,7 +12,11 @@ public partial class Order } - public void AddToOrderBag(Guid productId, double cost, double costWithDiscount, bool hasDiscount, double packingCost, + public void AddToOrderBag(Guid productId, + double cost, + double costWithDiscount, + bool hasDiscount, + double packingCost, Guid categoryId, Guid brandId, int count) diff --git a/Netina.Domain/MartenEntities/Pages/BasePage.cs b/Netina.Domain/MartenEntities/Pages/BasePage.cs index 704dd2b..be8fd48 100644 --- a/Netina.Domain/MartenEntities/Pages/BasePage.cs +++ b/Netina.Domain/MartenEntities/Pages/BasePage.cs @@ -10,4 +10,26 @@ public class BasePage : MartenEntity public string Slug { get; set; } = string.Empty; public string Type { get; set; } = string.Empty; public string Data { get; set; } = string.Empty; + public bool Indexing { get; set; } = true; + public List Sections { get; set; } = new(); +} + +public class BasePageSection +{ + public string Title { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string CTAText { get; set; } = string.Empty; + public string CTARoute { get; set; } = string.Empty; + public BasePageSectionType Type { get; set; } + public string Query { get; set; } = string.Empty; +} + +public enum BasePageSectionType +{ + [Display(Name = "اسلایدر محصولات")] + ProductSlider = 0, + [Display(Name = "اسلایدر دسته بندی محصولات")] + ProductCategorySlider = 1, + [Display(Name = "اسلایدر بلاگ ها")] + BlogSlider = 2 } \ No newline at end of file diff --git a/Netina.Domain/Netina.Domain.csproj b/Netina.Domain/Netina.Domain.csproj index 434d135..7206c71 100644 --- a/Netina.Domain/Netina.Domain.csproj +++ b/Netina.Domain/Netina.Domain.csproj @@ -83,6 +83,7 @@ +