From 7a6e5980f2adbeaf501b383e5d858369811dbbba Mon Sep 17 00:00:00 2001 From: Jonas Anker Rasmussen Date: Mon, 13 Nov 2023 00:18:46 +0100 Subject: [PATCH] Return 201 for POST --- .../Controllers/v2/ProductsController.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs index 5ec0e718..7bb4eafc 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs @@ -41,15 +41,17 @@ public ProductsController(IProductService productService, ClaimsUtilities claims /// /// The request containing the details of the product to be added and allowed user groups. /// The newly added product wrapped in a InitiateProductResponse object. - /// Product created + /// Product created /// Product name already exists [HttpPost] [AuthorizeRoles(UserGroup.Board)] - [ProducesResponseType(typeof(DetailedProductResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(DetailedProductResponse), StatusCodes.Status201Created)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status409Conflict)] public async Task> AddProduct([FromBody] AddProductRequest addProductRequest) { - return Ok(await _productService.AddProduct(addProductRequest)); + var product = await _productService.AddProduct(addProductRequest); + + return CreatedAtAction(nameof(GetProductById), new { id = product.Id, version = 2 }, product); } ///