slug
This commit is contained in:
@@ -1,32 +1,53 @@
|
|||||||
// Auto-generiert von CreateWebshopFiles.ps1
|
// src/Webshop.Api/Controllers/Public/ProductsController.cs
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Webshop.Application.Services.Public;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Webshop.Application.DTOs.Products;
|
using Webshop.Application.DTOs.Products;
|
||||||
|
using Webshop.Application.Services.Public.Interfaces; // <-- WICHTIGES USING HINZUF<55>GEN
|
||||||
|
|
||||||
namespace Webshop.Api.Controllers.Public
|
namespace Webshop.Api.Controllers.Public
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/v1/public/[controller]")]
|
[Route("api/v1/public/products")] // Route explizit gemacht f<>r Klarheit
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public class ProductsController : ControllerBase
|
public class ProductsController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ProductService _productService; // ServiceName nach Ihrer Konvention beibehalten
|
// --- KORREKTUR: Abh<62>ngigkeit vom Interface, nicht von der Klasse ---
|
||||||
|
private readonly IProductService _productService;
|
||||||
|
|
||||||
public ProductsController(ProductService productService)
|
public ProductsController(IProductService productService)
|
||||||
{
|
{
|
||||||
_productService = productService;
|
_productService = productService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ruft eine Liste aller <20>ffentlichen, aktiven Produkte ab.
|
||||||
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<ProductDto>), 200)]
|
||||||
public async Task<ActionResult<IEnumerable<ProductDto>>> GetAllProducts()
|
public async Task<ActionResult<IEnumerable<ProductDto>>> GetAllProducts()
|
||||||
{
|
{
|
||||||
var products = await _productService.GetAllProductsAsync();
|
var products = await _productService.GetAllProductsAsync();
|
||||||
return Ok(products);
|
return Ok(products);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ruft ein einzelnes <20>ffentliches Produkt anhand seines URL-Slugs ab.
|
||||||
|
/// </summary>
|
||||||
|
[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<ActionResult<ProductDto>> GetProductBySlug(string slug)
|
||||||
|
{
|
||||||
|
var product = await _productService.GetProductBySlugAsync(slug);
|
||||||
|
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(product);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/Webshop.Application/Services/Public/IProductService.cs
|
// RICHTIG - vollständig
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Webshop.Application.DTOs.Products;
|
using Webshop.Application.DTOs.Products;
|
||||||
@@ -8,7 +8,7 @@ namespace Webshop.Application.Services.Public.Interfaces
|
|||||||
public interface IProductService
|
public interface IProductService
|
||||||
{
|
{
|
||||||
Task<IEnumerable<ProductDto>> GetAllProductsAsync();
|
Task<IEnumerable<ProductDto>> GetAllProductsAsync();
|
||||||
// Task<ProductDto?> GetProductByIdAsync(Guid id); // Wenn Sie eine einzelne öffentliche Produktansicht brauchen
|
|
||||||
// Task<ProductDto> CreateProductAsync(ProductDto productDto); // Nur wenn Public Service auch Erstellung erlaubt
|
Task<ProductDto?> GetProductBySlugAsync(string slug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user