supplier und migration

This commit is contained in:
Tizian.Breuch
2025-07-23 12:33:01 +02:00
parent c3292d6739
commit 1fe88fac3a
8 changed files with 195 additions and 3 deletions

View File

@@ -0,0 +1,44 @@
// 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;
namespace Webshop.Api.Controllers.Admin
{
[ApiController]
[Route("api/v1/admin/[controller]")] // z.B. /api/v1/admin/suppliers
[Authorize(Roles = "Admin")] // Nur Admins
public class AdminSuppliersController : ControllerBase
{
private readonly AdminSupplierService _adminSupplierService;
public AdminSuppliersController(AdminSupplierService adminSupplierService)
{
_adminSupplierService = adminSupplierService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<SupplierDto>>> GetAllSuppliers()
{
var suppliers = await _adminSupplierService.GetAllSuppliersAsync();
return Ok(suppliers);
}
[HttpPost]
public async Task<ActionResult<SupplierDto>> CreateSupplier([FromBody] SupplierDto supplierDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var createdSupplier = await _adminSupplierService.CreateSupplierAsync(supplierDto);
return CreatedAtAction(nameof(GetSupplierById), new { id = createdSupplier.Id }, createdSupplier);
}
[HttpGet("{id}")]
public async Task<ActionResult<SupplierDto>> GetSupplierById(Guid id)
{
var supplier = await _adminSupplierService.GetSupplierByIdAsync(id);
if (supplier == null) return NotFound();
return Ok(supplier);
}
}
}

View File

@@ -66,6 +66,7 @@ builder.Services.AddAuthorization(); // Aktiviert die Autorisierung
// 4. Unsere eigenen Interfaces und Klassen registrieren (Dependency Injection)
builder.Services.AddScoped<IProductRepository, ProductRepository>();
builder.Services.AddScoped<ISupplierRepository, SupplierRepository>(); // NEU
// AUTH Services
builder.Services.AddScoped<IAuthService, AuthService>();
@@ -76,6 +77,7 @@ builder.Services.AddScoped<ProductService>(); // Ihr ProductService ist hier reg
// ADMIN Services
builder.Services.AddScoped<AdminUserService>();
builder.Services.AddScoped<AdminProductService>();
builder.Services.AddScoped<AdminSupplierService>(); // NEU
// CUSTOMER Services (sp<73>ter Implementierungen hinzuf<75>gen)
// builder.Services.AddScoped<CustomerOrderService>();