Files
ShopSolution-backend/Webshop.Api/Controllers/ProductsController.cs
2025-07-21 20:51:55 +02:00

34 lines
1.0 KiB
C#

// src/Webshop.Api/Controllers/ProductsController.cs
using Microsoft.AspNetCore.Mvc;
using Webshop.Application.DTOs;
using Webshop.Application.Services;
namespace Webshop.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
private readonly ProductService _productService;
public ProductsController(ProductService productService)
{
_productService = productService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<ProductDto>>> GetAllProducts()
{
var products = await _productService.GetAllProductsAsync();
return Ok(products);
}
[HttpPost]
public async Task<ActionResult<ProductDto>> CreateProduct([FromBody] ProductDto productDto)
{
var createdProduct = await _productService.CreateProductAsync(productDto);
return CreatedAtAction(nameof(GetAllProducts), new { id = createdProduct.Id }, createdProduct);
}
}
}