Fix product repo not returning a valid object, add query
This commit is contained in:
@@ -2,6 +2,7 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Printbase.Application.Products.Commands;
|
||||
using Printbase.Application.Products.Dtos;
|
||||
using Printbase.Application.Products.Queries;
|
||||
|
||||
namespace Printbase.WebApi.Controllers;
|
||||
|
||||
@@ -9,6 +10,23 @@ namespace Printbase.WebApi.Controllers;
|
||||
[Route("api/[controller]")]
|
||||
public class ProductVariantsController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ProductVariantDto>>> GetProductVariants(
|
||||
[FromQuery] Guid? productId = null,
|
||||
[FromQuery] bool? isActive = null,
|
||||
[FromQuery] bool inStockOnly = false)
|
||||
{
|
||||
var query = new GetProductVariantsQuery
|
||||
{
|
||||
ProductId = productId,
|
||||
IsActive = isActive,
|
||||
InStockOnly = inStockOnly
|
||||
};
|
||||
|
||||
var result = await mediator.Send(query);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ProductVariantDto>> CreateProductVariant([FromBody] CreateProductVariantCommand command)
|
||||
{
|
||||
@@ -16,7 +34,7 @@ public class ProductVariantsController(IMediator mediator) : ControllerBase
|
||||
return CreatedAtAction(nameof(CreateProductVariant), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<ActionResult> DeleteProductVariant(Guid id)
|
||||
{
|
||||
var command = new DeleteProductVariantCommand { Id = id };
|
||||
|
||||
Reference in New Issue
Block a user