diff --git a/Webshop.Api/Controllers/Public/ProductsController.cs b/Webshop.Api/Controllers/Public/ProductsController.cs index 855af42..2f7a5c4 100644 --- a/Webshop.Api/Controllers/Public/ProductsController.cs +++ b/Webshop.Api/Controllers/Public/ProductsController.cs @@ -1,32 +1,53 @@ -// Auto-generiert von CreateWebshopFiles.ps1 +// src/Webshop.Api/Controllers/Public/ProductsController.cs using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; -using Webshop.Application.Services.Public; - -using System; using System.Collections.Generic; using System.Threading.Tasks; using Webshop.Application.DTOs.Products; +using Webshop.Application.Services.Public.Interfaces; // <-- WICHTIGES USING HINZUFÜGEN namespace Webshop.Api.Controllers.Public { [ApiController] - [Route("api/v1/public/[controller]")] + [Route("api/v1/public/products")] // Route explizit gemacht für Klarheit [AllowAnonymous] public class ProductsController : ControllerBase { - private readonly ProductService _productService; // ServiceName nach Ihrer Konvention beibehalten + // --- KORREKTUR: Abhängigkeit vom Interface, nicht von der Klasse --- + private readonly IProductService _productService; - public ProductsController(ProductService productService) + public ProductsController(IProductService productService) { _productService = productService; } + /// + /// Ruft eine Liste aller öffentlichen, aktiven Produkte ab. + /// [HttpGet] + [ProducesResponseType(typeof(IEnumerable), 200)] public async Task>> GetAllProducts() { var products = await _productService.GetAllProductsAsync(); return Ok(products); } + + /// + /// Ruft ein einzelnes öffentliches Produkt anhand seines URL-Slugs ab. + /// + [HttpGet("{slug}")] // Ergibt die Route z.B. /api/v1/public/products/mein-produkt-slug + [ProducesResponseType(typeof(ProductDto), 200)] + [ProducesResponseType(404)] // Not Found + public async Task> GetProductBySlug(string slug) + { + var product = await _productService.GetProductBySlugAsync(slug); + + if (product == null) + { + return NotFound(); + } + + return Ok(product); + } } -} +} \ No newline at end of file diff --git a/Webshop.Application/Services/Public/Interfaces/IProductService.cs b/Webshop.Application/Services/Public/Interfaces/IProductService.cs index ae04b7b..4d55b7f 100644 --- a/Webshop.Application/Services/Public/Interfaces/IProductService.cs +++ b/Webshop.Application/Services/Public/Interfaces/IProductService.cs @@ -1,4 +1,4 @@ -// src/Webshop.Application/Services/Public/IProductService.cs +// RICHTIG - vollständig using System.Collections.Generic; using System.Threading.Tasks; using Webshop.Application.DTOs.Products; @@ -8,7 +8,7 @@ namespace Webshop.Application.Services.Public.Interfaces public interface IProductService { Task> GetAllProductsAsync(); - // Task GetProductByIdAsync(Guid id); // Wenn Sie eine einzelne öffentliche Produktansicht brauchen - // Task CreateProductAsync(ProductDto productDto); // Nur wenn Public Service auch Erstellung erlaubt + + Task GetProductBySlugAsync(string slug); } } \ No newline at end of file