Owneat Technical Guide main Help

Class ProductController

Namespace: Restaurant.API.Controllers
Assembly: Restaurant.API.dll

Controller made for Restaurant.Domain.Aggregates.ProductAggregate.Product management.

[ApiController] [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/[controller]s")] public class ProductController : ControllerBase

Inheritance

objectControllerBase ← ProductController

Inherited Members

ControllerBase.StatusCode\(int\), ControllerBase.StatusCode\(int, object?\), ControllerBase.Content\(string\), ControllerBase.Content\(string, string\), ControllerBase.Content\(string, string, Encoding\), ControllerBase.Content\(string, MediaTypeHeaderValue?\), ControllerBase.NoContent\(\), ControllerBase.Ok\(\), ControllerBase.Ok\(object?\), ControllerBase.Redirect\(string\), ControllerBase.RedirectPermanent\(string\), ControllerBase.RedirectPreserveMethod\(string\), ControllerBase.RedirectPermanentPreserveMethod\(string\), ControllerBase.LocalRedirect\(string\), ControllerBase.LocalRedirectPermanent\(string\), ControllerBase.LocalRedirectPreserveMethod\(string\), ControllerBase.LocalRedirectPermanentPreserveMethod\(string\), ControllerBase.RedirectToAction\(\), ControllerBase.RedirectToAction\(string?\), ControllerBase.RedirectToAction\(string?, object?\), ControllerBase.RedirectToAction\(string?, string?\), ControllerBase.RedirectToAction\(string?, string?, object?\), ControllerBase.RedirectToAction\(string?, string?, string?\), ControllerBase.RedirectToAction\(string?, string?, object?, string?\), ControllerBase.RedirectToActionPreserveMethod\(string?, string?, object?, string?\), ControllerBase.RedirectToActionPermanent\(string?\), ControllerBase.RedirectToActionPermanent\(string?, object?\), ControllerBase.RedirectToActionPermanent\(string?, string?\), ControllerBase.RedirectToActionPermanent\(string?, string?, string?\), ControllerBase.RedirectToActionPermanent\(string?, string?, object?\), ControllerBase.RedirectToActionPermanent\(string?, string?, object?, string?\), ControllerBase.RedirectToActionPermanentPreserveMethod\(string?, string?, object?, string?\), ControllerBase.RedirectToRoute\(string?\), ControllerBase.RedirectToRoute\(object?\), ControllerBase.RedirectToRoute\(string?, object?\), ControllerBase.RedirectToRoute\(string?, string?\), ControllerBase.RedirectToRoute\(string?, object?, string?\), ControllerBase.RedirectToRoutePreserveMethod\(string?, object?, string?\), ControllerBase.RedirectToRoutePermanent\(string?\), ControllerBase.RedirectToRoutePermanent\(object?\), ControllerBase.RedirectToRoutePermanent\(string?, object?\), ControllerBase.RedirectToRoutePermanent\(string?, string?\), ControllerBase.RedirectToRoutePermanent\(string?, object?, string?\), ControllerBase.RedirectToRoutePermanentPreserveMethod\(string?, object?, string?\), ControllerBase.RedirectToPage\(string\), ControllerBase.RedirectToPage\(string, object?\), ControllerBase.RedirectToPage\(string, string?\), ControllerBase.RedirectToPage\(string, string?, object?\), ControllerBase.RedirectToPage\(string, string?, string?\), ControllerBase.RedirectToPage\(string, string?, object?, string?\), ControllerBase.RedirectToPagePermanent\(string\), ControllerBase.RedirectToPagePermanent\(string, object?\), ControllerBase.RedirectToPagePermanent\(string, string?\), ControllerBase.RedirectToPagePermanent\(string, string?, string?\), ControllerBase.RedirectToPagePermanent\(string, string?, object?, string?\), ControllerBase.RedirectToPagePreserveMethod\(string, string?, object?, string?\), ControllerBase.RedirectToPagePermanentPreserveMethod\(string, string?, object?, string?\), ControllerBase.File\(byte\[\], string\), ControllerBase.File\(byte\[\], string, bool\), ControllerBase.File\(byte\[\], string, string?\), ControllerBase.File\(byte\[\], string, string?, bool\), ControllerBase.File\(byte\[\], string, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.File\(byte\[\], string, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.File\(byte\[\], string, string?, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.File\(byte\[\], string, string?, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.File\(Stream, string\), ControllerBase.File\(Stream, string, bool\), ControllerBase.File\(Stream, string, string?\), ControllerBase.File\(Stream, string, string?, bool\), ControllerBase.File\(Stream, string, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.File\(Stream, string, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.File\(Stream, string, string?, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.File\(Stream, string, string?, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.File\(string, string\), ControllerBase.File\(string, string, bool\), ControllerBase.File\(string, string, string?\), ControllerBase.File\(string, string, string?, bool\), ControllerBase.File\(string, string, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.File\(string, string, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.File\(string, string, string?, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.File\(string, string, string?, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.PhysicalFile\(string, string\), ControllerBase.PhysicalFile\(string, string, bool\), ControllerBase.PhysicalFile\(string, string, string?\), ControllerBase.PhysicalFile\(string, string, string?, bool\), ControllerBase.PhysicalFile\(string, string, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.PhysicalFile\(string, string, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.PhysicalFile\(string, string, string?, DateTimeOffset?, EntityTagHeaderValue\), ControllerBase.PhysicalFile\(string, string, string?, DateTimeOffset?, EntityTagHeaderValue, bool\), ControllerBase.Unauthorized\(\), ControllerBase.Unauthorized\(object?\), ControllerBase.NotFound\(\), ControllerBase.NotFound\(object?\), ControllerBase.BadRequest\(\), ControllerBase.BadRequest\(object?\), ControllerBase.BadRequest\(ModelStateDictionary\), ControllerBase.UnprocessableEntity\(\), ControllerBase.UnprocessableEntity\(object?\), ControllerBase.UnprocessableEntity\(ModelStateDictionary\), ControllerBase.Conflict\(\), ControllerBase.Conflict\(object?\), ControllerBase.Conflict\(ModelStateDictionary\), ControllerBase.Problem\(string?, string?, int?, string?, string?\), ControllerBase.ValidationProblem\(ValidationProblemDetails\), ControllerBase.ValidationProblem\(ModelStateDictionary\), ControllerBase.ValidationProblem\(\), ControllerBase.ValidationProblem\(string?, string?, int?, string?, string?, ModelStateDictionary?\), ControllerBase.Created\(\), ControllerBase.Created\(string?, object?\), ControllerBase.Created\(Uri?, object?\), ControllerBase.CreatedAtAction\(string?, object?\), ControllerBase.CreatedAtAction\(string?, object?, object?\), ControllerBase.CreatedAtAction\(string?, string?, object?, object?\), ControllerBase.CreatedAtRoute\(string?, object?\), ControllerBase.CreatedAtRoute\(object?, object?\), ControllerBase.CreatedAtRoute\(string?, object?, object?\), ControllerBase.Accepted\(\), ControllerBase.Accepted\(object?\), ControllerBase.Accepted\(Uri\), ControllerBase.Accepted\(string?\), ControllerBase.Accepted\(string?, object?\), ControllerBase.Accepted\(Uri, object?\), ControllerBase.AcceptedAtAction\(string?\), ControllerBase.AcceptedAtAction\(string?, string?\), ControllerBase.AcceptedAtAction\(string?, object?\), ControllerBase.AcceptedAtAction\(string?, string?, object?\), ControllerBase.AcceptedAtAction\(string?, object?, object?\), ControllerBase.AcceptedAtAction\(string?, string?, object?, object?\), ControllerBase.AcceptedAtRoute\(object?\), ControllerBase.AcceptedAtRoute\(string?\), ControllerBase.AcceptedAtRoute\(string?, object?\), ControllerBase.AcceptedAtRoute\(object?, object?\), ControllerBase.AcceptedAtRoute\(string?, object?, object?\), ControllerBase.Challenge\(\), ControllerBase.Challenge\(params string\[\]\), ControllerBase.Challenge\(AuthenticationProperties\), ControllerBase.Challenge\(AuthenticationProperties, params string\[\]\), ControllerBase.Forbid\(\), ControllerBase.Forbid\(params string\[\]\), ControllerBase.Forbid\(AuthenticationProperties\), ControllerBase.Forbid\(AuthenticationProperties, params string\[\]\), ControllerBase.SignIn\(ClaimsPrincipal\), ControllerBase.SignIn\(ClaimsPrincipal, string\), ControllerBase.SignIn\(ClaimsPrincipal, AuthenticationProperties\), ControllerBase.SignIn\(ClaimsPrincipal, AuthenticationProperties, string\), ControllerBase.SignOut\(\), ControllerBase.SignOut\(AuthenticationProperties\), ControllerBase.SignOut\(params string\[\]\), ControllerBase.SignOut\(AuthenticationProperties, params string\[\]\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel, string\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel, string, IValueProvider\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel, string, params Expression<Func<TModel, object?\>\>\[\]\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel, string, Func<ModelMetadata, bool\>\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel, string, IValueProvider, params Expression<Func<TModel, object?\>\>\[\]\), ControllerBase.TryUpdateModelAsync<TModel\>\(TModel, string, IValueProvider, Func<ModelMetadata, bool\>\), ControllerBase.TryUpdateModelAsync\(object, Type, string\), ControllerBase.TryUpdateModelAsync\(object, Type, string, IValueProvider, Func<ModelMetadata, bool\>\), ControllerBase.TryValidateModel\(object\), ControllerBase.TryValidateModel\(object, string?\), ControllerBase.HttpContext, ControllerBase.Request, ControllerBase.Response, ControllerBase.RouteData, ControllerBase.ModelState, ControllerBase.ControllerContext, ControllerBase.MetadataProvider, ControllerBase.ModelBinderFactory, ControllerBase.Url, ControllerBase.ObjectValidator, ControllerBase.ProblemDetailsFactory, ControllerBase.User, ControllerBase.Empty, object.Equals\(object?\), object.Equals\(object?, object?\), object.GetHashCode\(\), object.GetType\(\), object.MemberwiseClone\(\), object.ReferenceEquals\(object?, object?\), object.ToString\(\)

Constructors

ProductController\(IMediator\)

Products controller constructor, injecting IMediator to send requests.

public ProductController(IMediator mediator)

Parameters

mediator IMediator

Methods

AddAllergen\(Guid, Guid\)

Add an allergen to a product.

[HttpPut("{productGuid}/allergens/{allergenGuid}")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(409)] [ProducesResponseType(500)] public Task<ActionResult<Product>> AddAllergen(Guid productGuid, Guid allergenGuid)

Parameters

productGuid Guid

Guid of the product.

allergenGuid Guid

Guid of the allergen.

Returns

Task < ActionResult <Product\>\>

The updated product.

AddFoodLabel\(Guid, Guid\)

Add an food-label to a product.

[HttpPut("{productGuid}/food-labels/{foodLabelGuid}")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(409)] [ProducesResponseType(500)] public Task<ActionResult<Product>> AddFoodLabel(Guid productGuid, Guid foodLabelGuid)

Parameters

productGuid Guid

Guid of the product.

foodLabelGuid Guid

Guid of the food-label.

Returns

Task < ActionResult <Product\>\>

The updated product.

AddIngredient\(Guid, Guid\)

Add an ingredient to a product.

[HttpPut("{productGuid}/ingredients/{ingredientGuid}")] [Authorize(Roles = "Admin")] [ProducesResponseType(typeof(Ingredient), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(409)] [ProducesResponseType(500)] public Task<ActionResult<Product>> AddIngredient(Guid productGuid, Guid ingredientGuid)

Parameters

productGuid Guid

Guid of the product.

ingredientGuid Guid

Guid of the ingredient.

Returns

Task < ActionResult <Product\>\>

The updated product.

CreateIngredient\(Guid, CreateProductIngredientCommand\)

Create an ingredient in a product.

[HttpPut("{productGuid}/ingredients")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(409)] [ProducesResponseType(500)] public Task<ActionResult<Product>> CreateIngredient(Guid productGuid, CreateProductIngredientCommand command)

Parameters

productGuid Guid

Guid of the product.

command CreateProductIngredientCommand

The command to create an ingredient in a product.

Returns

Task < ActionResult <Product\>\>

The updated product.

CreatePersonalization\(Guid, CreateProductPersonalizationCommand\)

Create a personalization in a product.

[HttpPut("{productGuid}/personalizations")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(409)] [ProducesResponseType(500)] public Task<ActionResult<Product>> CreatePersonalization(Guid productGuid, CreateProductPersonalizationCommand command)

Parameters

productGuid Guid

Guid of the product.

command CreateProductPersonalizationCommand

The command to create an personalization in a product.

Returns

Task < ActionResult <Product\>\>

The updated product.

DeleteProduct\(Guid\)

Delete a product by Guid.

[HttpDelete("{productGuid}")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] public Task<ActionResult> DeleteProduct(Guid productGuid)

Parameters

productGuid Guid

Guid of the product to delete.

Returns

Task < ActionResult \>

A unit value that signify the success of the operation.

GetAllProducts\(\)

Gets a list of all products.

[HttpGet] [Authorize(Roles = "Admin")] [ProducesResponseType(typeof(IEnumerable<Product>), 200)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(500)] public Task<ActionResult<IEnumerable<Product>>> GetAllProducts()

Returns

Task < ActionResult < IEnumerable <Product\>\>\>

GetAllProductsByRestaurantId\(Guid\)

Gets a list of all products contained in a restaurant.

[HttpGet("restaurants/{restaurantGuid}/products")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(IEnumerable<Product>), 200)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(500)] public Task<ActionResult<IEnumerable<Product>>> GetAllProductsByRestaurantId(Guid restaurantGuid)

Parameters

restaurantGuid Guid

Returns

Task < ActionResult < IEnumerable <Product\>\>\>

GetProductById\(Guid\)

Get a product by Guid.

[HttpGet("{productGuid}")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult<Product>> GetProductById(Guid productGuid)

Parameters

productGuid Guid

Guid of the product to get.

Returns

Task < ActionResult <Product\>\>

The requested product.

RemoveAllergen\(Guid, Guid\)

Remove a allergen from an product.

[HttpDelete("{productGuid}/allergens/{allergenGuid}")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult> RemoveAllergen(Guid productGuid, Guid allergenGuid)

Parameters

productGuid Guid

Guid of the product.

allergenGuid Guid

Guid of the allergen.

Returns

Task < ActionResult \>

A unit value that signify a no content success response.

RemoveFoodLabel\(Guid, Guid\)

Remove a food-label from an product.

[HttpDelete("{productGuid}/food-labels/{foodLabelGuid}")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult> RemoveFoodLabel(Guid productGuid, Guid foodLabelGuid)

Parameters

productGuid Guid

Guid of the product.

foodLabelGuid Guid

Guid of the food-label to add.

Returns

Task < ActionResult \>

A unit value that signify a no content success response.

RemoveIngredient\(Guid, Guid\)

Remove an ingredient from a product.

[HttpDelete("{productGuid}/ingredients/{ingredientGuid}")] [Authorize(Roles = "Admin")] [ProducesResponseType(204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult<Product>> RemoveIngredient(Guid productGuid, Guid ingredientGuid)

Parameters

productGuid Guid

Guid of the product.

ingredientGuid Guid

Guid of the ingredient.

Returns

Task < ActionResult <Product\>\>

A unit value that signify a no content success response.

ReorderProducts\(ReorderProductsCommand\)

Update products by bulk to change their order.

[HttpPut("reorder")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Product), 204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult<Unit>> ReorderProducts(ReorderProductsCommand command)

Parameters

command ReorderProductsCommand

Dictionary that contain Guid and SortingIndex of the Products.

Returns

Task < ActionResult <Unit\>\>

The updated product.

UpdateExternalPaymentId\(Guid, UpdateProductExternalPaymentIdCommand\)

Update stripe id of a product.

[HttpPut("{productGuid}/update-external-payment-id")] [ProducesResponseType(204)] [ProducesResponseType(400)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult> UpdateExternalPaymentId(Guid productGuid, UpdateProductExternalPaymentIdCommand command)

Parameters

productGuid Guid

Guid of the product.

command UpdateProductExternalPaymentIdCommand

Command that contains the external payment id to delete.

Returns

Task < ActionResult \>

A unit value that signify a no content success response.

UpdateProduct\(Guid, UpdateProductCommand\)

Update a product by Guid.

[HttpPut("{productGuid}")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(409)] [ProducesResponseType(500)] public Task<ActionResult<Product>> UpdateProduct(Guid productGuid, UpdateProductCommand command)

Parameters

productGuid Guid

Guid of the product to update.

command UpdateProductCommand

Command from the body.

Returns

Task < ActionResult <Product\>\>

The updated product.

UpdateProductImage\(Guid, UpdateProductImageCommand\)

Update a product image.

[HttpPut("{productGuid}/image")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Unit), 204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult<Unit>> UpdateProductImage(Guid productGuid, UpdateProductImageCommand command)

Parameters

productGuid Guid

Guid of the product to update.

command UpdateProductImageCommand

Command from the body that contains the Img url.

Returns

Task < ActionResult <Unit\>\>

UpdateProductStock\(Guid, UpdateProductStockCommand\)

Update a product stock.

[HttpPut("{productGuid}/stock")] [Authorize(Roles = "Admin, Owner")] [ProducesResponseType(typeof(Unit), 204)] [ProducesResponseType(400)] [ProducesResponseType(401)] [ProducesResponseType(403)] [ProducesResponseType(404)] [ProducesResponseType(500)] public Task<ActionResult<Unit>> UpdateProductStock(Guid productGuid, UpdateProductStockCommand command)

Parameters

productGuid Guid

Guid of the product to update.

command UpdateProductStockCommand

Command from the body that contains the new stock.

Returns

Task < ActionResult <Unit\>\>

Last modified: 21 May 2024