feat : add version 0.22.25.43 , fix payment issue
parent
42d8f35940
commit
2210ba5f77
|
@ -3,28 +3,48 @@ using Netina.Common.Models.Exception;
|
|||
using Netina.Domain.CommandQueries.Commands;
|
||||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Netina.Domain.Dtos.SmallDtos;
|
||||
using Netina.Domain.Entities.Blogs;
|
||||
using Netina.Repository.Repositories.Base;
|
||||
|
||||
namespace Netina.Api.Controller;
|
||||
|
||||
public class SeedController : ICarterModule
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public SeedController(IWebHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
}
|
||||
public void AddRoutes(IEndpointRouteBuilder app)
|
||||
{
|
||||
//var group = app.NewVersionedApi("Seed")
|
||||
// .MapGroup("api/seed");
|
||||
if (_environment.IsDevelopment())
|
||||
{
|
||||
var group = app.NewVersionedApi("Seed")
|
||||
.MapGroup("api/seed");
|
||||
|
||||
|
||||
//group.MapPost("categories", SeedCategoriesAsync)
|
||||
// .WithDisplayName("SeedCategoriesAsync")
|
||||
// .HasApiVersion(1.0);
|
||||
group.MapPost("product/categories", SeedCategoriesAsync)
|
||||
.WithDisplayName("SeedCategoriesAsync")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
//group.MapPost("brands", SeedBrandsAsync)
|
||||
// .WithDisplayName("SeedBrandsAsync")
|
||||
// .HasApiVersion(1.0);
|
||||
group.MapPost("product/brands", SeedBrandsAsync)
|
||||
.WithDisplayName("SeedBrandsAsync")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("products", SeedProductsAsync)
|
||||
.WithDisplayName("SeedProductsAsync")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("blogs", SeedBlogsAsync)
|
||||
.WithDisplayName("SeedBlogsAsync")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("blog/categories", SeedBlogCategoriesAsync)
|
||||
.WithDisplayName("SeedBlogCategoriesAsync")
|
||||
.HasApiVersion(1.0);
|
||||
}
|
||||
|
||||
//group.MapPost("products",SeedProductsAsync)
|
||||
// .WithDisplayName("SeedProductsAsync")
|
||||
// .HasApiVersion(1.0);
|
||||
|
||||
|
||||
}
|
||||
|
@ -82,4 +102,41 @@ public class SeedController : ICarterModule
|
|||
|
||||
return TypedResults.Ok(brands);
|
||||
}
|
||||
|
||||
public async Task<IResult> SeedBlogsAsync([FromBody] List<SeedBlogRequestDto> request, [FromQuery]string key,IRepositoryWrapper repositoryWrapper,CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")
|
||||
throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized);
|
||||
foreach (var seedBlogRequestDto in request)
|
||||
{
|
||||
var ent = Blog.Create(seedBlogRequestDto.Title, seedBlogRequestDto.Content, seedBlogRequestDto.Tags, seedBlogRequestDto.ReadingTime,
|
||||
seedBlogRequestDto.Summery, seedBlogRequestDto.IsSuggested, seedBlogRequestDto.CategoryId);
|
||||
repositoryWrapper.SetRepository<Blog>().Add(ent);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
||||
public async Task<IResult> SeedBlogCategoriesAsync([FromBody] List<SeedBlogCategoryRequestDto> request, [FromQuery] string key, [FromServices]IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")
|
||||
throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized);
|
||||
|
||||
Dictionary<int, Guid> categories = new Dictionary<int, Guid>();
|
||||
var baseCategory = BlogCategory.Create("دسته بندی نشده","دسته بندی برای بلاگ های دسته بندی نشده");
|
||||
repositoryWrapper.SetRepository<BlogCategory>().Add(baseCategory);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
categories.Add(0, baseCategory.Id);
|
||||
foreach (var requestDto in request)
|
||||
{
|
||||
var ent = BlogCategory.Create(requestDto.Name, requestDto.Description);
|
||||
repositoryWrapper.SetRepository<BlogCategory>().Add(ent);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
categories.Add(requestDto.BaseCategoryId, ent.Id);
|
||||
}
|
||||
|
||||
return TypedResults.Ok(categories);
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<AssemblyVersion>0.22.24.42</AssemblyVersion>
|
||||
<FileVersion>0.22.24.42</FileVersion>
|
||||
<AssemblyVersion>0.22.25.43</AssemblyVersion>
|
||||
<FileVersion>0.22.25.43</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -57,7 +57,7 @@ public static class ServiceExtensions
|
|||
serviceCollection.AddDbContextFactory<ApplicationContext>(options =>
|
||||
{
|
||||
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
options.UseNpgsql(Configuration.GetConnectionString("Postgres"), b => b.MigrationsAssembly("NetinaShop.Repository"))
|
||||
options.UseNpgsql(Configuration.GetConnectionString("Postgres"), b => b.MigrationsAssembly("Netina.Repository"))
|
||||
.UseProjectAssembly(typeof(ApplicationUser).Assembly);
|
||||
|
||||
//options.EnableServiceProviderCaching(true);
|
||||
|
|
|
@ -19,7 +19,7 @@ public class SettingService : ISettingService
|
|||
|
||||
public async Task<object> GetSettingAsync(string settingName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"NetinaShop.Domain.MartenEntities.Settings.{settingName}");
|
||||
var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"Netina.Domain.MartenEntities.Settings.{settingName}");
|
||||
if (type == null)
|
||||
throw new AppException("Setting not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class SettingService : ISettingService
|
|||
|
||||
public async Task CreateOrUpdateSettingAsync(string settingName, JsonDocument settingObj, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"NetinaShop.Domain.MartenEntities.Settings.{settingName}");
|
||||
var type = Assembly.GetAssembly(typeof(DomainConfig))?.GetType($"Netina.Domain.MartenEntities.Settings.{settingName}");
|
||||
if (type == null)
|
||||
throw new AppException("Setting not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class SettingService : ISettingService
|
|||
{
|
||||
JsonData = JsonConvert.SerializeObject(settingObj.Deserialize(type)),
|
||||
Name = settingName,
|
||||
DotnetType = type.FullName ?? $"NetinaShop.Domain.MartenEntities.Settings.{settingName}"
|
||||
DotnetType = type.FullName ?? $"Netina.Domain.MartenEntities.Settings.{settingName}"
|
||||
};
|
||||
}
|
||||
else
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
namespace Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
|
||||
public class SeedBlogRequestDto
|
||||
{
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public string Tags { get; set; } = string.Empty;
|
||||
public int ReadingTime { get; set; }
|
||||
public string Summery { get; set; } = string.Empty;
|
||||
public bool IsSuggested { get; set; }
|
||||
public Guid CategoryId { get; set; }
|
||||
}
|
||||
|
||||
public class SeedBlogCategoryRequestDto
|
||||
{
|
||||
public int BaseCategoryId { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
|
@ -73,8 +73,8 @@ public class ZarinpalService : IPaymentService
|
|||
merchant_id = paymentSetting.ZarinPalApiKey
|
||||
};
|
||||
var response = await _restApiWrapper.ZarinpalRestApi.VerifyPaymentAsync(request);
|
||||
//if (response.data.code != 100)
|
||||
// throw new AppException($"Exception in get link from zarinpal | {response.data.message}");
|
||||
if (response.data.code != 100)
|
||||
throw new AppException($"Exception in get link from zarinpal | {response.data.message}");
|
||||
|
||||
payment.Status = PaymentStatus.Paid;
|
||||
payment.CardPan = response.data.card_pan;
|
||||
|
|
|
@ -23,7 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConfigFiles", "ConfigFiles"
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{4B7737FD-3BFC-4C21-AB47-4BFAF1CD1EDA}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetinaShop.WordPressDBConverter", "Tools\NetinaShop.WordPressDBConverter\NetinaShop.WordPressDBConverter.csproj", "{5112E6D9-FA93-4CE0-95EE-A5F6B1DD52B6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Netina.WordPressDBConverter", "Tools\NetinaShop.WordPressDBConverter\Netina.WordPressDBConverter.csproj", "{5112E6D9-FA93-4CE0-95EE-A5F6B1DD52B6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.WordPressDBConverter.Models;
|
||||
namespace Netina.WordPressDBConverter.Models;
|
||||
|
||||
public class WordPressPostDto
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.WordPressDBConverter.Models;
|
||||
namespace Netina.WordPressDBConverter.Models;
|
||||
|
||||
public class WordPressPostMetaDto
|
||||
{
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
namespace Netina.WordPressDBConverter.Models;
|
||||
|
||||
public class WordPressPostTagDto
|
||||
{
|
||||
public int TermId { get; set; }
|
||||
public string Tag { get; set; } = string.Empty;
|
||||
public int PostId { get; set; }
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.WordPressDBConverter.Models;
|
||||
namespace Netina.WordPressDBConverter.Models;
|
||||
|
||||
public class WordPressTermDto
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.WordPressDBConverter.Models;
|
||||
namespace Netina.WordPressDBConverter.Models;
|
||||
|
||||
public class WordPressTermRelationDto
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.WordPressDBConverter.Models;
|
||||
namespace Netina.WordPressDBConverter.Models;
|
||||
|
||||
public class WordPressTermTaxonomyDto
|
||||
{
|
||||
|
|
|
@ -1,44 +1,121 @@
|
|||
using NetinaShop.WordPressDBConverter.Models;
|
||||
using NetinaShop.WordPressDBConverter.Services.RestServices;
|
||||
using Netina.Common.Extensions;
|
||||
using Netina.Domain.CommandQueries.Commands;
|
||||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Netina.Domain.Dtos.SmallDtos;
|
||||
using Netina.WordPressDBConverter.Models;
|
||||
using Netina.WordPressDBConverter.Services.RestServices;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
Console.ReadKey();
|
||||
var termReader = new StreamReader("F:\\wp_terms.json");
|
||||
var termJson = termReader.ReadToEnd();
|
||||
Console.WriteLine("Terms File Read Success !");
|
||||
var terms = JsonConvert.DeserializeObject<List<WordPressTermDto>>(termJson);
|
||||
if (terms == null)
|
||||
throw new Exception("Terms is null");
|
||||
|
||||
var termTaxonomyReader = new StreamReader("F:\\wp_term_taxonomy.json");
|
||||
var termTaxonomyJson = termTaxonomyReader.ReadToEnd();
|
||||
Console.WriteLine("Term Taxonomy File Read Success !");
|
||||
var termTaxonomies = JsonConvert.DeserializeObject<List<WordPressTermTaxonomyDto>>(termTaxonomyJson);
|
||||
if (termTaxonomies == null)
|
||||
throw new Exception("Term Taxonomies is null");
|
||||
|
||||
|
||||
var termRelationshipsReader = new StreamReader("F:\\wp_term_relationships.json");
|
||||
var termRelationshipsJson = termRelationshipsReader.ReadToEnd();
|
||||
Console.WriteLine("Term Relationships File Read Success !");
|
||||
var termRelationships = JsonConvert.DeserializeObject<List<WordPressTermRelationDto>>(termRelationshipsJson);
|
||||
if (termRelationships == null)
|
||||
throw new Exception("Term Relationships is null");
|
||||
|
||||
var postReader = new StreamReader("F:\\wp_posts.json");
|
||||
int j = 0;
|
||||
int i = 0;
|
||||
while (!postReader.EndOfStream)
|
||||
var json = postReader.ReadToEnd();
|
||||
Console.WriteLine("Post File Read Success !");
|
||||
var posts = JsonConvert.DeserializeObject<List<WordPressPostDto>>(json);
|
||||
if (posts == null)
|
||||
throw new Exception("Posts is null");
|
||||
|
||||
|
||||
//CREATE CATEGORY PART
|
||||
List<SeedBlogCategoryRequestDto> categories = new List<SeedBlogCategoryRequestDto>();
|
||||
List<WordPressPostTagDto> tags = new List<WordPressPostTagDto>();
|
||||
foreach (var taxonomy in termTaxonomies)
|
||||
{
|
||||
var postJson = await postReader.ReadLineAsync();
|
||||
if (postJson != null)
|
||||
if (taxonomy.taxonomy == "category")
|
||||
{
|
||||
try
|
||||
{
|
||||
var post = JsonConvert.DeserializeObject<WordPressPostDto>(postJson.Substring(0,postJson.Length-1));
|
||||
if (post != null)
|
||||
var term = terms.FirstOrDefault(t => t.term_id == taxonomy.term_id);
|
||||
if (term != null)
|
||||
categories.Add(new SeedBlogCategoryRequestDto
|
||||
{
|
||||
BaseCategoryId = term.term_id.ToInt(),
|
||||
Description = taxonomy.description,
|
||||
Name = term.name
|
||||
});
|
||||
}
|
||||
|
||||
if (post.post_type == "page")
|
||||
{
|
||||
|
||||
Console.WriteLine($"Page number : {j++}");
|
||||
}
|
||||
|
||||
if (post.post_type == "post")
|
||||
{
|
||||
|
||||
Console.WriteLine($"Post number : {i++}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (taxonomy.taxonomy == "post_tag")
|
||||
{
|
||||
var term = terms.FirstOrDefault(t => t.term_id == taxonomy.term_id);
|
||||
if (term != null)
|
||||
tags.Add(new WordPressPostTagDto
|
||||
{
|
||||
TermId = term.term_id.ToInt(),
|
||||
Tag = term.name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedBlogCategoriesAsync(categories, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||
Console.WriteLine($"{categories.Count} ProductCategory Added Success !");
|
||||
|
||||
|
||||
//CREATE BLOG PART
|
||||
List<SeedBlogRequestDto> blogs = new List<SeedBlogRequestDto>();
|
||||
var random = new Random(1532);
|
||||
foreach (var wordPressPostDto in posts.Where(p => p.post_type == "post"))
|
||||
{
|
||||
SeedBlogRequestDto blog;
|
||||
Guid categoryId = default;
|
||||
string postTags = string.Empty;
|
||||
var postTermRelations = termRelationships.Where(p => p.object_id == wordPressPostDto.ID);
|
||||
foreach (var postTermRelation in postTermRelations)
|
||||
{
|
||||
var taxanomy = termTaxonomies.FirstOrDefault(f => f.term_taxonomy_id == postTermRelation.term_taxonomy_id);
|
||||
if (taxanomy != null)
|
||||
{
|
||||
if (taxanomy.taxonomy == "category")
|
||||
categoryId = categoriesRest.FirstOrDefault(c => c.Key == taxanomy.term_id.ToInt()).Value;
|
||||
if (taxanomy.taxonomy == "post_tag")
|
||||
postTags += tags.FirstOrDefault(t => t.TermId == taxanomy.term_id.ToInt())?.Tag + " , ";
|
||||
}
|
||||
}
|
||||
|
||||
if (categoryId == default)
|
||||
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
|
||||
|
||||
|
||||
blog = new SeedBlogRequestDto
|
||||
{
|
||||
CategoryId = categoryId,
|
||||
Content = wordPressPostDto.post_content,
|
||||
IsSuggested = false,
|
||||
ReadingTime = random.Next(1, 15),
|
||||
Title = wordPressPostDto.post_title,
|
||||
};
|
||||
|
||||
blogs.Add(blog);
|
||||
}
|
||||
|
||||
for (int i = 0; i < blogs.Count / 50; i++)
|
||||
{
|
||||
await RestWrapper.Instance.SeedRestApi.SeedBlogsAsync(blogs.Skip(i * 50).Take(50).ToList(),
|
||||
"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
|
||||
|
||||
Console.WriteLine($"{i * 50} / {blogs.Count} Product Added Success !");
|
||||
}
|
||||
|
||||
|
||||
Console.ReadKey();
|
||||
|
||||
|
||||
|
|
|
@ -2,16 +2,23 @@
|
|||
using Netina.Domain.Dtos.RequestDtos.SeedDtos;
|
||||
using Refit;
|
||||
|
||||
namespace NetinaShop.WordPressDBConverter.Services.RestServices;
|
||||
namespace Netina.WordPressDBConverter.Services.RestServices;
|
||||
|
||||
public interface ISeedRestApi
|
||||
{
|
||||
[Post("/categories")]
|
||||
[Post("/product/categories")]
|
||||
Task<Dictionary<int, Guid>> SeedCategoriesAsync([Body] List<SeedCategoryRequestDto> request, [Query] string key);
|
||||
|
||||
[Post("/brands")]
|
||||
[Post("/product/brands")]
|
||||
Task<Dictionary<int, Guid>> SeedBrandsAsync([Body] List<SeedBrandRequestDto> request, [Query] string key);
|
||||
|
||||
[Post("/products")]
|
||||
Task SeedProductsAsync([Body] List<CreateProductCommand> request, [Query] string key);
|
||||
|
||||
|
||||
[Post("/blog/categories")]
|
||||
Task<Dictionary<int, Guid>> SeedBlogCategoriesAsync([Body] List<SeedBlogCategoryRequestDto> request, [Query] string key);
|
||||
|
||||
[Post("/blogs")]
|
||||
Task SeedBlogsAsync([Body] List<SeedBlogRequestDto> request, [Query] string key);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using Refit;
|
||||
|
||||
namespace NetinaShop.WordPressDBConverter.Services.RestServices;
|
||||
namespace Netina.WordPressDBConverter.Services.RestServices;
|
||||
|
||||
public class RestWrapper
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue