changes
This commit is contained in:
29
Webshop.Api/Controllers/Public/ProductsController.cs
Normal file
29
Webshop.Api/Controllers/Public/ProductsController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webshop.Application.DTOs; // ProductDto
|
||||
using Webshop.Application.Services.Public; // ProductCatalogService
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Webshop.Api.Controllers.Public // Beachten Sie den Namespace
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/public/[controller]")] // z.B. /api/v1/public/products
|
||||
[AllowAnonymous] // Jeder darf hier zugreifen (Gast oder eingeloggter User)
|
||||
public class ProductsController : ControllerBase
|
||||
{
|
||||
private readonly ProductService _productCatalogService; // Umbenannt
|
||||
|
||||
public ProductsController(ProductService productCatalogService) // Injiziert den umbenannten Service
|
||||
{
|
||||
_productCatalogService = productCatalogService;
|
||||
}
|
||||
|
||||
[HttpGet] // /api/v1/public/products
|
||||
public async Task<ActionResult<IEnumerable<ProductDto>>> GetAllProducts()
|
||||
{
|
||||
var products = await _productCatalogService.GetAllProductsAsync(); // Ruft Service-Methode auf
|
||||
return Ok(products);
|
||||
}
|
||||
// Keine POST, PUT, DELETE hier für öffentliche Zugriffe.
|
||||
// Diese gehören in den AdminProductsController.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user