feat (scalarUi) , fix (search)

-Add scalar ui instead of swagger
-Fix search product returns
release
Amir Hossein Khademi 2024-05-28 10:46:18 +03:30
parent b7dbe67e7f
commit 9f6af37e7f
7 changed files with 73 additions and 27 deletions

View File

@ -13,11 +13,8 @@
"Microsoft.AspNetCore.Http.Connections": "Debug" "Microsoft.AspNetCore.Http.Connections": "Debug"
} }
}, },
"ShopSettings": {
"TaxesFee": 9
},
"SiteSettings": { "SiteSettings": {
"BaseUrl": "http://localhost:32770", "BaseUrl": "https://api.hamyanedalat.com",
"WebSiteUrl": "https://hamyanedalat.com", "WebSiteUrl": "https://hamyanedalat.com",
"AdminPanelBaseUrl": "https://admin.hamyanedalat.com", "AdminPanelBaseUrl": "https://admin.hamyanedalat.com",
"StorageBaseUrl": "https://storage.hamyanedalat.com", "StorageBaseUrl": "https://storage.hamyanedalat.com",
@ -28,18 +25,14 @@
"Email": "avvampier@gmail.com", "Email": "avvampier@gmail.com",
"Password": "2Tsr87RWRn5T", "Password": "2Tsr87RWRn5T",
"Phone": "09214802813", "Phone": "09214802813",
"RoleName": "RootAdmin", "RoleName": "RootAdmin"
"FirstName": "همه کاره",
"LastName": "سیستم"
}, },
"Manager": { "Manager": {
"Username": "09122171024", "Username": "09122171024",
"Email": "kamran_mirzayi@gmail.com", "Email": "kamran_mirzayi@gmail.com",
"Password": "YAWEheKEi7gh", "Password": "YAWEheKEi7gh",
"Phone": "09128387004", "Phone": "09128387004",
"RoleName": "Manager", "RoleName": "Manager"
"FirstName": "کامران",
"LastName": "میرزایی"
}, },
"StorageSetting": { "StorageSetting": {
"AccessKey": "de129835-b43a-4552-8ed4-865e2635ab3d", "AccessKey": "de129835-b43a-4552-8ed4-865e2635ab3d",

View File

@ -17,6 +17,8 @@ public class SeedController : ICarterModule
var group = app.NewVersionedApi("Seed") var group = app.NewVersionedApi("Seed")
.MapGroup("api/seed"); .MapGroup("api/seed");
group.MapPost("sitemap", CreateSiteMapAsync)
.HasApiVersion(1.0);
group.MapPost("product/categories", SeedCategoriesAsync) group.MapPost("product/categories", SeedCategoriesAsync)
.WithDisplayName("SeedCategoriesAsync") .WithDisplayName("SeedCategoriesAsync")
@ -43,6 +45,16 @@ public class SeedController : ICarterModule
} }
public async Task<IResult> CreateSiteMapAsync([FromQuery] string key, ISiteMapService siteMapService, CancellationToken cancellationToken)
{
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")
throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized);
await siteMapService.CreateSiteMapAsync();
return TypedResults.Ok();
}
public async Task<IResult> SeedProductsAsync([FromBody] List<CreateProductCommand> request, [FromQuery] string key, IMediator mediator, CancellationToken cancellationToken) public async Task<IResult> SeedProductsAsync([FromBody] List<CreateProductCommand> request, [FromQuery] string key, IMediator mediator, CancellationToken cancellationToken)
{ {
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==") if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")

View File

@ -1,3 +1,4 @@
using Netina.Api.WebFramework.ScalarUi;
using Netina.Repository.Behaviors; using Netina.Repository.Behaviors;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -97,12 +98,13 @@ var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{ //app.UseCustomSwagger(siteSetting.BaseUrl);
//app.UseSwagger(); app.UseSwagger();
//app.UseSwaggerUI(); app.MapScalarUi();
} //app.UseSwaggerUI();
else
if (app.Environment.IsProduction())
{ {
app.UseHsts(); app.UseHsts();
} }
@ -113,7 +115,6 @@ app.UseCors(x => x
.AllowCredentials()); .AllowCredentials());
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseCustomSwagger(siteSetting.BaseUrl);
app.UseAuthorization(); app.UseAuthorization();
app.UseAuthentication(); app.UseAuthentication();

View File

@ -21,7 +21,7 @@
"Docker": { "Docker": {
"commandName": "Docker", "commandName": "Docker",
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/scalar/v1",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_URLS": "http://+:80" "ASPNETCORE_URLS": "http://+:80"
}, },

View File

@ -0,0 +1,44 @@
namespace Netina.Api.WebFramework.ScalarUi;
public static class ScalarUiConfiguration
{
public static void MapScalarUi(this IEndpointRouteBuilder app)
{
app.MapGet("/scalar/{documentName}", (string documentName) =>
{
var scalarScript = $$"""
<!doctype html>
<html>
<head>
<title>Scalar API Reference</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
</head>
<body>
<!-- Add your own OpenAPI/Swagger specification URL here: -->
<!-- Note: The example is our public proxy (to avoid CORS issues). You can remove the `data-proxy-url` attribute if you dont need it. -->
<script
id="api-reference"
data-url="/swagger/{{documentName}}/swagger.json"></script>
<!-- Optional: You can set a full configuration object like this: -->
<script>
var configuration = {
theme: 'bluePlanet',
}
document.getElementById('api-reference').dataset.configuration =
JSON.stringify(configuration)
</script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>
""";
return Results.Content(scalarScript, "text/html");
}).ExcludeFromDescription();
}
}

View File

@ -1,6 +1,4 @@
using MediatR; using Netina.Domain.Dtos.ResponseDtos.Zarehbin;
using Netina.Domain.Dtos.ResponseDtos.Torob;
using Netina.Domain.Dtos.ResponseDtos.Zarehbin;
using Netina.Domain.Entities.ProductCategories; using Netina.Domain.Entities.ProductCategories;
namespace Netina.Core.CoreServices; namespace Netina.Core.CoreServices;
@ -15,17 +13,16 @@ public class SearchService : ISearchService
} }
public async Task<SearchResponseDto> SearchAsync(string name, CancellationToken cancellationToken = default) public async Task<SearchResponseDto> SearchAsync(string name, CancellationToken cancellationToken = default)
{ {
var searchQuery = name.ToLower().Trim(); var searchQuery = name;
int minSimilarityThreshold = 20;
var products = await _repositoryWrapper.SetRepository<Product>() var products = await _repositoryWrapper.SetRepository<Product>()
.TableNoTracking .TableNoTracking
.Where(p => FuzzySharp.Fuzz.PartialRatio(p.PersianName.ToLower().Trim(), searchQuery) >= minSimilarityThreshold) .OrderByDescending(p => EF.Functions.TrigramsSimilarity(p.PersianName, searchQuery))
.Select(ProductMapper.ProjectToSDto) .Select(ProductMapper.ProjectToSDto)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
var categories = await _repositoryWrapper.SetRepository<ProductCategory>() var categories = await _repositoryWrapper.SetRepository<ProductCategory>()
.TableNoTracking .TableNoTracking
.Where(p => FuzzySharp.Fuzz.PartialRatio(p.Name.ToLower().Trim(), searchQuery) >= minSimilarityThreshold) .OrderByDescending(p => EF.Functions.TrigramsSimilarity(p.Name, searchQuery))
.Select(ProductCategoryMapper.ProjectToSDto) .Select(ProductCategoryMapper.ProjectToSDto)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);

View File

@ -1,5 +1,4 @@
using Netina.Common.Models.Api; using SixLabors.ImageSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
namespace Netina.Core.Utilities; namespace Netina.Core.Utilities;