Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Grand.API - minor refactoring - use GenericQueryHandler(Brand, Collection, Category, ProductAttributes, Product, SpecificationAttribute)

support9081e12df605
diff --git a/src/API/Grand.Api/Controllers/OData/BrandController.cs b/src/API/Grand.Api/Controllers/OData/BrandController.cs
index ba5f9a89e..d3810a2ec 100644
--- a/src/API/Grand.Api/Controllers/OData/BrandController.cs
+++ b/src/API/Grand.Api/Controllers/OData/BrandController.cs
@@ -33,7 +33,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Brands))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<BrandDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>()));
}
[SwaggerOperation(summary: "Get entity from Brand by key", OperationId = "GetBrandById")]
@@ -46,15 +46,13 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Brands))
return Forbid();
- var brand = await _mediator.Send(new GetQuery<BrandDto>() { Id = key });
+ var brand = await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>(key));
if (!brand.Any())
return NotFound();
return Ok(brand.FirstOrDefault());
}
-
-
[SwaggerOperation(summary: "Add new entity to Brand", OperationId = "InsertBrand")]
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
@@ -85,7 +83,7 @@ namespace Grand.Api.Controllers.OData
return Forbid();
- var brand = await _mediator.Send(new GetQuery<BrandDto>() { Id = model.Id });
+ var brand = await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>(model.Id));
if (!brand.Any())
{
return NotFound();
@@ -111,7 +109,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Brands))
return Forbid();
- var brand = await _mediator.Send(new GetQuery<BrandDto>() { Id = key });
+ var brand = await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>(key));
if (!brand.Any())
{
return NotFound();
@@ -138,7 +136,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Brands))
return Forbid();
- var brand = await _mediator.Send(new GetQuery<BrandDto>() { Id = key });
+ var brand = await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>(key));
if (!brand.Any())
{
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/CategoryController.cs b/src/API/Grand.Api/Controllers/OData/CategoryController.cs
index ad86342f0..fcc2de902 100644
--- a/src/API/Grand.Api/Controllers/OData/CategoryController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CategoryController.cs
@@ -35,7 +35,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Categories))
return Forbid();
- var category = await _mediator.Send(new GetQuery<CategoryDto>() { Id = key });
+ var category = await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>(key));
if (!category.Any())
return NotFound();
@@ -52,7 +52,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Categories))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<CategoryDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>()));
}
[SwaggerOperation(summary: "Add new entity to Category", OperationId = "InsertCategory")]
@@ -84,7 +84,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Categories))
return Forbid();
- var category = await _mediator.Send(new GetQuery<CategoryDto>() { Id = model.Id });
+ var category = await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>(model.Id));
if (!category.Any())
{
return NotFound();
@@ -108,7 +108,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Categories))
return Forbid();
- var category = await _mediator.Send(new GetQuery<CategoryDto>() { Id = key });
+ var category = await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>(key));
if (!category.Any())
{
return NotFound();
@@ -133,7 +133,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Categories))
return Forbid();
- var category = await _mediator.Send(new GetQuery<CategoryDto>() { Id = key });
+ var category = await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>(key));
if (!category.Any())
{
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/CollectionController.cs b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
index 6911c7a32..e9fa54cb7 100644
--- a/src/API/Grand.Api/Controllers/OData/CollectionController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
@@ -33,7 +33,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
return Forbid();
- var collection = await _mediator.Send(new GetQuery<CollectionDto>() { Id = key });
+ var collection = await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>(key));
if (!collection.Any())
return NotFound();
@@ -50,7 +50,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<CollectionDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>()));
}
[SwaggerOperation(summary: "Add new entity to Collection", OperationId = "InsertCollection")]
@@ -82,7 +82,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
return Forbid();
- var collection = await _mediator.Send(new GetQuery<CollectionDto>() { Id = model.Id });
+ var collection = await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>(model.Id));
if (!collection.Any())
{
return NotFound();
@@ -108,7 +108,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
return Forbid();
- var collection = await _mediator.Send(new GetQuery<CollectionDto>() { Id = key });
+ var collection = await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>(key));
if (!collection.Any())
{
return NotFound();
@@ -135,7 +135,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
return Forbid();
- var collection = await _mediator.Send(new GetQuery<CollectionDto>() { Id = key });
+ var collection = await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>(key));
if (!collection.Any())
{
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/CountryController.cs b/src/API/Grand.Api/Controllers/OData/CountryController.cs
index 3f9be1e52..9a03f5957 100644
--- a/src/API/Grand.Api/Controllers/OData/CountryController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CountryController.cs
@@ -32,7 +32,7 @@ namespace Grand.Api.Controllers.OData
return Forbid();
//Domain.Directory.Country
- var country = await _mediator.Send(new GetGenericQuery<CountryDto, Domain.Directory.Country>() { Id = key });
+ var country = await _mediator.Send(new GetGenericQuery<CountryDto, Domain.Directory.Country>(key));
if (!country.Any())
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs b/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
index e5509a457..648bb7b2f 100644
--- a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
@@ -31,7 +31,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Currencies))
return Forbid();
- var currency = await _mediator.Send(new GetGenericQuery<CurrencyDto, Domain.Directory.Currency>() { Id = key });
+ var currency = await _mediator.Send(new GetGenericQuery<CurrencyDto, Domain.Directory.Currency>(key));
if (!currency.Any())
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
index 006786d36..e741797c7 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
@@ -36,7 +36,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes))
return Forbid();
- var productAttribute = await _mediator.Send(new GetQuery<ProductAttributeDto>() { Id = key });
+ var productAttribute = await _mediator.Send(new GetGenericQuery<ProductAttributeDto, Domain.Catalog.ProductAttribute>(key));
if (!productAttribute.Any())
return NotFound();
@@ -53,7 +53,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<ProductAttributeDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<ProductAttributeDto, Domain.Catalog.ProductAttribute>()));
}
[SwaggerOperation(summary: "Add new entity to ProductAttribute", OperationId = "InsertProductAttribute")]
@@ -103,7 +103,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes))
return Forbid();
- var productAttribute = await _mediator.Send(new GetQuery<ProductAttributeDto>() { Id = key });
+ var productAttribute = await _mediator.Send(new GetGenericQuery<ProductAttributeDto, Domain.Catalog.ProductAttribute>(key));
if (!productAttribute.Any())
return NotFound();
@@ -128,7 +128,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes))
return Forbid();
- var productAttribute = await _mediator.Send(new GetQuery<ProductAttributeDto>() { Id = key });
+ var productAttribute = await _mediator.Send(new GetGenericQuery<ProductAttributeDto, Domain.Catalog.ProductAttribute>(key));
if (!productAttribute.Any())
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/ProductController.cs b/src/API/Grand.Api/Controllers/OData/ProductController.cs
index a7bd6b6a9..33e71c558 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductController.cs
@@ -36,7 +36,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -53,7 +53,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<ProductDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>()));
}
[SwaggerOperation(summary: "Add new entity to Product", OperationId = "InsertProduct")]
@@ -103,7 +103,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -128,7 +128,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -151,7 +151,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -181,7 +181,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -212,7 +212,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -244,7 +244,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -284,7 +284,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -315,7 +315,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -346,7 +346,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -386,7 +386,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -418,7 +418,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -450,7 +450,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -490,7 +490,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -521,7 +521,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -552,7 +552,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -592,7 +592,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -623,7 +623,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -654,7 +654,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -694,7 +694,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -725,7 +725,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
@@ -756,7 +756,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Products))
return Forbid();
- var product = await _mediator.Send(new GetQuery<ProductDto>() { Id = key });
+ var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any())
return NotFound();
diff --git a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
index 74f69270c..beeac80f2 100644
--- a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
+++ b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
@@ -33,7 +33,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes))
return Forbid();
- var specificationAttribute = await _mediator.Send(new GetQuery<SpecificationAttributeDto>() { Id = key });
+ var specificationAttribute = await _mediator.Send(new GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>(key));
if (!specificationAttribute.Any())
return NotFound();
@@ -50,7 +50,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<SpecificationAttributeDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>()));
}
[SwaggerOperation(summary: "Add new entity to SpecificationAttribute", OperationId = "InsertSpecificationAttribute")]
@@ -100,7 +100,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes))
return Forbid();
- var specification = await _mediator.Send(new GetQuery<SpecificationAttributeDto>() { Id = key });
+ var specification = await _mediator.Send(new GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>(key));
if (!specification.Any())
{
return NotFound();
@@ -127,7 +127,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes))
return Forbid();
- var specification = await _mediator.Send(new GetQuery<SpecificationAttributeDto>() { Id = key });
+ var specification = await _mediator.Send(new GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>(key));
if (!specification.Any())
{
return NotFound();
diff --git a/src/API/Grand.Api/Infrastructure/ODataStartup.cs b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
index 85a32b649..9f1a07db4 100644
--- a/src/API/Grand.Api/Infrastructure/ODataStartup.cs
+++ b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
@@ -1,4 +1,5 @@
using Grand.Api.Constants;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.DTOs.Common;
using Grand.Api.Infrastructure.DependencyManagement;
using Grand.Api.Queries.Handlers.Common;
@@ -96,6 +97,23 @@ namespace Grand.Api.Infrastructure
services.AddScoped(typeof(IRequestHandler<GetGenericQuery<CurrencyDto, Domain.Directory.Currency>,
IQueryable<CurrencyDto>>), typeof(GetGenericQueryHandler<CurrencyDto, Domain.Directory.Currency>));
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<BrandDto, Domain.Catalog.Brand>,
+ IQueryable<BrandDto>>), typeof(GetGenericQueryHandler<BrandDto, Domain.Catalog.Brand>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<CategoryDto, Domain.Catalog.Category>,
+ IQueryable<CategoryDto>>), typeof(GetGenericQueryHandler<CategoryDto, Domain.Catalog.Category>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<CollectionDto, Domain.Catalog.Collection>,
+ IQueryable<CollectionDto>>), typeof(GetGenericQueryHandler<CollectionDto, Domain.Catalog.Collection>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<ProductAttributeDto, Domain.Catalog.ProductAttribute>,
+ IQueryable<ProductAttributeDto>>), typeof(GetGenericQueryHandler<ProductAttributeDto, Domain.Catalog.ProductAttribute>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<ProductDto, Domain.Catalog.Product>,
+ IQueryable<ProductDto>>), typeof(GetGenericQueryHandler<ProductDto, Domain.Catalog.Product>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>,
+ IQueryable<SpecificationAttributeDto>>), typeof(GetGenericQueryHandler<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>));
}
}
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs
deleted file mode 100644
index d14f2c6dd..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Grand.Api.DTOs.Catalog;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetBrandQueryHandler : IRequestHandler<GetQuery<BrandDto>, IQueryable<BrandDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetBrandQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<BrandDto>> Handle(GetQuery<BrandDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<BrandDto>(typeof(Domain.Catalog.Brand).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
-
- }
- }
-}
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs
deleted file mode 100644
index f8bb9226d..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Grand.Api.DTOs.Catalog;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetCategoryQueryHandler : IRequestHandler<GetQuery<CategoryDto>, IQueryable<CategoryDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetCategoryQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<CategoryDto>> Handle(GetQuery<CategoryDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<CategoryDto>(typeof(Domain.Catalog.Category).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
-
- }
- }
-}
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs
deleted file mode 100644
index 30bddee4a..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Grand.Api.DTOs.Catalog;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetCollectionQueryHandler : IRequestHandler<GetQuery<CollectionDto>, IQueryable<CollectionDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetCollectionQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
-
- public async Task<IQueryable<CollectionDto>> Handle(GetQuery<CollectionDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<CollectionDto>(typeof(Domain.Catalog.Collection).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
- }
- }
-}
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs
deleted file mode 100644
index 58b3a88f9..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Grand.Api.DTOs.Catalog;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetProductAttributeQueryHandler : IRequestHandler<GetQuery<ProductAttributeDto>, IQueryable<ProductAttributeDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetProductAttributeQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<ProductAttributeDto>> Handle(GetQuery<ProductAttributeDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<ProductAttributeDto>(typeof(Domain.Catalog.ProductAttribute).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
-
- }
- }
-}
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs
deleted file mode 100644
index e2287bf37..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Grand.Api.DTOs.Catalog;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetProductQueryHandler : IRequestHandler<GetQuery<ProductDto>, IQueryable<ProductDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetProductQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
-
- public async Task<IQueryable<ProductDto>> Handle(GetQuery<ProductDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<ProductDto>(typeof(Domain.Catalog.Product).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
-
- }
- }
-}
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs
deleted file mode 100644
index f93ce7e8d..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Grand.Api.DTOs.Catalog;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetSpecificationAttributeQueryHandler : IRequestHandler<GetQuery<SpecificationAttributeDto>, IQueryable<SpecificationAttributeDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetSpecificationAttributeQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<SpecificationAttributeDto>> Handle(GetQuery<SpecificationAttributeDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<SpecificationAttributeDto>(typeof(Domain.Catalog.SpecificationAttribute).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
-
- }
- }
-}
diff --git a/src/API/Grand.Api/Queries/Models/Common/GetGenericQuery.cs b/src/API/Grand.Api/Queries/Models/Common/GetGenericQuery.cs
index e440c4772..861f207b0 100644
--- a/src/API/Grand.Api/Queries/Models/Common/GetGenericQuery.cs
+++ b/src/API/Grand.Api/Queries/Models/Common/GetGenericQuery.cs
@@ -2,12 +2,8 @@
using Grand.Domain;
using MediatR;
-namespace Grand.Api.Queries.Models.Common
-{
- public class GetGenericQuery<T,C> : IRequest<IQueryable<T>>
- where T : BaseApiEntityModel
- where C : BaseEntity
- {
- public string Id { get; set; }
- }
-}
+namespace Grand.Api.Queries.Models.Common;
+
+public record GetGenericQuery<T, C>(string Id = null) : IRequest<IQueryable<T>> where T : BaseApiEntityModel where C : BaseEntity;
+
+