try
This commit is contained in:
18
Webshop.Api/Controllers/Admin/AdminCategoriesController.cs
Normal file
18
Webshop.Api/Controllers/Admin/AdminCategoriesController.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.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminCategoriesController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
18
Webshop.Api/Controllers/Admin/AdminDiscountsController.cs
Normal file
18
Webshop.Api/Controllers/Admin/AdminDiscountsController.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.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminDiscountsController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
18
Webshop.Api/Controllers/Admin/AdminOrdersController.cs
Normal file
18
Webshop.Api/Controllers/Admin/AdminOrdersController.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.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminOrdersController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webshop.Application.DTOs; // ProductDto and AdminProductDto
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Webshop.Application.DTOs;
|
||||
using Webshop.Application.Services.Admin;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")] // z.B. /api/v1/admin/products
|
||||
[Authorize(Roles = "Admin")] // Nur Benutzer mit der Rolle "Admin" dürfen zugreifen
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminProductsController : ControllerBase
|
||||
{
|
||||
private readonly AdminProductService _adminProductService;
|
||||
@@ -17,14 +22,14 @@ namespace Webshop.Api.Controllers.Admin
|
||||
_adminProductService = adminProductService;
|
||||
}
|
||||
|
||||
[HttpGet] // /api/v1/admin/products
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<AdminProductDto>>> GetAdminProducts()
|
||||
{
|
||||
var products = await _adminProductService.GetAllAdminProductsAsync();
|
||||
return Ok(products);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")] // /api/v1/admin/products/{id}
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<AdminProductDto>> GetAdminProduct(Guid id)
|
||||
{
|
||||
var product = await _adminProductService.GetAdminProductByIdAsync(id);
|
||||
@@ -32,7 +37,7 @@ namespace Webshop.Api.Controllers.Admin
|
||||
return Ok(product);
|
||||
}
|
||||
|
||||
[HttpPost] // /api/v1/admin/products
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<AdminProductDto>> CreateAdminProduct([FromBody] AdminProductDto productDto)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
@@ -40,18 +45,17 @@ namespace Webshop.Api.Controllers.Admin
|
||||
return CreatedAtAction(nameof(GetAdminProduct), new { id = createdProduct.Id }, createdProduct);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")] // /api/v1/admin/products/{id}
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateAdminProduct(Guid id, [FromBody] AdminProductDto productDto)
|
||||
{
|
||||
if (id != productDto.Id) return BadRequest();
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var success = await _adminProductService.UpdateAdminProductAsync(productDto);
|
||||
if (!success) return NotFound();
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")] // /api/v1/admin/products/{id}
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteAdminProduct(Guid id)
|
||||
{
|
||||
var success = await _adminProductService.DeleteAdminProductAsync(id);
|
||||
@@ -59,4 +63,4 @@ namespace Webshop.Api.Controllers.Admin
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
Webshop.Api/Controllers/Admin/AdminSettingsController.cs
Normal file
18
Webshop.Api/Controllers/Admin/AdminSettingsController.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.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminSettingsController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs
|
||||
// src/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webshop.Application.DTOs; // SupplierDto
|
||||
using Webshop.Application.Services.Admin;
|
||||
using Webshop.Application.Services.Admin; // AdminSupplierService
|
||||
using System.Collections.Generic; // Für IEnumerable
|
||||
using System.Threading.Tasks; // Für Task
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
@@ -11,6 +13,7 @@ namespace Webshop.Api.Controllers.Admin
|
||||
[Authorize(Roles = "Admin")] // Nur Admins
|
||||
public class AdminSuppliersController : ControllerBase
|
||||
{
|
||||
// HIER MUSS NUR EINE EINZIGE DEKLARATION STEHEN
|
||||
private readonly AdminSupplierService _adminSupplierService;
|
||||
|
||||
public AdminSuppliersController(AdminSupplierService adminSupplierService)
|
||||
@@ -1,13 +1,18 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webshop.Application.DTOs.Users; // UserDto
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Webshop.Application.DTOs.Users;
|
||||
using Webshop.Application.Services.Admin;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")] // z.B. /api/v1/admin/users
|
||||
[Authorize(Roles = "Admin")] // Nur Benutzer mit der Rolle "Admin" dürfen zugreifen
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminUsersController : ControllerBase
|
||||
{
|
||||
private readonly AdminUserService _adminUserService;
|
||||
@@ -17,20 +22,19 @@ namespace Webshop.Api.Controllers.Admin
|
||||
_adminUserService = adminUserService;
|
||||
}
|
||||
|
||||
[HttpGet] // /api/v1/admin/users
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<UserDto>>> GetAllUsers()
|
||||
{
|
||||
var users = await _adminUserService.GetAllUsersAsync();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("{userId}")] // /api/v1/admin/users/{userId}
|
||||
[HttpGet("{userId}")]
|
||||
public async Task<ActionResult<UserDto>> GetUserById(string userId)
|
||||
{
|
||||
var user = await _adminUserService.GetUserByIdAsync(userId);
|
||||
if (user == null) return NotFound();
|
||||
return Ok(user);
|
||||
}
|
||||
// TODO: Hier könnten weitere Methoden für User-Verwaltung (Rollen ändern, löschen etc.) hinzukommen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
Webshop.Api/Controllers/Customer/CheckoutController.cs
Normal file
18
Webshop.Api/Controllers/Customer/CheckoutController.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.Customer
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/customer/[controller]")]
|
||||
[Authorize(Roles = "Customer")]
|
||||
public class CheckoutController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
// using Webshop.Application.DTOs.Orders; // Später erstellen
|
||||
// using Webshop.Application.Services.Customer; // Später erstellen
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Webshop.Api.Controllers.Customer // Beachten Sie den Namespace
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Api.Controllers.Customer
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/customer/[controller]")] // z.B. /api/v1/customer/orders
|
||||
[Authorize(Roles = "Customer")] // Nur Benutzer mit der Rolle "Customer" dürfen zugreifen
|
||||
[Route("api/v1/customer/[controller]")]
|
||||
[Authorize(Roles = "Customer")]
|
||||
public class OrdersController : ControllerBase
|
||||
{
|
||||
// Beispiel-Endpunkt für eingeloggte Kunden
|
||||
[HttpGet("my-orders")]
|
||||
public async Task<IActionResult> GetMyOrders()
|
||||
{
|
||||
// Hier würden Sie die Bestellungen des eingeloggten Benutzers abrufen.
|
||||
// Die Benutzer-ID können Sie über User.FindFirstValue(ClaimTypes.NameIdentifier) abrufen.
|
||||
// return Ok(await _orderService.GetOrdersForCurrentUserAsync(User.FindFirstValue(ClaimTypes.NameIdentifier)));
|
||||
return Ok(new { Message = "Dies sind Ihre Bestellungen (Platzhalter)." });
|
||||
return Ok(new { Message = "Dies ist Ihr persönlicher Bestellverlauf (Platzhalter)." });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
Webshop.Api/Controllers/Customer/ProfileController.cs
Normal file
18
Webshop.Api/Controllers/Customer/ProfileController.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.Customer
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/customer/[controller]")]
|
||||
[Authorize(Roles = "Customer")]
|
||||
public class ProfileController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
18
Webshop.Api/Controllers/Customer/ReviewsController.cs
Normal file
18
Webshop.Api/Controllers/Customer/ReviewsController.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.Customer
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/customer/[controller]")]
|
||||
[Authorize(Roles = "Customer")]
|
||||
public class ReviewsController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
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