From 34f2efa128c70c3e906141aa01fb97d6f0118662 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Mon, 1 Apr 2024 13:05:11 +0330 Subject: [PATCH] add version 0.17.21.34 , fix payment issues --- .version | 2 +- .../AppSettings/appsettings.Development.json | 4 +- NetinaShop.Api/Controller/SeedController.cs | 33 +------- .../Controller/SettingController.cs | 40 +++------ NetinaShop.Api/NetinaShop.Api.csproj | 28 +++---- .../MiddleWares/ExceptionHandlerMiddleware.cs | 10 ++- .../Models/Entity/IMartenEntity.cs | 9 ++ .../Models/Entity/MartenEntity.cs | 41 ++++++++++ NetinaShop.Common/NetinaShop.Common.csproj | 10 +-- .../CoreServices/Abstracts/IPageService.cs | 8 +- .../CoreServices/Abstracts/ISettingService.cs | 7 ++ NetinaShop.Core/CoreServices/PageService.cs | 37 ++++----- .../CoreServices/SettingService.cs | 59 +++++++++++++ NetinaShop.Core/NetinaShop.Core.csproj | 13 ++- ...{BasePageEntitySDto.cs => BasePageSDto.cs} | 4 +- .../Pages/BasePage.cs} | 7 +- .../Pages/FAQPage.cs | 4 +- .../MartenEntities/Settings/BaseSetting.cs | 8 ++ .../Settings/PaymentSetting.cs | 3 +- .../MartenEntities/Settings/ShopSetting.cs | 12 +++ NetinaShop.Domain/NetinaShop.Domain.csproj | 10 +-- .../Marten/MartenRepository.cs | 58 +++++++++++++ .../Marten/MartenRepositoryWrapper.cs | 16 ++++ .../NetinaShop.Infrastructure.csproj | 6 +- .../Services/Scrapers/DigikalaScraper.cs | 1 - .../Services/ZarinpalService.cs | 2 +- .../NetinaShop - Backup.Repository.csproj | 82 +++++++++++++++++++ .../NetinaShop.Repository.csproj | 14 ++-- .../Entity/Abstracts/IMartenRepository.cs | 15 ---- .../Repositories/Entity/MartenRepository.cs | 60 -------------- .../Repositories/Marten/IMartenRepository.cs | 15 ++++ .../Marten/IMartenRepositoryWrapper.cs | 6 ++ 32 files changed, 409 insertions(+), 215 deletions(-) create mode 100644 NetinaShop.Common/Models/Entity/IMartenEntity.cs create mode 100644 NetinaShop.Common/Models/Entity/MartenEntity.cs create mode 100644 NetinaShop.Core/CoreServices/Abstracts/ISettingService.cs create mode 100644 NetinaShop.Core/CoreServices/SettingService.cs rename NetinaShop.Domain/Dtos/SmallDtos/{BasePageEntitySDto.cs => BasePageSDto.cs} (80%) rename NetinaShop.Domain/{Entities/Pages/BasePageEntity.cs => MartenEntities/Pages/BasePage.cs} (75%) rename NetinaShop.Domain/{Entities => MartenEntities}/Pages/FAQPage.cs (76%) create mode 100644 NetinaShop.Domain/MartenEntities/Settings/BaseSetting.cs rename NetinaShop.Domain/{Entities => MartenEntities}/Settings/PaymentSetting.cs (72%) create mode 100644 NetinaShop.Domain/MartenEntities/Settings/ShopSetting.cs create mode 100644 NetinaShop.Infrastructure/Marten/MartenRepository.cs create mode 100644 NetinaShop.Infrastructure/Marten/MartenRepositoryWrapper.cs create mode 100644 NetinaShop.Repository/NetinaShop - Backup.Repository.csproj delete mode 100644 NetinaShop.Repository/Repositories/Entity/Abstracts/IMartenRepository.cs delete mode 100644 NetinaShop.Repository/Repositories/Entity/MartenRepository.cs create mode 100644 NetinaShop.Repository/Repositories/Marten/IMartenRepository.cs create mode 100644 NetinaShop.Repository/Repositories/Marten/IMartenRepositoryWrapper.cs diff --git a/.version b/.version index a2c8172..bb7aa56 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.17.20.33 \ No newline at end of file +0.17.21.34 \ No newline at end of file diff --git a/NetinaShop.Api/AppSettings/appsettings.Development.json b/NetinaShop.Api/AppSettings/appsettings.Development.json index 1e6b2e5..b179df8 100644 --- a/NetinaShop.Api/AppSettings/appsettings.Development.json +++ b/NetinaShop.Api/AppSettings/appsettings.Development.json @@ -17,8 +17,8 @@ "TaxesFee": 9 }, "SiteSettings": { - "BaseUrl": "http://192.168.88.251:32770", - "AdminPanelBaseUrl": "https://admin.vesmook.com", + "BaseUrl": "http://localhost:32770", + "AdminPanelBaseUrl": "https://admin.vesmeh.com", "KaveNegarApiKey": "3735494B4143727A794346457461576A2B4B6668414973424E333561505A694B", "UserSetting": { "Username": "netinashop", diff --git a/NetinaShop.Api/Controller/SeedController.cs b/NetinaShop.Api/Controller/SeedController.cs index 277762a..e132758 100644 --- a/NetinaShop.Api/Controller/SeedController.cs +++ b/NetinaShop.Api/Controller/SeedController.cs @@ -6,38 +6,9 @@ public class SeedController : ICarterModule { public void AddRoutes(IEndpointRouteBuilder app) { - var group = app.NewVersionedApi("Seed") - .MapGroup("api/seed"); + //var group = app.NewVersionedApi("Seed") + // .MapGroup("api/seed"); - group.MapGet("test1", () => - { - return TypedResults.BadRequest(new ApiResult(false, ApiResultStatusCode.ServerError, - "Server Error 1 ( BAD REQUEST )")); - }) - .WithDisplayName("SeedCategoriesAsync") - .HasApiVersion(1.0); - - group.MapGet("test2", () => - { - throw new Exception("Server Error 2 ( EXCEPTION THROWN )"); - }) - .WithDisplayName("SeedCategoriesAsync") - .HasApiVersion(1.0); - - group.MapGet("test3", () => - { - return TypedResults.Problem("Server Error 2 ( EXCEPTION THROWN )"); - }) - .WithDisplayName("SeedCategoriesAsync") - .HasApiVersion(1.0); - - - group.MapGet("test3", () => - { - return TypedResults.StatusCode(500); - }) - .WithDisplayName("SeedCategoriesAsync") - .HasApiVersion(1.0); //group.MapPost("categories", SeedCategoriesAsync) // .WithDisplayName("SeedCategoriesAsync") diff --git a/NetinaShop.Api/Controller/SettingController.cs b/NetinaShop.Api/Controller/SettingController.cs index 37694dc..507d825 100644 --- a/NetinaShop.Api/Controller/SettingController.cs +++ b/NetinaShop.Api/Controller/SettingController.cs @@ -1,6 +1,4 @@ -using System.Reflection; -using System.Text.Json; -using NetinaShop.Repository.Repositories.Entity.Abstracts; +using System.Text.Json; namespace NetinaShop.Api.Controller; @@ -9,43 +7,25 @@ public class SettingController : ICarterModule public void AddRoutes(IEndpointRouteBuilder app) { var group = app.NewVersionedApi("Setting") - .MapGroup("api/setting") - .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()); + .MapGroup("api/setting"); group.MapGet("{settingName}", GetSettingAsync) .WithDisplayName("GetSetting") + .RequireAuthorization(builder=>builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()) .HasApiVersion(1.0); + group.MapPost("{settingName}", PostSettingAsync) .WithDisplayName("PostSettingAsync") + .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()) .HasApiVersion(1.0); } - public async Task GetSettingAsync(string settingName, [FromServices] IMartenRepository martenRepository, CancellationToken cancellationToken) + public async Task GetSettingAsync(string settingName, [FromServices] ISettingService settingService, CancellationToken cancellationToken) + => TypedResults.Ok(await settingService.GetSettingAsync(settingName, cancellationToken)); + + public async Task PostSettingAsync(string settingName, [FromBody]JsonDocument settingObj, [FromServices]ISettingService settingService, CancellationToken cancellationToken) { - var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"NetinaShop.Domain.Entities.Settings.{settingName}"); - if (type == null) - throw new AppException("Setting not found", ApiResultStatusCode.NotFound); - - var setting = await ((dynamic)martenRepository.GetType()?.GetMethod("GetEntityAsync") - ?.MakeGenericMethod(type) - .Invoke(martenRepository,new object[]{ cancellationToken })!); - if (setting == null) - setting = Activator.CreateInstance(type); - - return TypedResults.Ok(setting); - } - - public async Task PostSettingAsync(string settingName, [FromBody]JsonDocument settingObj, [FromServices] IMartenRepository martenRepository, CancellationToken cancellationToken) - { - var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"NetinaShop.Domain.Entities.Settings.{settingName}"); - if (type == null) - throw new AppException("Setting not found", ApiResultStatusCode.NotFound); - var setting = settingObj.Deserialize(type); - if (setting == null) - throw new AppException("Setting not found", ApiResultStatusCode.NotFound); - await ((dynamic)martenRepository.GetType().GetMethod("AddOrUpdateEntityAsync") - ?.MakeGenericMethod(type).Invoke(martenRepository, new[] { setting , cancellationToken })!); - + await settingService.CreateOrUpdateSettingAsync(settingName, settingObj,cancellationToken); return TypedResults.Ok(); } } \ No newline at end of file diff --git a/NetinaShop.Api/NetinaShop.Api.csproj b/NetinaShop.Api/NetinaShop.Api.csproj index abfed67..e3212f9 100644 --- a/NetinaShop.Api/NetinaShop.Api.csproj +++ b/NetinaShop.Api/NetinaShop.Api.csproj @@ -6,43 +6,43 @@ enable true Linux - 0.17.20.33 - 0.17.20.33 + 0.17.21.34 + 0.17.21.34 - + - + - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + - + - + @@ -50,9 +50,9 @@ - + - + diff --git a/NetinaShop.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs b/NetinaShop.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs index b3b6ac3..0017063 100644 --- a/NetinaShop.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs +++ b/NetinaShop.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs @@ -145,7 +145,10 @@ public class ExceptionHandlerMiddleware Formatting = Formatting.Indented }); - context.Response.StatusCode = 501; + if (httpStatusCode == HttpStatusCode.InternalServerError) + context.Response.StatusCode = 501; + else + context.Response.StatusCode = (int)httpStatusCode; context.Response.ContentType = "application/json"; await context.Response.WriteAsJsonAsync(result); } @@ -171,7 +174,10 @@ public class ExceptionHandlerMiddleware Formatting = Formatting.Indented }); - context.Response.StatusCode = 501; + if (httpStatusCode == HttpStatusCode.InternalServerError) + context.Response.StatusCode = 501; + else + context.Response.StatusCode = (int)httpStatusCode; context.Response.ContentType = "application/json"; await context.Response.WriteAsJsonAsync(result); } diff --git a/NetinaShop.Common/Models/Entity/IMartenEntity.cs b/NetinaShop.Common/Models/Entity/IMartenEntity.cs new file mode 100644 index 0000000..c3f77be --- /dev/null +++ b/NetinaShop.Common/Models/Entity/IMartenEntity.cs @@ -0,0 +1,9 @@ +namespace NetinaShop.Common.Models.Entity; + +public interface IMartenEntity +{ + string CreatedBy { get; } + string ModifiedBy { get; } + DateTime CreatedAt { get; } + DateTime ModifiedAt { get; } +} \ No newline at end of file diff --git a/NetinaShop.Common/Models/Entity/MartenEntity.cs b/NetinaShop.Common/Models/Entity/MartenEntity.cs new file mode 100644 index 0000000..98eaa03 --- /dev/null +++ b/NetinaShop.Common/Models/Entity/MartenEntity.cs @@ -0,0 +1,41 @@ +namespace NetinaShop.Common.Models.Entity; + +public class MartenEntity : IMartenEntity +{ + public Guid Id { get; set; } + + + [Display(Name = "تاریخ ساخت")] + public DateTime CreatedAt { get; set; } + + [Display(Name = "ساخته شده توسط")] + public string CreatedBy { get; set; } = string.Empty; + + [Display(Name = "اخرین تغییر در")] + public DateTime ModifiedAt { get; set; } + + [Display(Name = "اخرین تغییر توسط")] + public string ModifiedBy { get; set; } = string.Empty; + + + + public bool Equals(ApiEntity other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Id.Equals(other.Id); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((ApiEntity)obj); + } + + public override int GetHashCode() + { + return Id.GetHashCode(); + } +} \ No newline at end of file diff --git a/NetinaShop.Common/NetinaShop.Common.csproj b/NetinaShop.Common/NetinaShop.Common.csproj index 346c5b2..dbe9777 100644 --- a/NetinaShop.Common/NetinaShop.Common.csproj +++ b/NetinaShop.Common/NetinaShop.Common.csproj @@ -1,6 +1,6 @@  - + + - + diff --git a/NetinaShop.Core/CoreServices/Abstracts/IPageService.cs b/NetinaShop.Core/CoreServices/Abstracts/IPageService.cs index 6a4cc1a..d2a20f3 100644 --- a/NetinaShop.Core/CoreServices/Abstracts/IPageService.cs +++ b/NetinaShop.Core/CoreServices/Abstracts/IPageService.cs @@ -1,10 +1,8 @@ -using NetinaShop.Domain.Entities.Pages; - -namespace NetinaShop.Core.CoreServices.Abstracts; +namespace NetinaShop.Core.CoreServices.Abstracts; public interface IPageService : IScopedDependency { - Task GetPageAsync(Guid? id = null, string? pageName = null, string? pageSlug = null,string? type = null, CancellationToken cancellationToken=default); - Task> GetPagesAsync(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); } \ No newline at end of file diff --git a/NetinaShop.Core/CoreServices/Abstracts/ISettingService.cs b/NetinaShop.Core/CoreServices/Abstracts/ISettingService.cs new file mode 100644 index 0000000..88b7622 --- /dev/null +++ b/NetinaShop.Core/CoreServices/Abstracts/ISettingService.cs @@ -0,0 +1,7 @@ +namespace NetinaShop.Core.CoreServices.Abstracts; + +public interface ISettingService : IScopedDependency +{ + public Task GetSettingAsync(string settingName, CancellationToken cancellationToken = default); + public Task CreateOrUpdateSettingAsync(string settingName, JsonDocument settingObj, CancellationToken cancellationToken = default); +} diff --git a/NetinaShop.Core/CoreServices/PageService.cs b/NetinaShop.Core/CoreServices/PageService.cs index 62befc3..204f9ee 100644 --- a/NetinaShop.Core/CoreServices/PageService.cs +++ b/NetinaShop.Core/CoreServices/PageService.cs @@ -1,36 +1,35 @@ using System.Reflection; using System.Text.Json; -using Microsoft.AspNetCore.Mvc.RazorPages; using NetinaShop.Domain; -using NetinaShop.Domain.Entities.Pages; -using NetinaShop.Repository.Repositories.Entity.Abstracts; +using NetinaShop.Domain.MartenEntities.Pages; +using NetinaShop.Repository.Repositories.Marten; namespace NetinaShop.Core.CoreServices; public class PageService : IPageService { - private readonly IMartenRepository _martenRepository; + private readonly IMartenRepositoryWrapper _martenRepositoryWrapper; - public PageService(IMartenRepository martenRepository) + public PageService(IMartenRepositoryWrapper martenRepositoryWrapperWrapper) { - _martenRepository = martenRepository; + _martenRepositoryWrapper = martenRepositoryWrapperWrapper; } - 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) { - BasePageEntity? page = null; + BasePage? page = null; if (id != null) - page = await _martenRepository.GetEntityAsync(id.Value, cancellationToken); + page = await _martenRepositoryWrapper.SetRepository().GetEntityAsync(id.Value, cancellationToken); else if (pageSlug != null) - page = await _martenRepository.GetEntityAsync(entity => entity.Slug == pageSlug, cancellationToken); + page = await _martenRepositoryWrapper.SetRepository().GetEntityAsync(entity => entity.Slug == pageSlug, cancellationToken); else if (pageName != null) - page = await _martenRepository.GetEntityAsync(entity => entity.Name == pageName, cancellationToken); + page = await _martenRepositoryWrapper.SetRepository().GetEntityAsync(entity => entity.Name == pageName, cancellationToken); else if (type != null) - page = await _martenRepository.GetEntityAsync(entity => entity.Type == type, cancellationToken); + page = await _martenRepositoryWrapper.SetRepository().GetEntityAsync(entity => entity.Type == type, cancellationToken); if (page == null) throw new AppException("Page not found", ApiResultStatusCode.NotFound); var entityType = Assembly.GetAssembly(typeof(DomainConfig))?.GetType(page.Type); - var dto = new BasePageEntitySDto + var dto = new BasePageSDto { Content = page.Content, Description = page.Description, @@ -45,15 +44,15 @@ public class PageService : IPageService return dto; } - public async Task> GetPagesAsync(CancellationToken cancellationToken = default) + public async Task> GetPagesAsync(CancellationToken cancellationToken = default) { - List sDtos = new List(); - var pages = await _martenRepository.GetEntitiesAsync(cancellationToken); + List sDtos = new List(); + var pages = await _martenRepositoryWrapper.SetRepository().GetEntitiesAsync(cancellationToken); foreach (var page in pages) { var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType(page.Type); - var dto = new BasePageEntitySDto + var dto = new BasePageSDto { Content = page.Content, Description = page.Description, @@ -71,7 +70,7 @@ public class PageService : IPageService public async Task CreatePageAsync(PageActionRequestDto entity, CancellationToken cancellationToken = default) { - var basePage = new BasePageEntity + var basePage = new BasePage { Content = entity.Content, Description = entity.Description, @@ -84,7 +83,7 @@ public class PageService : IPageService }; var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType(entity.Type); basePage.Data = JsonConvert.SerializeObject(((JsonElement)entity.Data).Deserialize(type)); - await _martenRepository.AddOrUpdateEntityAsync(basePage, cancellationToken); + await _martenRepositoryWrapper.SetRepository().AddOrUpdateEntityAsync(basePage, cancellationToken); return true; } } \ No newline at end of file diff --git a/NetinaShop.Core/CoreServices/SettingService.cs b/NetinaShop.Core/CoreServices/SettingService.cs new file mode 100644 index 0000000..6b01239 --- /dev/null +++ b/NetinaShop.Core/CoreServices/SettingService.cs @@ -0,0 +1,59 @@ +namespace NetinaShop.Core.CoreServices; + + +public class SettingService : ISettingService +{ + private readonly IMartenRepositoryWrapper _martenRepositoryWrapper; + + public SettingService(IMartenRepositoryWrapper martenRepositoryWrapper) + { + _martenRepositoryWrapper = martenRepositoryWrapper; + } + + public async Task GetSettingAsync(string settingName, CancellationToken cancellationToken = default) + { + var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"NetinaShop.Domain.MartenEntities.Settings.{settingName}"); + if (type == null) + throw new AppException("Setting not found", ApiResultStatusCode.NotFound); + + var baseSetting = await _martenRepositoryWrapper.SetRepository() + .GetEntityAsync(s => s.Name == settingName, cancellationToken); + object? setting; + if (baseSetting == null) + setting = Activator.CreateInstance(type); + else + setting = JsonConvert.DeserializeObject(baseSetting.JsonData, type) ?? Activator.CreateInstance(type); + + if (setting == null) + throw new AppException("Setting type or base is wrong"); + + return setting; + } + + public async Task CreateOrUpdateSettingAsync(string settingName, JsonDocument settingObj, CancellationToken cancellationToken = default) + { + var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"NetinaShop.Domain.MartenEntities.Settings.{settingName}"); + if (type == null) + throw new AppException("Setting not found", ApiResultStatusCode.NotFound); + + var baseSetting = await _martenRepositoryWrapper.SetRepository() + .GetEntityAsync(s => s.Name == settingName, cancellationToken); + + if (baseSetting == null) + { + baseSetting = new BaseSetting + { + JsonData = JsonConvert.SerializeObject(settingObj.Deserialize(type)), + Name = settingName, + DotnetType = type.FullName ?? $"NetinaShop.Domain.MartenEntities.Settings.{settingName}" + }; + } + else + { + baseSetting.JsonData = JsonConvert.SerializeObject(settingObj.Deserialize(type)); + } + + await _martenRepositoryWrapper.SetRepository() + .AddOrUpdateEntityAsync(baseSetting, cancellationToken); + } +} \ No newline at end of file diff --git a/NetinaShop.Core/NetinaShop.Core.csproj b/NetinaShop.Core/NetinaShop.Core.csproj index 8695861..4552ed3 100644 --- a/NetinaShop.Core/NetinaShop.Core.csproj +++ b/NetinaShop.Core/NetinaShop.Core.csproj @@ -10,11 +10,11 @@ - + - - - + + + @@ -48,6 +48,7 @@ + @@ -60,14 +61,18 @@ + + + + diff --git a/NetinaShop.Domain/Dtos/SmallDtos/BasePageEntitySDto.cs b/NetinaShop.Domain/Dtos/SmallDtos/BasePageSDto.cs similarity index 80% rename from NetinaShop.Domain/Dtos/SmallDtos/BasePageEntitySDto.cs rename to NetinaShop.Domain/Dtos/SmallDtos/BasePageSDto.cs index b21766c..252f76c 100644 --- a/NetinaShop.Domain/Dtos/SmallDtos/BasePageEntitySDto.cs +++ b/NetinaShop.Domain/Dtos/SmallDtos/BasePageSDto.cs @@ -1,9 +1,9 @@ -using NetinaShop.Domain.Entities.Pages; +using NetinaShop.Domain.MartenEntities.Pages; using Newtonsoft.Json; namespace NetinaShop.Domain.Dtos.SmallDtos; -public class BasePageEntitySDto : BaseDto +public class BasePageSDto : BaseDto { public string Name { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; diff --git a/NetinaShop.Domain/Entities/Pages/BasePageEntity.cs b/NetinaShop.Domain/MartenEntities/Pages/BasePage.cs similarity index 75% rename from NetinaShop.Domain/Entities/Pages/BasePageEntity.cs rename to NetinaShop.Domain/MartenEntities/Pages/BasePage.cs index e6d33c5..23ac83e 100644 --- a/NetinaShop.Domain/Entities/Pages/BasePageEntity.cs +++ b/NetinaShop.Domain/MartenEntities/Pages/BasePage.cs @@ -1,10 +1,7 @@ -using System.Text.Json; +namespace NetinaShop.Domain.MartenEntities.Pages; -namespace NetinaShop.Domain.Entities.Pages; - -public class BasePageEntity +public class BasePage : MartenEntity { - public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public string Content { get; set; } = string.Empty; diff --git a/NetinaShop.Domain/Entities/Pages/FAQPage.cs b/NetinaShop.Domain/MartenEntities/Pages/FAQPage.cs similarity index 76% rename from NetinaShop.Domain/Entities/Pages/FAQPage.cs rename to NetinaShop.Domain/MartenEntities/Pages/FAQPage.cs index d8dd156..72c113c 100644 --- a/NetinaShop.Domain/Entities/Pages/FAQPage.cs +++ b/NetinaShop.Domain/MartenEntities/Pages/FAQPage.cs @@ -1,5 +1,5 @@ -namespace NetinaShop.Domain.Entities.Pages; - +namespace NetinaShop.Domain.MartenEntities.Pages; + [PageClassDisplay("FAQPage", "صفحه سوالات متداول")] public class FAQPage { diff --git a/NetinaShop.Domain/MartenEntities/Settings/BaseSetting.cs b/NetinaShop.Domain/MartenEntities/Settings/BaseSetting.cs new file mode 100644 index 0000000..536c627 --- /dev/null +++ b/NetinaShop.Domain/MartenEntities/Settings/BaseSetting.cs @@ -0,0 +1,8 @@ +namespace NetinaShop.Domain.MartenEntities.Settings; + +public class BaseSetting : MartenEntity +{ + public string Name { get; set; } = string.Empty; + public string JsonData { get; set; } = string.Empty; + public string DotnetType { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/NetinaShop.Domain/Entities/Settings/PaymentSetting.cs b/NetinaShop.Domain/MartenEntities/Settings/PaymentSetting.cs similarity index 72% rename from NetinaShop.Domain/Entities/Settings/PaymentSetting.cs rename to NetinaShop.Domain/MartenEntities/Settings/PaymentSetting.cs index b7bf677..43261e1 100644 --- a/NetinaShop.Domain/Entities/Settings/PaymentSetting.cs +++ b/NetinaShop.Domain/MartenEntities/Settings/PaymentSetting.cs @@ -1,8 +1,7 @@ -namespace NetinaShop.Domain.Entities.Settings; +namespace NetinaShop.Domain.MartenEntities.Settings; public class PaymentSetting { - public Guid Id { get; set; } public string ZarinPalApiKey { get; set; } = string.Empty; public string PayPalApiKey { get; set; } = string.Empty; public string BehPardakhtApiKey { get; set; } = string.Empty; diff --git a/NetinaShop.Domain/MartenEntities/Settings/ShopSetting.cs b/NetinaShop.Domain/MartenEntities/Settings/ShopSetting.cs new file mode 100644 index 0000000..d14d3ce --- /dev/null +++ b/NetinaShop.Domain/MartenEntities/Settings/ShopSetting.cs @@ -0,0 +1,12 @@ +namespace NetinaShop.Domain.MartenEntities.Settings; + +public class ShopSetting +{ + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string Slogan { get; set; } = string.Empty; + public double LocationLat { get; set; } + public double LocationLon { get; set; } + public string Address { get; set; } = string.Empty; + public string SupportPhoneNumber { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/NetinaShop.Domain/NetinaShop.Domain.csproj b/NetinaShop.Domain/NetinaShop.Domain.csproj index a525d20..63cffcb 100644 --- a/NetinaShop.Domain/NetinaShop.Domain.csproj +++ b/NetinaShop.Domain/NetinaShop.Domain.csproj @@ -1,6 +1,6 @@  - + - + diff --git a/NetinaShop.Infrastructure/Marten/MartenRepository.cs b/NetinaShop.Infrastructure/Marten/MartenRepository.cs new file mode 100644 index 0000000..d636a0b --- /dev/null +++ b/NetinaShop.Infrastructure/Marten/MartenRepository.cs @@ -0,0 +1,58 @@ +using Marten; + +namespace NetinaShop.Infrastructure.Marten; + +public class MartenRepository : IMartenRepository where TMartenEntity : IMartenEntity +{ + private readonly IDocumentStore _documentStore; + + public MartenRepository(IDocumentStore documentStore) + { + _documentStore = documentStore; + } + + public async Task> GetEntitiesAsync(CancellationToken cancellation) + { + await using var session = _documentStore.QuerySession(); + var entities = await session.Query().ToListAsync(cancellation); + return entities.ToList(); + } + + public async Task> GetEntitiesAsync(Expression> expression, CancellationToken cancellation) + { + await using var session = _documentStore.QuerySession(); + var entities = await session.Query().Where(expression).ToListAsync(cancellation); + return entities.ToList(); + } + + public async Task GetEntityAsync(Guid id, CancellationToken cancellation) + { + await using var session = _documentStore.QuerySession(); + var setting = await session.LoadAsync(id, cancellation); + if (setting == null) + throw new AppException($"{nameof(setting)} not found", ApiResultStatusCode.NotFound); + return setting; + } + + public async Task GetEntityAsync(Expression> expression, CancellationToken cancellation) + { + await using var session = _documentStore.QuerySession(); + var entity = await session.Query().FirstOrDefaultAsync(expression, cancellation); + return entity; + } + + public async Task AddOrUpdateEntityAsync(TMartenEntity setting, CancellationToken cancellation) + { + if (setting == null) + throw new AppException($"{nameof(setting)} is null", ApiResultStatusCode.BadRequest); + + await using var session = _documentStore.LightweightSession(); + session.Store(setting); + await session.SaveChangesAsync(cancellation); + } + + public Task RemoveEntityAsync(CancellationToken cancellation) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/NetinaShop.Infrastructure/Marten/MartenRepositoryWrapper.cs b/NetinaShop.Infrastructure/Marten/MartenRepositoryWrapper.cs new file mode 100644 index 0000000..a363f02 --- /dev/null +++ b/NetinaShop.Infrastructure/Marten/MartenRepositoryWrapper.cs @@ -0,0 +1,16 @@ +using Marten; + +namespace NetinaShop.Infrastructure.Marten; + +public class MartenRepositoryWrapper : IMartenRepositoryWrapper +{ + private readonly IDocumentStore _documentStore; + + public MartenRepositoryWrapper(IDocumentStore documentStore) + { + _documentStore = documentStore; + } + + public IMartenRepository SetRepository() where TMartenEntity : IMartenEntity + => new MartenRepository(_documentStore); +} \ No newline at end of file diff --git a/NetinaShop.Infrastructure/NetinaShop.Infrastructure.csproj b/NetinaShop.Infrastructure/NetinaShop.Infrastructure.csproj index ff37125..30ed8bc 100644 --- a/NetinaShop.Infrastructure/NetinaShop.Infrastructure.csproj +++ b/NetinaShop.Infrastructure/NetinaShop.Infrastructure.csproj @@ -8,7 +8,8 @@ - + + @@ -27,12 +28,15 @@ + + + diff --git a/NetinaShop.Infrastructure/Services/Scrapers/DigikalaScraper.cs b/NetinaShop.Infrastructure/Services/Scrapers/DigikalaScraper.cs index 10d9421..004658d 100644 --- a/NetinaShop.Infrastructure/Services/Scrapers/DigikalaScraper.cs +++ b/NetinaShop.Infrastructure/Services/Scrapers/DigikalaScraper.cs @@ -3,7 +3,6 @@ using NetinaShop.Domain.Dtos.ScraperDtos.Response; using NetinaShop.Domain.Dtos.SmallDtos; using NetinaShop.Domain.Entities.Products; using NetinaShop.Repository.Repositories.Base.Contracts; -using System.Linq; using MediatR; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; diff --git a/NetinaShop.Infrastructure/Services/ZarinpalService.cs b/NetinaShop.Infrastructure/Services/ZarinpalService.cs index fc52e11..6147b07 100644 --- a/NetinaShop.Infrastructure/Services/ZarinpalService.cs +++ b/NetinaShop.Infrastructure/Services/ZarinpalService.cs @@ -23,7 +23,7 @@ public class ZarinpalService : IPaymentService { description = $"پرداخت {amount.ToString("N0")} ریال توسط {fullName} با شماره تماس {phoneNumber} برای سفارش با شماره {factorNumber}", amount = (int)amount, - callback_url = Path.Combine("https://api.vesmook.com", "api", "accounting", "pay", "verify"), + callback_url = Path.Combine(_siteSettings.BaseUrl, "api", "accounting", "pay", "verify"), merchant_id = "4292b845-b510-4d1d-8ee2-097499b198e5", metadata = new ZarinaplPaymentLinkRequestMetadata { mobile = phoneNumber } }; diff --git a/NetinaShop.Repository/NetinaShop - Backup.Repository.csproj b/NetinaShop.Repository/NetinaShop - Backup.Repository.csproj new file mode 100644 index 0000000..e435894 --- /dev/null +++ b/NetinaShop.Repository/NetinaShop - Backup.Repository.csproj @@ -0,0 +1,82 @@ + + + + net8.0 + enable + enable + + + +x + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NetinaShop.Repository/NetinaShop.Repository.csproj b/NetinaShop.Repository/NetinaShop.Repository.csproj index 7d06a92..d6f4b54 100644 --- a/NetinaShop.Repository/NetinaShop.Repository.csproj +++ b/NetinaShop.Repository/NetinaShop.Repository.csproj @@ -8,23 +8,22 @@ - - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + @@ -70,7 +69,6 @@ - diff --git a/NetinaShop.Repository/Repositories/Entity/Abstracts/IMartenRepository.cs b/NetinaShop.Repository/Repositories/Entity/Abstracts/IMartenRepository.cs deleted file mode 100644 index 3824d24..0000000 --- a/NetinaShop.Repository/Repositories/Entity/Abstracts/IMartenRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Linq.Expressions; - -namespace NetinaShop.Repository.Repositories.Entity.Abstracts; - -public interface IMartenRepository : IScopedDependency -{ - Task> GetEntitiesAsync(CancellationToken cancellation) where TSetting : notnull; - Task> GetEntitiesAsync(Expression> expression,CancellationToken cancellation) where TSetting : notnull; - - Task GetEntityAsync(Guid id,CancellationToken cancellation) where TSetting : notnull; - Task GetEntityAsync(Expression> expression, CancellationToken cancellation) where TSetting : notnull; - - Task AddOrUpdateEntityAsync(TSetting setting, CancellationToken cancellation) where TSetting : notnull; - Task RemoveEntityAsync(CancellationToken cancellation); -} \ No newline at end of file diff --git a/NetinaShop.Repository/Repositories/Entity/MartenRepository.cs b/NetinaShop.Repository/Repositories/Entity/MartenRepository.cs deleted file mode 100644 index eb13011..0000000 --- a/NetinaShop.Repository/Repositories/Entity/MartenRepository.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Linq.Expressions; -using Marten; - -namespace NetinaShop.Repository.Repositories.Entity; - -public class MartenRepository : IMartenRepository -{ - private readonly IDocumentStore _documentStore; - - public MartenRepository(IDocumentStore documentStore) - { - _documentStore = documentStore; - } - public async Task> GetEntitiesAsync(CancellationToken cancellation) where TSetting : notnull - { - await using var session = _documentStore.QuerySession(); - var entities = await session.Query().ToListAsync(cancellation); - return entities.ToList(); - } - - public async Task> GetEntitiesAsync(Expression> expression, CancellationToken cancellation) where TSetting : notnull - { - await using var session = _documentStore.QuerySession(); - var entities = await session.Query().Where(expression).ToListAsync(cancellation); - return entities.ToList(); - } - - public async Task GetEntityAsync(Guid id,CancellationToken cancellation) where TSetting : notnull - { - await using var session = _documentStore.QuerySession(); - var setting = await session.LoadAsync(id,cancellation); - if (setting == null) - throw new AppException($"{nameof(setting)} not found", ApiResultStatusCode.NotFound); - return setting; - } - - public async Task GetEntityAsync(Expression> expression, CancellationToken cancellation) where TSetting : notnull - { - await using var session = _documentStore.QuerySession(); - var entity = await session.Query().FirstOrDefaultAsync(expression,cancellation); - if (entity == null) - throw new AppException($"{nameof(entity)} not found", ApiResultStatusCode.NotFound); - return entity; - } - - public async Task AddOrUpdateEntityAsync(TSetting setting, CancellationToken cancellation) where TSetting : notnull - { - if (setting == null) - throw new AppException($"{nameof(setting)} is null", ApiResultStatusCode.BadRequest); - - await using var session = _documentStore.LightweightSession(); - session.Store(setting); - await session.SaveChangesAsync(cancellation); - } - - public Task RemoveEntityAsync(CancellationToken cancellation) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/NetinaShop.Repository/Repositories/Marten/IMartenRepository.cs b/NetinaShop.Repository/Repositories/Marten/IMartenRepository.cs new file mode 100644 index 0000000..e2739c1 --- /dev/null +++ b/NetinaShop.Repository/Repositories/Marten/IMartenRepository.cs @@ -0,0 +1,15 @@ +using System.Linq.Expressions; + +namespace NetinaShop.Repository.Repositories.Marten; + +public interface IMartenRepository : IScopedDependency where TMartenEntity : IMartenEntity +{ + Task> GetEntitiesAsync(CancellationToken cancellation); + Task> GetEntitiesAsync(Expression> expression, CancellationToken cancellation); + + Task GetEntityAsync(Guid id, CancellationToken cancellation); + Task GetEntityAsync(Expression> expression, CancellationToken cancellation); + + Task AddOrUpdateEntityAsync(TMartenEntity setting, CancellationToken cancellation); + Task RemoveEntityAsync(CancellationToken cancellation); +} \ No newline at end of file diff --git a/NetinaShop.Repository/Repositories/Marten/IMartenRepositoryWrapper.cs b/NetinaShop.Repository/Repositories/Marten/IMartenRepositoryWrapper.cs new file mode 100644 index 0000000..9c49d29 --- /dev/null +++ b/NetinaShop.Repository/Repositories/Marten/IMartenRepositoryWrapper.cs @@ -0,0 +1,6 @@ +namespace NetinaShop.Repository.Repositories.Marten; + +public interface IMartenRepositoryWrapper : IScopedDependency +{ + IMartenRepository SetRepository() where TMartenEntity : IMartenEntity; +} \ No newline at end of file