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.

Improvements in OData Handling: Adding Select Functionality, Removing Warnings, and URL Adjustments (#469)

Krzysztof Pajakecaf59cfcd20
diff --git a/src/API/Grand.Api/Controllers/BaseODataController.cs b/src/API/Grand.Api/Controllers/BaseODataController.cs
index d3ef74d7d..176e2ec7f 100644
--- a/src/API/Grand.Api/Controllers/BaseODataController.cs
+++ b/src/API/Grand.Api/Controllers/BaseODataController.cs
@@ -10,8 +10,6 @@ namespace Grand.Api.Controllers
{
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ODataRouteComponent]
- [Route("odata/[controller]")]
- [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
[AuthorizeApiAdmin]
[ServiceFilter(typeof(ModelValidationAttribute))]
public abstract class BaseODataController : ODataController
diff --git a/src/API/Grand.Api/Controllers/OData/BrandController.cs b/src/API/Grand.Api/Controllers/OData/BrandController.cs
index d033b81c1..448986fde 100644
--- a/src/API/Grand.Api/Controllers/OData/BrandController.cs
+++ b/src/API/Grand.Api/Controllers/OData/BrandController.cs
@@ -6,13 +6,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
-using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Brand")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class BrandController : BaseODataController
{
private readonly IMediator _mediator;
@@ -25,7 +26,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Brand", OperationId = "GetBrands")]
[HttpGet]
- [EnableQuery]
+ [MongoEnableQuery]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
@@ -40,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.OK)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> GetById([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Brands)) return Forbid();
diff --git a/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs b/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs
index 254a40795..2825b48be 100644
--- a/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs
@@ -4,11 +4,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/BrandLayout")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class BrandLayoutController : BaseODataController
{
private readonly IMediator _mediator;
@@ -37,7 +40,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from BrandLayout", OperationId = "GetBrandLayouts")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CategoryController.cs b/src/API/Grand.Api/Controllers/OData/CategoryController.cs
index 3cc29534b..d4e567726 100644
--- a/src/API/Grand.Api/Controllers/OData/CategoryController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CategoryController.cs
@@ -6,13 +6,15 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Category")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CategoryController : BaseODataController
{
private readonly IMediator _mediator;
@@ -30,7 +32,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Categories)) return Forbid();
@@ -42,7 +44,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Category", OperationId = "GetCategories")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs b/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs
index de6a30006..a514f5ec3 100644
--- a/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs
@@ -4,11 +4,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/CategoryLayout")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CategoryLayoutController : BaseODataController
{
private readonly IMediator _mediator;
@@ -27,7 +30,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
@@ -39,7 +42,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from CategoryLayout", OperationId = "GetCategoryLayout")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CollectionController.cs b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
index ecfba2a8a..aa8f8ef07 100644
--- a/src/API/Grand.Api/Controllers/OData/CollectionController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
@@ -6,13 +6,15 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Collection")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CollectionController : BaseODataController
{
private readonly IMediator _mediator;
@@ -28,7 +30,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections)) return Forbid();
@@ -40,7 +42,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Collection", OperationId = "GetCollections")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs b/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs
index 8eef0f45e..018cf2fa0 100644
--- a/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs
@@ -4,11 +4,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/CollectionLayout")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CollectionLayoutController : BaseODataController
{
private readonly IMediator _mediator;
@@ -25,7 +28,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
@@ -37,7 +40,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from CollectionLayout", OperationId = "GetCollectionLayouts")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CountryController.cs b/src/API/Grand.Api/Controllers/OData/CountryController.cs
index e7bec5cac..a440f7c72 100644
--- a/src/API/Grand.Api/Controllers/OData/CountryController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CountryController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Country")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CountryController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Countries)) return Forbid();
@@ -39,7 +42,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Country", OperationId = "GetCountries")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs b/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
index 24b23a9dd..0db0044dc 100644
--- a/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CurrencyController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Currency")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CurrencyController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Currencies)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Currency", OperationId = "GetCurrencies")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/CustomerController.cs b/src/API/Grand.Api/Controllers/OData/CustomerController.cs
index 346437cbc..524e98be2 100644
--- a/src/API/Grand.Api/Controllers/OData/CustomerController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CustomerController.cs
@@ -13,6 +13,8 @@ using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Customer")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CustomerController : BaseODataController
{
private readonly IMediator _mediator;
@@ -33,16 +35,16 @@ namespace Grand.Api.Controllers.OData
_permissionService = permissionService;
}
- [SwaggerOperation(summary: "Get entity from Customer by key", OperationId = "GetCustomerByEmail")]
- [HttpGet("{key}")]
+ [SwaggerOperation(summary: "Get entity from Customer by email", OperationId = "GetCustomerByEmail")]
+ [HttpGet]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string email)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = email });
if (customer == null) return NotFound();
return Ok(customer);
@@ -79,50 +81,48 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Delete(string key)
+ public async Task<IActionResult> Delete([FromRoute] string email)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = email });
if (customer == null) return NotFound();
- await _mediator.Send(new DeleteCustomerCommand { Email = key });
+ await _mediator.Send(new DeleteCustomerCommand { Email = email });
return Ok();
}
- //odata/Customer/(email)/AddAddress
+ //odata/Customer/email/AddAddress
[SwaggerOperation(summary: "Invoke action AddAddress", OperationId = "AddAddress")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{email}/AddAddress")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> AddAddress(string key, [FromBody] AddressDto address)
+ public async Task<IActionResult> AddAddress([FromRoute] string email, [FromBody] AddressDto address)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = email });
if (customer == null) return NotFound();
address = await _mediator.Send(new AddCustomerAddressCommand { Customer = customer, Address = address });
return Ok(address);
}
- //odata/Customer/(email)/UpdateAddress
+ //odata/Customer/email/UpdateAddress
[SwaggerOperation(summary: "Invoke action UpdateAddress", OperationId = "UpdateAddress")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{email}/UpdateAddress")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateAddress(string key, [FromBody] AddressDto address)
+ public async Task<IActionResult> UpdateAddress([FromRoute] string email, [FromBody] AddressDto address)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = email });
if (customer == null) return NotFound();
address = await _mediator.Send(new UpdateCustomerAddressCommand { Customer = customer, Address = address });
@@ -130,21 +130,20 @@ namespace Grand.Api.Controllers.OData
return Ok(address);
}
- //odata/Customer/(email)/DeleteAddress
+ //odata/Customer/email/DeleteAddress
//body: { "addressId": "xxx" }
[SwaggerOperation(summary: "Invoke action DeleteAddress", OperationId = "DeleteAddress")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{email}/DeleteAddress")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteAddress(string key, [FromBody] DeleteAddressDto model)
+ public async Task<IActionResult> DeleteAddress([FromRoute] string email, [FromBody] DeleteAddressDto model)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
if (model == null || string.IsNullOrEmpty(model.AddressId)) return NotFound();
- var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = email });
if (customer == null) return NotFound();
var address = customer.Addresses.FirstOrDefault(x => x.Id == model.AddressId);
@@ -155,25 +154,24 @@ namespace Grand.Api.Controllers.OData
return Ok(true);
}
- //odata/Customer/(email)/SetPassword
+ //odata/Customer/email/SetPassword
//body: { "password": "123456" }
[SwaggerOperation(summary: "Invoke action SetPassword", OperationId = "SetPassword")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{email}/SetPassword")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> SetPassword(string key, [FromBody] PasswordDto model)
+ public async Task<IActionResult> SetPassword([FromRoute] string email, [FromBody] PasswordDto model)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
if (model == null || string.IsNullOrEmpty(model.Password)) return NotFound();
- var changePassRequest = new ChangePasswordRequest(key, _customerSettings.DefaultPasswordFormat, model.Password);
+ var changePassRequest = new ChangePasswordRequest(email, _customerSettings.DefaultPasswordFormat, model.Password);
await _customerManagerService.ChangePassword(changePassRequest);
return Ok(true);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs
index dd5f46f50..34cf82f46 100644
--- a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs
@@ -6,13 +6,15 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/CustomerGroup")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class CustomerGroupController : BaseODataController
{
private readonly IMediator _mediator;
@@ -29,7 +31,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
@@ -41,7 +43,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from CustomerGroup", OperationId = "GetCustomerGroups")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs b/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs
index 8b3cf9ab4..0c318de16 100644
--- a/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs
+++ b/src/API/Grand.Api/Controllers/OData/DeliveryDateController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/DeliveryDate")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class DeliveryDateController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Delivery Date", OperationId = "GetDeliveryDates")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/LanguageController.cs b/src/API/Grand.Api/Controllers/OData/LanguageController.cs
index 174efd93e..553f222f3 100644
--- a/src/API/Grand.Api/Controllers/OData/LanguageController.cs
+++ b/src/API/Grand.Api/Controllers/OData/LanguageController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Language")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class LanguageController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Languages)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Languages", OperationId = "GetLanguages")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/PickupPointController.cs b/src/API/Grand.Api/Controllers/OData/PickupPointController.cs
index 0a9114aa8..520aff3c7 100644
--- a/src/API/Grand.Api/Controllers/OData/PickupPointController.cs
+++ b/src/API/Grand.Api/Controllers/OData/PickupPointController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/PickupPoint")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class PickupPointController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from PickupPoint", OperationId = "GetPickupPoints")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/PictureController.cs b/src/API/Grand.Api/Controllers/OData/PictureController.cs
index bcf389096..3ddb0ebca 100644
--- a/src/API/Grand.Api/Controllers/OData/PictureController.cs
+++ b/src/API/Grand.Api/Controllers/OData/PictureController.cs
@@ -10,6 +10,8 @@ using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Picture")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class PictureController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +28,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Pictures)) return Forbid();
diff --git a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
index e079e6a48..84d424b0d 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
@@ -6,13 +6,15 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/ProductAttribute")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class ProductAttributeController : BaseODataController
{
private readonly IMediator _mediator;
@@ -31,7 +33,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes)) return Forbid();
@@ -43,7 +45,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from ProductAttribute", OperationId = "GetProductAttributes")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/ProductController.cs b/src/API/Grand.Api/Controllers/OData/ProductController.cs
index 90b790d78..2bd584896 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductController.cs
@@ -6,13 +6,15 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Product")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class ProductController : BaseODataController
{
private readonly IMediator _mediator;
@@ -31,7 +33,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid();
@@ -43,7 +45,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Product", OperationId = "GetProducts")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
@@ -80,7 +82,7 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Partially update entity in Product", OperationId = "PartiallyUpdateProduct")]
- [HttpPatch("{key}")]
+ [HttpPatch]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
@@ -106,7 +108,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Delete(string key)
+ public async Task<IActionResult> Delete([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid();
@@ -118,16 +120,15 @@ namespace Grand.Api.Controllers.OData
return Ok();
}
- //odata/Product/(id)/UpdateStock
+ //odata/Product/id/UpdateStock
//body: { "WarehouseId": "", "Stock": 10 }
[SwaggerOperation(summary: "Invoke action UpdateStock", OperationId = "UpdateStock")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateStock")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateStock(string key, [FromBody] ProductUpdateStock model)
+ public async Task<IActionResult> UpdateStock([FromRoute] string key, [FromBody] ProductUpdateStock model)
{
if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid();
@@ -144,13 +145,12 @@ namespace Grand.Api.Controllers.OData
#region Product category
[SwaggerOperation(summary: "Invoke action CreateProductCategory", OperationId = "CreateProductCategory")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/CreateProductCategory")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> CreateProductCategory(string key, [FromBody] ProductCategoryDto productCategory)
+ public async Task<IActionResult> CreateProductCategory([FromRoute] string key, [FromBody] ProductCategoryDto productCategory)
{
if (productCategory == null) return BadRequest();
@@ -171,13 +171,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action UpdateProductCategory", OperationId = "UpdateProductCategory")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateProductCategory")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateProductCategory(string key, [FromBody] ProductCategoryDto productCategory)
+ public async Task<IActionResult> UpdateProductCategory([FromRoute] string key, [FromBody] ProductCategoryDto productCategory)
{
if (productCategory == null) return BadRequest();
@@ -198,13 +197,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action DeleteProductCategory", OperationId = "DeleteProductCategory")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/DeleteProductCategory")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteProductCategory(string key, [FromBody] ProductCategoryDeleteDto model)
+ public async Task<IActionResult> DeleteProductCategory([FromRoute] string key, [FromBody] ProductCategoryDeleteDto model)
{
if (model == null) return BadRequest();
@@ -234,13 +232,12 @@ namespace Grand.Api.Controllers.OData
#region Product collection
[SwaggerOperation(summary: "Invoke action CreateProductCollection", OperationId = "CreateProductCollection")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/CreateProductCollection")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> CreateProductCollection(string key, [FromBody] ProductCollectionDto productCollection)
+ public async Task<IActionResult> CreateProductCollection([FromRoute] string key, [FromBody] ProductCollectionDto productCollection)
{
if (productCollection == null) return BadRequest();
@@ -261,13 +258,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action UpdateProductCollection", OperationId = "UpdateProductCollection")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateProductCollection")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateProductCollection(string key, [FromBody] ProductCollectionDto productCollection)
+ public async Task<IActionResult> UpdateProductCollection([FromRoute] string key, [FromBody] ProductCollectionDto productCollection)
{
if (productCollection == null) return BadRequest();
@@ -288,13 +284,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action DeleteProductCollection", OperationId = "DeleteProductCollection")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/DeleteProductCollection")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteProductCollection(string key, [FromBody] ProductCollectionDeleteDto model)
+ public async Task<IActionResult> DeleteProductCollection([FromRoute] string key, [FromBody] ProductCollectionDeleteDto model)
{
if (model == null) return BadRequest();
@@ -324,13 +319,12 @@ namespace Grand.Api.Controllers.OData
#region Product picture
[SwaggerOperation(summary: "Invoke action CreateProductPicture", OperationId = "CreateProductPicture")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/CreateProductPicture")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> CreateProductPicture(string key, [FromBody] ProductPictureDto productPicture)
+ public async Task<IActionResult> CreateProductPicture([FromRoute] string key, [FromBody] ProductPictureDto productPicture)
{
if (productPicture == null) return BadRequest();
@@ -351,13 +345,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action UpdateProductPicture", OperationId = "UpdateProductPicture")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateProductPicture")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateProductPicture(string key, [FromBody] ProductPictureDto productPicture)
+ public async Task<IActionResult> UpdateProductPicture([FromRoute] string key, [FromBody] ProductPictureDto productPicture)
{
if (productPicture == null) return BadRequest();
@@ -378,13 +371,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action DeleteProductPicture", OperationId = "DeleteProductPicture")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/DeleteProductPicture")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteProductPicture(string key, [FromBody] ProductPictureDeleteDto model)
+ public async Task<IActionResult> DeleteProductPicture([FromRoute] string key, [FromBody] ProductPictureDeleteDto model)
{
if (model == null) return BadRequest();
@@ -414,13 +406,12 @@ namespace Grand.Api.Controllers.OData
#region Product specification
[SwaggerOperation(summary: "Invoke action CreateProductSpecification", OperationId = "CreateProductSpecification")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/CreateProductSpecification")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> CreateProductSpecification(string key, [FromBody] ProductSpecificationAttributeDto productSpecification)
+ public async Task<IActionResult> CreateProductSpecification([FromRoute] string key, [FromBody] ProductSpecificationAttributeDto productSpecification)
{
if (productSpecification == null) return BadRequest();
@@ -441,13 +432,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action UpdateProductSpecification", OperationId = "UpdateProductSpecification")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateProductSpecification")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateProductSpecification(string key, [FromBody] ProductSpecificationAttributeDto productSpecification)
+ public async Task<IActionResult> UpdateProductSpecification([FromRoute] string key, [FromBody] ProductSpecificationAttributeDto productSpecification)
{
if (productSpecification == null) return BadRequest();
@@ -468,13 +458,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action DeleteProductSpecification", OperationId = "DeleteProductSpecification")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/DeleteProductSpecification")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteProductSpecification(string key, [FromBody] ProductSpecificationAttributeDeleteDto model)
+ public async Task<IActionResult> DeleteProductSpecification([FromRoute] string key, [FromBody] ProductSpecificationAttributeDeleteDto model)
{
if (model == null) return BadRequest();
@@ -504,13 +493,12 @@ namespace Grand.Api.Controllers.OData
#region Product tierprice
[SwaggerOperation(summary: "Invoke action CreateProductTierPrice", OperationId = "CreateProductTierPrice")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/CreateProductTierPrice")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> CreateProductTierPrice(string key, [FromBody] ProductTierPriceDto productTierPrice)
+ public async Task<IActionResult> CreateProductTierPrice([FromRoute] string key, [FromBody] ProductTierPriceDto productTierPrice)
{
if (productTierPrice == null) return BadRequest();
@@ -531,13 +519,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action UpdateProductTierPrice", OperationId = "UpdateProductTierPrice")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateProductTierPrice")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateProductTierPrice(string key, [FromBody] ProductTierPriceDto productTierPrice)
+ public async Task<IActionResult> UpdateProductTierPrice([FromRoute] string key, [FromBody] ProductTierPriceDto productTierPrice)
{
if (productTierPrice == null) return BadRequest();
@@ -558,13 +545,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action DeleteProductTierPrice", OperationId = "DeleteProductTierPrice")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/DeleteProductTierPrice")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteProductTierPrice(string key, [FromBody] ProductTierPriceDeleteDto model)
+ public async Task<IActionResult> DeleteProductTierPrice([FromRoute] string key, [FromBody] ProductTierPriceDeleteDto model)
{
if (model == null) return BadRequest();
@@ -594,13 +580,12 @@ namespace Grand.Api.Controllers.OData
#region Product attribute mapping
[SwaggerOperation(summary: "Invoke action CreateProductAttributeMapping", OperationId = "CreateProductAttributeMapping")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/CreateProductAttributeMapping")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> CreateProductAttributeMapping(string key, [FromBody] ProductAttributeMappingDto productAttributeMapping)
+ public async Task<IActionResult> CreateProductAttributeMapping([FromRoute] string key, [FromBody] ProductAttributeMappingDto productAttributeMapping)
{
if (productAttributeMapping == null) return BadRequest();
@@ -621,13 +606,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action UpdateProductAttributeMapping", OperationId = "UpdateProductAttributeMapping")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/UpdateProductAttributeMapping")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> UpdateProductAttributeMapping(string key, [FromBody] ProductAttributeMappingDto productAttributeMapping)
+ public async Task<IActionResult> UpdateProductAttributeMapping([FromRoute] string key, [FromBody] ProductAttributeMappingDto productAttributeMapping)
{
if (productAttributeMapping == null) return BadRequest();
@@ -648,13 +632,12 @@ namespace Grand.Api.Controllers.OData
}
[SwaggerOperation(summary: "Invoke action DeleteProductAttributeMapping", OperationId = "DeleteProductAttributeMapping")]
- [Route("({key})/[action]")]
- [HttpPost]
+ [HttpPost("/{key}/DeleteProductAttributeMapping")]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> DeleteProductAttributeMapping(string key, [FromBody] ProductAttributeMappingDeleteDto model)
+ public async Task<IActionResult> DeleteProductAttributeMapping([FromRoute] string key, [FromBody] ProductAttributeMappingDeleteDto model)
{
if (model == null) return BadRequest();
@@ -664,19 +647,15 @@ namespace Grand.Api.Controllers.OData
if (!product.Any()) return NotFound();
var attrId = model.Id;
- if (!string.IsNullOrEmpty(attrId))
- {
- var pam = product.FirstOrDefault()!.ProductAttributeMappings.FirstOrDefault(x => x.Id == attrId);
- if (pam == null) return BadRequest("No product attribute mapping found with the specified id");
+ if (string.IsNullOrEmpty(attrId)) return NotFound();
+
+ var pam = product.FirstOrDefault()!.ProductAttributeMappings.FirstOrDefault(x => x.Id == attrId);
+ if (pam == null) return BadRequest("No product attribute mapping found with the specified id");
- if (ModelState.IsValid)
- {
- var result = await _mediator.Send(new DeleteProductAttributeMappingCommand { Product = product.FirstOrDefault(), Model = pam });
- return Ok(result);
- }
- return BadRequest(ModelState);
- }
- return NotFound();
+ if (!ModelState.IsValid) return BadRequest(ModelState);
+
+ var result = await _mediator.Send(new DeleteProductAttributeMappingCommand { Product = product.FirstOrDefault(), Model = pam });
+ return Ok(result);
}
#endregion
}
diff --git a/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs b/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs
index 3452010af..c9fcc7076 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs
@@ -4,11 +4,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/ProductLayout")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class ProductLayoutController : BaseODataController
{
private readonly IMediator _mediator;
@@ -25,7 +28,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from ProductTemplate", OperationId = "GetProductTemplates")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs b/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs
index 72fbc55be..3ee0c32ab 100644
--- a/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ShippingMethodController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/ShippingMethod")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class ShippingMethodController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from ShippingMethod", OperationId = "GetShippingMethods")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
index 12a24be29..e43e975f9 100644
--- a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
+++ b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
@@ -6,13 +6,15 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/SpecificationAttribute")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class SpecificationAttributeController : BaseODataController
{
private readonly IMediator _mediator;
@@ -28,7 +30,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid();
@@ -40,7 +42,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from SpecificationAttribute", OperationId = "GetSpecificationAttributes")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/StoreController.cs b/src/API/Grand.Api/Controllers/OData/StoreController.cs
index 224445063..e13f403ff 100644
--- a/src/API/Grand.Api/Controllers/OData/StoreController.cs
+++ b/src/API/Grand.Api/Controllers/OData/StoreController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Store")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class StoreController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Stores)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Store", OperationId = "GetStores")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/VendorController.cs b/src/API/Grand.Api/Controllers/OData/VendorController.cs
index 08b7e9ee5..94be3990e 100644
--- a/src/API/Grand.Api/Controllers/OData/VendorController.cs
+++ b/src/API/Grand.Api/Controllers/OData/VendorController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Vendor")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class VendorController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Vendors)) return Forbid();
@@ -39,7 +42,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Vendor", OperationId = "GetVendors")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Controllers/OData/WarehouseController.cs b/src/API/Grand.Api/Controllers/OData/WarehouseController.cs
index 2837e1bbe..dc52adff6 100644
--- a/src/API/Grand.Api/Controllers/OData/WarehouseController.cs
+++ b/src/API/Grand.Api/Controllers/OData/WarehouseController.cs
@@ -5,11 +5,14 @@ using Grand.Business.Core.Utilities.Common.Security;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
+using MongoDB.AspNetCore.OData;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
namespace Grand.Api.Controllers.OData
{
+ [Route("odata/Warehouse")]
+ [ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")]
public class WarehouseController : BaseODataController
{
private readonly IMediator _mediator;
@@ -26,7 +29,7 @@ namespace Grand.Api.Controllers.OData
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
- public async Task<IActionResult> Get(string key)
+ public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid();
@@ -38,7 +41,7 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Warehouse", OperationId = "GetWarehouses")]
[HttpGet]
- [EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [MongoEnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
diff --git a/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs b/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs
index 25cccd2f0..cdf188a28 100644
--- a/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs
+++ b/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs
@@ -74,6 +74,16 @@ namespace Grand.Api.Extensions
Type = "string"
}
});
+ operation.Parameters.Add(new OpenApiParameter {
+ Name = "$select",
+ AllowReserved = true,
+ In = ParameterLocation.Query,
+ Description = "Select specific properties from the model",
+ Required = false,
+ Schema = new OpenApiSchema {
+ Type = "string"
+ }
+ });
}
private void ApplyV2(OpenApiOperation operation, OperationFilterContext context)
diff --git a/src/API/Grand.Api/Grand.Api.csproj b/src/API/Grand.Api/Grand.Api.csproj
index bcaf0acce..76650aad5 100644
--- a/src/API/Grand.Api/Grand.Api.csproj
+++ b/src/API/Grand.Api/Grand.Api.csproj
@@ -9,6 +9,7 @@
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.2.4" />
+ <PackageReference Include="MongoDB.AspNetCore.OData" Version="1.0.0-rc1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
</ItemGroup>
diff --git a/src/API/Grand.Api/Infrastructure/ODataStartup.cs b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
index fbd87bb5f..67c6b8b31 100644
--- a/src/API/Grand.Api/Infrastructure/ODataStartup.cs
+++ b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
@@ -57,7 +57,7 @@ namespace Grand.Api.Infrastructure
{
opt.EnableQueryFeatures(Configurations.MaxLimit);
opt.AddRouteComponents(Configurations.ODataRoutePrefix, GetEdmModel(apiConfig));
- opt.Select().Filter().Count().Expand();
+ opt.Select().Filter().Count();
});
services.AddScoped<ModelValidationAttribute>();