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 - GenericQueryHandler - Currency

support2feb349244b3
diff --git a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs b/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
index 9973d128b..e5509a457 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 GetQuery<CurrencyDto>() { Id = key });
+ var currency = await _mediator.Send(new GetGenericQuery<CurrencyDto, Domain.Directory.Currency>() { Id = key });
if (!currency.Any())
return NotFound();
@@ -48,7 +48,7 @@ namespace Grand.Api.Controllers.OData
if (!await _permissionService.Authorize(PermissionSystemName.Currencies))
return Forbid();
- return Ok(await _mediator.Send(new GetQuery<CurrencyDto>()));
+ return Ok(await _mediator.Send(new GetGenericQuery<CurrencyDto, Domain.Directory.Currency>()));
}
}
}
diff --git a/src/API/Grand.Api/Infrastructure/ODataStartup.cs b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
index 9b864535b..85a32b649 100644
--- a/src/API/Grand.Api/Infrastructure/ODataStartup.cs
+++ b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
@@ -89,9 +89,13 @@ namespace Grand.Api.Infrastructure
{
//Workaround - there is a problem with register generic type with IRequestHandler
+
services.AddScoped(typeof(IRequestHandler<GetGenericQuery<CountryDto, Domain.Directory.Country>,
IQueryable<CountryDto>>), typeof(GetGenericQueryHandler<CountryDto, Domain.Directory.Country>));
+ services.AddScoped(typeof(IRequestHandler<GetGenericQuery<CurrencyDto, Domain.Directory.Currency>,
+ IQueryable<CurrencyDto>>), typeof(GetGenericQueryHandler<CurrencyDto, Domain.Directory.Currency>));
+
}
}
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs
deleted file mode 100644
index 6085d6c93..000000000
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Grand.Api.DTOs.Common;
-using Grand.Api.Queries.Models.Common;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Api.Queries.Handlers.Common
-{
- public class GetCurrencyQueryHandler : IRequestHandler<GetQuery<CurrencyDto>, IQueryable<CurrencyDto>>
- {
- private readonly IDatabaseContext _dbContext;
-
- public GetCurrencyQueryHandler(IDatabaseContext dbContext)
- {
- _dbContext = dbContext;
- }
- public async Task<IQueryable<CurrencyDto>> Handle(GetQuery<CurrencyDto> request, CancellationToken cancellationToken)
- {
- var query = _dbContext.Table<CurrencyDto>(typeof(Domain.Directory.Currency).Name);
-
- if (string.IsNullOrEmpty(request.Id))
- return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
- }
- }
-}