Add CRUDs and validation/controllers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Imprink.Application.Domains.ProductVariants;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.Products.Query;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Imprink.WebApi.Controllers;
|
||||
@@ -10,9 +11,38 @@ namespace Imprink.WebApi.Controllers;
|
||||
public class ProductVariantsController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<IEnumerable<ProductVariantDto>>> GetProductVariants(
|
||||
[FromQuery] GetProductVariantsQuery query)
|
||||
{
|
||||
return Ok(await mediator.Send(query));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<ActionResult<ProductVariantDto>> CreateProductVariant(
|
||||
[FromBody] CreateProductVariantCommand command)
|
||||
{
|
||||
var result = await mediator.Send(command);
|
||||
return CreatedAtAction(nameof(GetProductVariants), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<ActionResult<ProductVariantDto>> UpdateProductVariant(
|
||||
Guid id,
|
||||
[FromBody] UpdateProductVariantCommand command)
|
||||
{
|
||||
if (id != command.Id) return BadRequest("ID mismatch");
|
||||
|
||||
return Ok(await mediator.Send(command));
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<ActionResult> DeleteProductVariant(Guid id)
|
||||
{
|
||||
await mediator.Send(new DeleteProductVariantCommand { Id = id });
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user