try
This commit is contained in:
18
Webshop.Api/Controllers/Public/CategoriesController.cs
Normal file
18
Webshop.Api/Controllers/Public/CategoriesController.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Api.Controllers.Public
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/public/[controller]")]
|
||||
[AllowAnonymous]
|
||||
public class CategoriesController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webshop.Application.DTOs; // ProductDto
|
||||
using Webshop.Application.Services.Public; // ProductCatalogService
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Webshop.Application.DTOs;
|
||||
using Webshop.Application.Services.Public;
|
||||
|
||||
namespace Webshop.Api.Controllers.Public // Beachten Sie den Namespace
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Api.Controllers.Public
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/public/[controller]")] // z.B. /api/v1/public/products
|
||||
[AllowAnonymous] // Jeder darf hier zugreifen (Gast oder eingeloggter User)
|
||||
[Route("api/v1/public/[controller]")]
|
||||
[AllowAnonymous]
|
||||
public class ProductsController : ControllerBase
|
||||
{
|
||||
private readonly ProductService _productCatalogService; // Umbenannt
|
||||
private readonly ProductService _productService; // ServiceName nach Ihrer Konvention beibehalten
|
||||
|
||||
public ProductsController(ProductService productCatalogService) // Injiziert den umbenannten Service
|
||||
public ProductsController(ProductService productService)
|
||||
{
|
||||
_productCatalogService = productCatalogService;
|
||||
_productService = productService;
|
||||
}
|
||||
|
||||
[HttpGet] // /api/v1/public/products
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ProductDto>>> GetAllProducts()
|
||||
{
|
||||
var products = await _productCatalogService.GetAllProductsAsync(); // Ruft Service-Methode auf
|
||||
var products = await _productService.GetAllProductsAsync();
|
||||
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