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(Warehouse, DeliveryDate, ShippingMethod, PickupPoint)

support53ab73e403b8
diff --git a/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs b/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs
index 1ca2f7842..50e4cecab 100644
--- a/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs
+++ b/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs
@@ -31,7 +31,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- var deliverydate = await _mediator.Send(new GetQuery<DeliveryDateDto>() { Id = key });
+ var deliverydate = await _mediator.Send(new GetGenericQuery<DeliveryDateDto, Domain.Shipping.DeliveryDate>(key));
if (!deliverydate.Any())
return NotFound();
@@ -48,7 +48,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<DeliveryDateDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<DeliveryDateDto, Domain.Shipping.DeliveryDate>()));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/PickupPointController.cs b/src/API/Grand.Api/Controllers/OData/PickupPointController.cs
index 0bae66802..a0d0697e2 100644
--- a/src/API/Grand.Api/Controllers/OData/PickupPointController.cs
+++ b/src/API/Grand.Api/Controllers/OData/PickupPointController.cs
@@ -31,7 +31,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- var points = await _mediator.Send(new GetQuery<PickupPointDto>() { Id = key });
+ var points = await _mediator.Send(new GetGenericQuery<PickupPointDto, Domain.Shipping.PickupPoint>(key));
if (!points.Any())
return NotFound();
@@ -49,7 +49,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<PickupPointDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<PickupPointDto, Domain.Shipping.PickupPoint>()));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs b/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs
index 49b4c96d0..084a22491 100644
--- a/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs
@@ -31,7 +31,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- var shipping = await _mediator.Send(new GetQuery<ShippingMethodDto>() { Id = key });
+ var shipping = await _mediator.Send(new GetGenericQuery<ShippingMethodDto, Domain.Shipping.ShippingMethod>(key));
if (!shipping.Any())
return NotFound();
@@ -48,7 +48,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<ShippingMethodDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<ShippingMethodDto, Domain.Shipping.ShippingMethod>()));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/WarehouseController.cs b/src/API/Grand.Api/Controllers/OData/WarehouseController.cs
index 1edcf772b..e88deb2b2 100644
--- a/src/API/Grand.Api/Controllers/OData/WarehouseController.cs
+++ b/src/API/Grand.Api/Controllers/OData/WarehouseController.cs
@@ -31,7 +31,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- var warehouse = await _mediator.Send(new GetQuery<WarehouseDto>() { Id = key });
+ var warehouse = await _mediator.Send(new GetGenericQuery<WarehouseDto, Domain.Shipping.Warehouse>(key));
if (!warehouse.Any())
return NotFound();
@@ -48,7 +48,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<WarehouseDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<WarehouseDto, Domain.Shipping.Warehouse>()));
}
}
}
diff --git a/src/API/Grand.Api/Infrastructure/ODataStartup.cs b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
index 9f1a07db4..0007478d6 100644
--- a/src/API/Grand.Api/Infrastructure/ODataStartup.cs
+++ b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
@@ -1,6 +1,7 @@
using Grand.Api.Constants;
using Grand.Api.DTOs.Catalog;
using Grand.Api.DTOs.Common;
+using Grand.Api.DTOs.Shipping;
using Grand.Api.Infrastructure.DependencyManagement;
using Grand.Api.Queries.Handlers.Common;
using Grand.Api.Queries.Models.Common;
@@ -115,6 +116,18 @@ namespace Grand.Api.Infrastructure
services.AddScoped(typeof(IRequestHandler<GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>,
IQueryable<SpecificationAttributeDto>>), typeof(GetGenericQueryHandler<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>));
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<WarehouseDto, Domain.Shipping.Warehouse>,
+ IQueryable<WarehouseDto>>), typeof(GetGenericQueryHandler<WarehouseDto, Domain.Shipping.Warehouse>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<ShippingMethodDto, Domain.Shipping.ShippingMethod>,
+ IQueryable<ShippingMethodDto>>), typeof(GetGenericQueryHandler<ShippingMethodDto, Domain.Shipping.ShippingMethod>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<PickupPointDto, Domain.Shipping.PickupPoint>,
+ IQueryable<PickupPointDto>>), typeof(GetGenericQueryHandler<PickupPointDto, Domain.Shipping.PickupPoint>));
+
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<DeliveryDateDto, Domain.Shipping.DeliveryDate>,
+ IQueryable<DeliveryDateDto>>), typeof(GetGenericQueryHandler<DeliveryDateDto, Domain.Shipping.DeliveryDate>));
+
}
}
}
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs
deleted file mode 100644
index 26025def3..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Grand.Api.DTOs.Shipping;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Shipping
-{
- public class GetDeliveryDateQueryHandler : IRequestHandler<GetQuery<DeliveryDateDto>, IQueryable<DeliveryDateDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetDeliveryDateQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<DeliveryDateDto>> Handle(GetQuery<DeliveryDateDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<DeliveryDateDto>(typeof(Domain.Shipping.DeliveryDate).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
- }
- }
-}
\ No newline at end of file
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs
deleted file mode 100644
index 07bedecf2..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Grand.Api.DTOs.Shipping;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Shipping
-{
- public class GetPickupPointQueryHandler : IRequestHandler<GetQuery<PickupPointDto>, IQueryable<PickupPointDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetPickupPointQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<PickupPointDto>> Handle(GetQuery<PickupPointDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<PickupPointDto>(typeof(Domain.Shipping.PickupPoint).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
- }
- }
-}
\ No newline at end of file
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs
deleted file mode 100644
index 3862e1740..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Grand.Api.DTOs.Shipping;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Shipping
-{
- public class GetShippingMethodQueryHandler : IRequestHandler<GetQuery<ShippingMethodDto>, IQueryable<ShippingMethodDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetShippingMethodQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<ShippingMethodDto>> Handle(GetQuery<ShippingMethodDto> request, CancellationToken cancellationToken)
- {
- var shippingMethod = _dbContext.Table<ShippingMethodDto>(typeof(Domain.Shipping.ShippingMethod).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return shippingMethod;
- else
- return await Task.FromResult(shippingMethod.Where(x => x.Id == request.Id));
- }
- }
-}
\ No newline at end of file
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs
deleted file mode 100644
index 7e7cf4d3b..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Grand.Api.DTOs.Shipping;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Shipping
-{
- public class GetWarehouseQueryHandler : IRequestHandler<GetQuery<WarehouseDto>, IQueryable<WarehouseDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetWarehouseQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<WarehouseDto>> Handle(GetQuery<WarehouseDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<WarehouseDto>(typeof(Domain.Shipping.Warehouse).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
- }
- }
-}
\ No newline at end of file