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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Update API to OData 8.0 (#95)
Krzysztof Pajak90de12a96e6a
diff --git a/src/API/Grand.Api/Controllers/BaseODataController.cs b/src/API/Grand.Api/Controllers/BaseODataController.csindex 2cba38fef..3929c5113 100644--- a/src/API/Grand.Api/Controllers/BaseODataController.cs+++ b/src/API/Grand.Api/Controllers/BaseODataController.cs@@ -1,12 +1,14 @@using Grand.Api.Filters;-using Microsoft.AspNet.OData;using Microsoft.AspNetCore.Authentication.JwtBearer;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Routing.Attributes;+using Microsoft.AspNetCore.OData.Routing.Controllers;namespace Grand.Api.Controllers{[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]+ [ODataRouteComponent][Route("odata/[controller]")][ApiExplorerSettings(IgnoreApi = false)][AuthorizeApiAdmin]diff --git a/src/API/Grand.Api/Controllers/OData/BrandController.cs b/src/API/Grand.Api/Controllers/OData/BrandController.csindex 957990494..544b09063 100644--- a/src/API/Grand.Api/Controllers/OData/BrandController.cs+++ b/src/API/Grand.Api/Controllers/OData/BrandController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -24,6 +24,17 @@ namespace Grand.Api.Controllers.OData_permissionService = permissionService;}+ [SwaggerOperation(summary: "Get entities from Brand", OperationId = "GetBrands")]+ [HttpGet]+ [EnableQuery]+ public async Task<IActionResult> Get()+ {+ if (!await _permissionService.Authorize(PermissionSystemName.Brands))+ return Forbid();++ return Ok(await _mediator.Send(new GetQuery<BrandDto>()));+ }+[SwaggerOperation(summary: "Get entity from Brand by key", OperationId = "GetBrandById")][HttpGet("{key}")]public async Task<IActionResult> Get(string key)@@ -38,16 +49,7 @@ namespace Grand.Api.Controllers.ODatareturn Ok(brand);}- [SwaggerOperation(summary: "Get entities from Brand", OperationId = "GetBrands")]- [HttpGet]- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]- public async Task<IActionResult> Get()- {- if (!await _permissionService.Authorize(PermissionSystemName.Brands))- return Forbid();-- return Ok(await _mediator.Send(new GetQuery<BrandDto>()));- }+[SwaggerOperation(summary: "Add new entity to Brand", OperationId = "InsertBrand")][HttpPost]@@ -59,7 +61,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddBrandCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs b/src/API/Grand.Api/Controllers/OData/BrandLayoutController.csindex 2241a242b..f3677adae 100644--- a/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs+++ b/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs@@ -2,9 +2,8 @@using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/CategoryController.cs b/src/API/Grand.Api/Controllers/OData/CategoryController.csindex 08861ce00..deb9de51a 100644--- a/src/API/Grand.Api/Controllers/OData/CategoryController.cs+++ b/src/API/Grand.Api/Controllers/OData/CategoryController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -61,7 +61,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddCategoryCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs b/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.csindex 46fb111d3..86bfe1ef6 100644--- a/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs+++ b/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs@@ -2,9 +2,8 @@using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/CollectionController.cs b/src/API/Grand.Api/Controllers/OData/CollectionController.csindex 09a654058..5bebb3e43 100644--- a/src/API/Grand.Api/Controllers/OData/CollectionController.cs+++ b/src/API/Grand.Api/Controllers/OData/CollectionController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -59,7 +59,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddCollectionCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs b/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.csindex 4d8c40ca3..a4f2c5030 100644--- a/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs+++ b/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs@@ -2,9 +2,8 @@using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/CountryController.cs b/src/API/Grand.Api/Controllers/OData/CountryController.csindex 6b4bb19ff..579d98c9f 100644--- a/src/API/Grand.Api/Controllers/OData/CountryController.cs+++ b/src/API/Grand.Api/Controllers/OData/CountryController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs b/src/API/Grand.Api/Controllers/OData/CurrencyController.csindex 6f9f5952f..43233cc30 100644--- a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs+++ b/src/API/Grand.Api/Controllers/OData/CurrencyController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/CustomerController.cs b/src/API/Grand.Api/Controllers/OData/CustomerController.csindex e6bf328f4..e804d9243 100644--- a/src/API/Grand.Api/Controllers/OData/CustomerController.cs+++ b/src/API/Grand.Api/Controllers/OData/CustomerController.cs@@ -7,8 +7,8 @@ using Grand.Business.Customers.Interfaces;using Grand.Business.Customers.Utilities;using Grand.Domain.Customers;using MediatR;-using Microsoft.AspNet.OData;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -59,7 +59,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddCustomerCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.csindex 31168e14e..020c69b8c 100644--- a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs+++ b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -60,7 +60,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddCustomerGroupCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs b/src/API/Grand.Api/Controllers/OData/DeliveryDateController.csindex 6df06b9a2..c2010614b 100644--- a/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs+++ b/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/LanguageController.cs b/src/API/Grand.Api/Controllers/OData/LanguageController.csindex 81d3b243e..bdc97dd51 100644--- a/src/API/Grand.Api/Controllers/OData/LanguageController.cs+++ b/src/API/Grand.Api/Controllers/OData/LanguageController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/PickupPointController.cs b/src/API/Grand.Api/Controllers/OData/PickupPointController.csindex c6d43343c..ade52b9d1 100644--- a/src/API/Grand.Api/Controllers/OData/PickupPointController.cs+++ b/src/API/Grand.Api/Controllers/OData/PickupPointController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/PictureController.cs b/src/API/Grand.Api/Controllers/OData/PictureController.csindex 138f4459a..3d5a4f6a5 100644--- a/src/API/Grand.Api/Controllers/OData/PictureController.cs+++ b/src/API/Grand.Api/Controllers/OData/PictureController.cs@@ -45,7 +45,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddPictureCommand() { PictureDto = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.csindex 8abf7efe3..bcc8cd7f9 100644--- a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs+++ b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -62,7 +62,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddProductAttributeCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/ProductController.cs b/src/API/Grand.Api/Controllers/OData/ProductController.csindex a07feef22..99c12f306 100644--- a/src/API/Grand.Api/Controllers/OData/ProductController.cs+++ b/src/API/Grand.Api/Controllers/OData/ProductController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -62,7 +62,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddProductCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}@@ -120,7 +120,7 @@ namespace Grand.Api.Controllers.ODatareturn Ok();}- //odata/Product(id)/UpdateStock+ //odata/Product/(id)/UpdateStock//body: { "Stock": 10 }[SwaggerOperation(summary: "Invoke action UpdateStock", OperationId = "UpdateStock")][Route("({key})/[action]")]diff --git a/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs b/src/API/Grand.Api/Controllers/OData/ProductLayoutController.csindex 32b9654c3..757b82c49 100644--- a/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs+++ b/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs@@ -2,9 +2,8 @@using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs b/src/API/Grand.Api/Controllers/OData/ShippingMethodController.csindex 332616887..f876658e5 100644--- a/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs+++ b/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.csindex 1d131e800..0154de5b8 100644--- a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs+++ b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs@@ -4,10 +4,10 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Formatter;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;@@ -59,7 +59,7 @@ namespace Grand.Api.Controllers.ODataif (ModelState.IsValid){model = await _mediator.Send(new AddSpecificationAttributeCommand() { Model = model });- return Created(model);+ return Ok(model);}return BadRequest(ModelState);}diff --git a/src/API/Grand.Api/Controllers/OData/StateProvinceController.cs b/src/API/Grand.Api/Controllers/OData/StateProvinceController.csindex 7eda35cc0..b7c9641a4 100644--- a/src/API/Grand.Api/Controllers/OData/StateProvinceController.cs+++ b/src/API/Grand.Api/Controllers/OData/StateProvinceController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/StoreController.cs b/src/API/Grand.Api/Controllers/OData/StoreController.csindex 376f68092..ebefe085e 100644--- a/src/API/Grand.Api/Controllers/OData/StoreController.cs+++ b/src/API/Grand.Api/Controllers/OData/StoreController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/VendorController.cs b/src/API/Grand.Api/Controllers/OData/VendorController.csindex 5a118abad..1adeccecd 100644--- a/src/API/Grand.Api/Controllers/OData/VendorController.cs+++ b/src/API/Grand.Api/Controllers/OData/VendorController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Controllers/OData/WarehouseController.cs b/src/API/Grand.Api/Controllers/OData/WarehouseController.csindex 630502ba8..7e1bd8e8d 100644--- a/src/API/Grand.Api/Controllers/OData/WarehouseController.cs+++ b/src/API/Grand.Api/Controllers/OData/WarehouseController.cs@@ -3,9 +3,8 @@ using Grand.Api.Queries.Models.Common;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Services.Security;using MediatR;-using Microsoft.AspNet.OData;-using Microsoft.AspNet.OData.Query;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.OData.Query;using Swashbuckle.AspNetCore.Annotations;using System.Linq;using System.Threading.Tasks;diff --git a/src/API/Grand.Api/Grand.Api.csproj b/src/API/Grand.Api/Grand.Api.csprojindex cd0b45d2f..a55db3394 100644--- a/src/API/Grand.Api/Grand.Api.csproj+++ b/src/API/Grand.Api/Grand.Api.csproj@@ -20,11 +20,9 @@<ProjectReference Include="..\..\Core\Grand.SharedKernel\Grand.SharedKernel.csproj" /></ItemGroup><ItemGroup>- <PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.8" />- <PackageReference Include="Microsoft.AspNetCore.OData.Versioning" Version="5.0.0" />- <PackageReference Include="Microsoft.OData.Core" Version="7.9.0" />- <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />- <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />+ <PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.1" />+ <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />+ <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.5" /></ItemGroup></Project>diff --git a/src/API/Grand.Api/Infrastructure/AuthenticationStartup.cs b/src/API/Grand.Api/Infrastructure/AuthenticationStartup.csdeleted file mode 100644index 4fbb90c56..000000000--- a/src/API/Grand.Api/Infrastructure/AuthenticationStartup.cs+++ /dev/null@@ -1,48 +0,0 @@-using Grand.Api.Constants;-using Grand.Business.Authentication.Interfaces;-using Grand.Business.Authentication.Services;-using Grand.Infrastructure;-using Grand.Infrastructure.Configuration;-using Microsoft.AspNet.OData.Extensions;-using Microsoft.AspNetCore.Builder;-using Microsoft.AspNetCore.Hosting;-using Microsoft.Extensions.Configuration;-using Microsoft.Extensions.DependencyInjection;--namespace Grand.Api.Infrastructure-{- public partial class AuthenticationStartup : IStartupApplication- {- public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)- {- var apiConfig = application.ApplicationServices.GetService<ApiConfig>();- if (apiConfig.Enabled)- {- application.UseCors(Configurations.CorsPolicyName);- }- }-- public void ConfigureServices(IServiceCollection services,- IConfiguration configuration)- {- var apiConfig = services.BuildServiceProvider().GetService<ApiConfig>();- if (apiConfig.Enabled)- {- //cors- services.AddCors(options =>- {- options.AddPolicy(Configurations.CorsPolicyName,- builder => builder.AllowAnyOrigin()- .AllowAnyMethod()- .AllowAnyHeader());- });-- //Add OData- services.AddOData();- services.AddODataQueryFilter();- }- }- public int Priority => 505;- public bool BeforeConfigure => true;- }-}diff --git a/src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs b/src/API/Grand.Api/Infrastructure/DependencyEdmModel.csindex b4527e138..93be30a91 100644--- a/src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs+++ b/src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs@@ -5,7 +5,7 @@ using Grand.Api.DTOs.Shipping;using Grand.Api.Infrastructure.DependencyManagement;using Grand.Domain.Catalog;using Grand.Infrastructure.Configuration;-using Microsoft.AspNet.OData.Builder;+using Microsoft.OData.ModelBuilder;using System;using System.Collections.Generic;@@ -18,36 +18,31 @@ namespace Grand.Api.Infrastructure#region Language modelbuilder.EntitySet<LanguageDto>("Language");- builder.EntityType<LanguageDto>().Count().Filter().OrderBy().Page();#endregion#region Currency modelbuilder.EntitySet<CurrencyDto>("Currency");- builder.EntityType<CurrencyDto>().Count().Filter().OrderBy().Page();#endregion#region Store modelbuilder.EntitySet<StoreDto>("Store");- builder.EntityType<StoreDto>().Count().Filter().OrderBy().Page();-+#endregion#region Country modelbuilder.EntitySet<CountryDto>("Country");- builder.EntityType<CountryDto>().Count().Filter().OrderBy().Page();#endregion#region State province modelbuilder.EntitySet<StateProvinceDto>("StateProvince");- builder.EntityType<StateProvinceDto>().Count().Filter().OrderBy().Page();-+#endregion#region layout model@@ -56,14 +51,12 @@ namespace Grand.Api.Infrastructurebuilder.EntitySet<LayoutDto>("CollectionLayout");builder.EntitySet<LayoutDto>("ProductlLayout");builder.EntitySet<LayoutDto>("BrandlLayout");- builder.EntityType<LayoutDto>().Count().Filter().OrderBy().Page();#endregion#region Picture modelbuilder.EntitySet<PictureDto>("Picture");- builder.EntityType<PictureDto>().Count().Filter().OrderBy().Page();#endregion}@@ -71,7 +64,6 @@ namespace Grand.Api.Infrastructure{builder.EntitySet<ProductDto>("Product");var product = builder.EntityType<ProductDto>();- product.Count().Filter().OrderBy().Page();builder.ComplexType<ProductCategoryDto>();builder.ComplexType<ProductCollectionDto>();builder.ComplexType<ProductPictureDto>();@@ -246,28 +238,23 @@ namespace Grand.Api.Infrastructure#region Category modelbuilder.EntitySet<CategoryDto>("Category");- builder.EntityType<CategoryDto>().Count().Filter().OrderBy().Page();#endregion#region Brand modelbuilder.EntitySet<BrandDto>("Brand");- builder.EntityType<BrandDto>().Count().Filter().OrderBy().Page();#endregion#region Collection modelbuilder.EntitySet<CollectionDto>("Collection");- builder.EntityType<CollectionDto>().Count().Filter().OrderBy().Page();-#endregion#region Product attribute modelbuilder.EntitySet<ProductAttributeDto>("ProductAttribute");- builder.EntityType<ProductAttributeDto>().Count().Filter().OrderBy().Page();builder.ComplexType<PredefinedProductAttributeValueDto>();#endregion@@ -275,7 +262,6 @@ namespace Grand.Api.Infrastructure#region Product attribute modelbuilder.EntitySet<SpecificationAttributeDto>("SpecificationAttribute");- builder.EntityType<SpecificationAttributeDto>().Count().Filter().OrderBy().Page();builder.ComplexType<SpecificationAttributeOptionDto>();#endregion@@ -341,15 +327,13 @@ namespace Grand.Api.Infrastructure#region Customer group modelbuilder.EntitySet<CustomerGroupDto>("CustomerGroup");- builder.EntityType<CustomerGroupDto>().Count().Filter().OrderBy().Page();#endregion#region Vendorsbuilder.EntitySet<VendorDto>("Vendor");- builder.EntityType<VendorDto>().Count().Filter().OrderBy().Page();-+#endregion}@@ -358,28 +342,24 @@ namespace Grand.Api.Infrastructure#region Warehouse modelbuilder.EntitySet<WarehouseDto>("Warehouse");- builder.EntityType<WarehouseDto>().Count().Filter().OrderBy().Page();-+#endregion#region Delivery date modelbuilder.EntitySet<DeliveryDateDto>("DeliveryDate");- builder.EntityType<DeliveryDateDto>().Count().Filter().OrderBy().Page();-+#endregion#region Pickup point modelbuilder.EntitySet<PickupPointDto>("PickupPoint");- builder.EntityType<PickupPointDto>().Count().Filter().OrderBy().Page();#endregion#region Shipping method modelbuilder.EntitySet<ShippingMethodDto>("ShippingMethod");- builder.EntityType<ShippingMethodDto>().Count().Filter().OrderBy().Page();#endregion}diff --git a/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs b/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.csindex ad85efaec..7748b50cd 100644--- a/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs+++ b/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs@@ -1,5 +1,5 @@using Grand.Infrastructure.Configuration;-using Microsoft.AspNet.OData.Builder;+using Microsoft.OData.ModelBuilder;namespace Grand.Api.Infrastructure.DependencyManagement{diff --git a/src/API/Grand.Api/Infrastructure/EnumSchemaFilter.cs b/src/API/Grand.Api/Infrastructure/EnumSchemaFilter.csindex 1b12e2c1a..19a708258 100644--- a/src/API/Grand.Api/Infrastructure/EnumSchemaFilter.cs+++ b/src/API/Grand.Api/Infrastructure/EnumSchemaFilter.cs@@ -8,14 +8,17 @@ namespace Grand.Api.Infrastructure{public class EnumSchemaFilter : ISchemaFilter{- public void Apply(OpenApiSchema model, SchemaFilterContext context)+ public void Apply(OpenApiSchema schema, SchemaFilterContext context){if (context.Type.IsEnum){- model.Enum.Clear();- Enum.GetNames(context.Type)- .ToList()- .ForEach(n => model.Enum.Add(new OpenApiString(n)));+ var enumValues = schema.Enum.ToArray();+ foreach (var item in enumValues)+ {+ var value = (OpenApiPrimitive<int>)item;+ var name = Enum.GetName(context.Type, value.Value);+ schema.Description += $"{value.Value} - {name}; ";+ }}}}diff --git a/src/API/Grand.Api/Infrastructure/ODataParamsStartup.cs b/src/API/Grand.Api/Infrastructure/ODataParamsStartup.csdeleted file mode 100644index 5d0193e4c..000000000--- a/src/API/Grand.Api/Infrastructure/ODataParamsStartup.cs+++ /dev/null@@ -1,49 +0,0 @@-using Grand.Infrastructure;-using Grand.Infrastructure.Configuration;-using Microsoft.AspNet.OData.Formatter;-using Microsoft.AspNetCore.Builder;-using Microsoft.AspNetCore.Hosting;-using Microsoft.Extensions.Configuration;-using Microsoft.Extensions.DependencyInjection;-using Microsoft.Net.Http.Headers;-using System.Linq;--namespace Grand.Api.Infrastructure-{- public class ODataParamsStartup : IStartupApplication- {- public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)- {-- }-- public void ConfigureServices(IServiceCollection services, IConfiguration configuration)- {- var apiConfig = services.BuildServiceProvider().GetService<ApiConfig>();- if (apiConfig.Enabled && apiConfig.UseSwagger)- {- SetOutputFormatters(services);- }- }-- public int Priority => 900;- public bool BeforeConfigure => true;-- private void SetOutputFormatters(IServiceCollection services)- {- services.AddMvcCore(options =>- {- foreach (var outputFormatter in options.OutputFormatters.OfType<ODataOutputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0))- {- outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata"));- }- foreach (var inputFormatter in options.InputFormatters.OfType<ODataInputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0))- {- inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata"));- }- });- }--- }-}diff --git a/src/API/Grand.Api/Infrastructure/ODataRouteProvider.cs b/src/API/Grand.Api/Infrastructure/ODataRouteProvider.csdeleted file mode 100644index 5cd09df7a..000000000--- a/src/API/Grand.Api/Infrastructure/ODataRouteProvider.cs+++ /dev/null@@ -1,62 +0,0 @@-using Grand.Api.Constants;-using Grand.Api.Infrastructure.DependencyManagement;-using Grand.Infrastructure.Configuration;-using Grand.Infrastructure.Endpoints;-using Grand.Infrastructure.TypeSearchers;-using Microsoft.AspNet.OData.Builder;-using Microsoft.AspNet.OData.Extensions;-using Microsoft.AspNetCore.Routing;-using Microsoft.Extensions.DependencyInjection;-using Microsoft.OData.Edm;-using System;-using System.Linq;--namespace Grand.Api.Infrastructure-{- public class ODataRouteProvider : IEndpointProvider- {- public int Priority => 10;-- public void RegisterEndpoint(IEndpointRouteBuilder routeBuilder)- {- var apiConfig = routeBuilder.ServiceProvider.GetRequiredService<ApiConfig>();- if (apiConfig.Enabled)- {- //OData- var serviceProvider = routeBuilder.ServiceProvider;- IEdmModel model = GetEdmModel(serviceProvider, apiConfig);- routeBuilder.Count().Filter().OrderBy().MaxTop(Configurations.MaxLimit);- routeBuilder.MapODataRoute(Configurations.ODataRouteName, Configurations.ODataRoutePrefix, model);- routeBuilder.EnableDependencyInjection();- }- }-- private IEdmModel GetEdmModel(IServiceProvider serviceProvider, ApiConfig apiConfig)- {- var builder = new ODataConventionModelBuilder(serviceProvider);- builder.Namespace = Configurations.ODataModelBuilderNamespace;- RegisterDependencies(builder, apiConfig);- return builder.GetEdmModel();- }-- private void RegisterDependencies(ODataConventionModelBuilder builder, ApiConfig apiConfig)- {- var typeFinder = new AppTypeSearcher();-- //find dependency provided by other assemblies- var dependencyInject = typeFinder.ClassesOfType<IDependencyEdmModel>();-- //create and sort instances of dependency inject- var instances = dependencyInject- .Select(di => (IDependencyEdmModel)Activator.CreateInstance(di))- .OrderBy(di => di.Order);-- //register all provided dependencies- foreach (var dependencyRegistrar in instances)- dependencyRegistrar.Register(builder, apiConfig);-- }--- }-}diff --git a/src/API/Grand.Api/Infrastructure/ODataStartup.cs b/src/API/Grand.Api/Infrastructure/ODataStartup.csnew file mode 100644index 000000000..2764ed512--- /dev/null+++ b/src/API/Grand.Api/Infrastructure/ODataStartup.cs@@ -0,0 +1,83 @@+using Grand.Api.Constants;+using Grand.Api.Infrastructure.DependencyManagement;+using Grand.Infrastructure;+using Grand.Infrastructure.Configuration;+using Grand.Infrastructure.TypeSearchers;+using Microsoft.AspNetCore.Builder;+using Microsoft.AspNetCore.Hosting;+using Microsoft.AspNetCore.OData;+using Microsoft.Extensions.Configuration;+using Microsoft.Extensions.DependencyInjection;+using Microsoft.OData.Edm;+using Microsoft.OData.ModelBuilder;+using System;+using System.Linq;++namespace Grand.Api.Infrastructure+{+ public partial class ODataStartup : IStartupApplication+ {+ public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)+ {+ var apiConfig = application.ApplicationServices.GetService<ApiConfig>();+ if (apiConfig.Enabled)+ {+ application.UseCors(Configurations.CorsPolicyName);+ }+ }++ public void ConfigureServices(IServiceCollection services,+ IConfiguration configuration)+ {+ var apiConfig = services.BuildServiceProvider().GetService<ApiConfig>();+ if (apiConfig.Enabled)+ {+ //cors+ services.AddCors(options =>+ {+ options.AddPolicy(Configurations.CorsPolicyName,+ builder => builder.AllowAnyOrigin()+ .AllowAnyMethod()+ .AllowAnyHeader());+ });+ //Add OData+ services.AddControllers().AddOData(opt =>+ {+ opt.EnableQueryFeatures(Configurations.MaxLimit);+ opt.AddRouteComponents(Configurations.ODataRoutePrefix, GetEdmModel(apiConfig));+ opt.Select().Filter().Count().Expand();+ });+ }+ }+ public int Priority => 505;+ public bool BeforeConfigure => false;+++ private IEdmModel GetEdmModel(ApiConfig apiConfig)+ {+ var builder = new ODataConventionModelBuilder {+ Namespace = Configurations.ODataModelBuilderNamespace+ };+ RegisterDependencies(builder, apiConfig);+ return builder.GetEdmModel();+ }++ private void RegisterDependencies(ODataConventionModelBuilder builder, ApiConfig apiConfig)+ {+ var typeFinder = new AppTypeSearcher();++ //find dependency provided by other assemblies+ var dependencyInject = typeFinder.ClassesOfType<IDependencyEdmModel>();++ //create and sort instances of dependency inject+ var instances = dependencyInject+ .Select(di => (IDependencyEdmModel)Activator.CreateInstance(di))+ .OrderBy(di => di.Order);++ //register all provided dependencies+ foreach (var dependencyRegistrar in instances)+ dependencyRegistrar.Register(builder, apiConfig);++ }+ }+}diff --git a/src/API/Grand.Api/Infrastructure/SwaggerStartup.cs b/src/API/Grand.Api/Infrastructure/SwaggerStartup.csindex a612dc819..e2d19f780 100644--- a/src/API/Grand.Api/Infrastructure/SwaggerStartup.cs+++ b/src/API/Grand.Api/Infrastructure/SwaggerStartup.cs@@ -4,6 +4,7 @@ using Grand.Infrastructure.Configuration;using Microsoft.AspNetCore.Authentication.JwtBearer;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;+using Microsoft.AspNetCore.OData;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.OpenApi.Models;@@ -16,6 +17,10 @@ namespace Grand.Api.Infrastructurepublic void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment){var apiConfig = application.ApplicationServices.GetService<ApiConfig>();++ if(apiConfig.Enabled)+ application.UseODataQueryRequest();+if (apiConfig.Enabled && apiConfig.UseSwagger){application.UseSwagger();@@ -31,7 +36,7 @@ namespace Grand.Api.Infrastructurevar apiConfig = services.BuildServiceProvider().GetService<ApiConfig>();if (apiConfig.Enabled && apiConfig.UseSwagger){-+services.AddSwaggerGen(c =>{c.SwaggerDoc("v1", new OpenApiInfo { Title = "Grandnode API", Version = "v1" });@@ -58,11 +63,12 @@ namespace Grand.Api.Infrastructurec.EnableAnnotations();c.SchemaFilter<EnumSchemaFilter>();});+}}- public int Priority => 90;- public bool BeforeConfigure => true;+ public int Priority => 500;+ public bool BeforeConfigure => false;}}