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.

API - Collection - add ProducesResponseType

KrzysztofPajak7e4adf20f0b1
diff --git a/src/API/Grand.Api/Controllers/OData/CollectionController.cs b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
index 5bebb3e43..744a78dec 100644
--- a/src/API/Grand.Api/Controllers/OData/CollectionController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
@@ -10,6 +10,7 @@ using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Swashbuckle.AspNetCore.Annotations;
using System.Linq;
+using System.Net;
using System.Threading.Tasks;
namespace Grand.Api.Controllers.OData
@@ -26,6 +27,9 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entity from Collection by key", OperationId = "GetCollectionById")]
[HttpGet("{key}")]
+ [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+ [ProducesResponseType((int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Get(string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
@@ -41,6 +45,8 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Get entities from Collection", OperationId = "GetCollections")]
[HttpGet]
[EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]
+ [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+ [ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get()
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
@@ -51,6 +57,9 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Add new entity to Collection", OperationId = "InsertCollection")]
[HttpPost]
+ [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+ [ProducesResponseType((int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Post([FromBody] CollectionDto model)
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
@@ -66,12 +75,15 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Update entity in Collection", OperationId = "UpdateCollection")]
[HttpPut]
+ [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+ [ProducesResponseType((int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest)]
+ [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Put([FromBody] CollectionDto model)
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
return Forbid();
-
var collection = await _mediator.Send(new GetQuery<CollectionDto>() { Id = model.Id });
if (!collection.Any())
{
@@ -89,6 +101,10 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Partially update entity in Collection", OperationId = "PartiallyUpdateCollection")]
[HttpPatch]
+ [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+ [ProducesResponseType((int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest)]
+ [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Patch([FromODataUri] string key, [FromBody] JsonPatchDocument<CollectionDto> model)
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections))
@@ -113,6 +129,9 @@ namespace Grand.Api.Controllers.OData
[SwaggerOperation(summary: "Delete entity in Collection", OperationId = "DeleteCollection")]
[HttpDelete]
+ [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+ [ProducesResponseType((int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Delete(string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections))