This commit is contained in:
Tizian.Breuch
2025-07-29 19:11:34 +02:00
parent 3907cba29d
commit 6fc6aaef3e
14 changed files with 375 additions and 31 deletions

View File

@@ -0,0 +1,66 @@
// src/Webshop.Api/Controllers/Admin/AdminPaymentMethodsController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Payments; // AdminPaymentMethodDto
using Webshop.Application.Services.Admin; // IAdminPaymentMethodService
namespace Webshop.Api.Controllers.Admin
{
[ApiController]
[Route("api/v1/admin/paymentmethods")] // Saubere Route
[Authorize(Roles = "Admin")] // Nur Admins
public class AdminPaymentMethodsController : ControllerBase
{
private readonly IAdminPaymentMethodService _adminPaymentMethodService;
public AdminPaymentMethodsController(IAdminPaymentMethodService adminPaymentMethodService)
{
_adminPaymentMethodService = adminPaymentMethodService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<AdminPaymentMethodDto>>> GetAllPaymentMethods()
{
var paymentMethods = await _adminPaymentMethodService.GetAllAsync();
return Ok(paymentMethods);
}
[HttpGet("{id}")]
public async Task<ActionResult<AdminPaymentMethodDto>> GetPaymentMethodById(Guid id)
{
var paymentMethod = await _adminPaymentMethodService.GetByIdAsync(id);
if (paymentMethod == null) return NotFound();
return Ok(paymentMethod);
}
[HttpPost]
public async Task<ActionResult<AdminPaymentMethodDto>> CreatePaymentMethod([FromBody] AdminPaymentMethodDto paymentMethodDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var createdPaymentMethod = await _adminPaymentMethodService.CreateAsync(paymentMethodDto);
return CreatedAtAction(nameof(GetPaymentMethodById), new { id = createdPaymentMethod.Id }, createdPaymentMethod);
}
[HttpPut("{id}")]
public async Task<IActionResult> UpdatePaymentMethod(Guid id, [FromBody] AdminPaymentMethodDto paymentMethodDto)
{
if (id != paymentMethodDto.Id) return BadRequest();
if (!ModelState.IsValid) return BadRequest(ModelState);
var success = await _adminPaymentMethodService.UpdateAsync(paymentMethodDto);
if (!success) return NotFound();
return NoContent(); // 204 No Content für erfolgreiches Update
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeletePaymentMethod(Guid id)
{
var success = await _adminPaymentMethodService.DeleteAsync(id);
if (!success) return NotFound();
return NoContent();
}
}
}

View File

@@ -0,0 +1,30 @@
// src/Webshop.Api/Controllers/Public/PaymentMethodsController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Payments; // PaymentMethodDto
using Webshop.Application.Services.Public; // IPaymentMethodService
namespace Webshop.Api.Controllers.Public
{
[ApiController]
[Route("api/v1/public/paymentmethods")] // Saubere Route
[AllowAnonymous] // Jeder darf die verfügbaren Zahlungsmethoden sehen
public class PaymentMethodsController : ControllerBase
{
private readonly IPaymentMethodService _paymentMethodService;
public PaymentMethodsController(IPaymentMethodService paymentMethodService)
{
_paymentMethodService = paymentMethodService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<PaymentMethodDto>>> GetActivePaymentMethods()
{
var paymentMethods = await _paymentMethodService.GetAllActiveAsync();
return Ok(paymentMethods);
}
}
}

View File

@@ -85,11 +85,13 @@ builder.Services.AddScoped<IAuthService, AuthService>();
// PUBLIC Services
builder.Services.AddScoped<IProductService, ProductService>();
builder.Services.AddScoped<IPaymentMethodService, PaymentMethodService>();
// ADMIN Services
builder.Services.AddScoped<IAdminUserService, AdminUserService>();
builder.Services.AddScoped<IAdminProductService, AdminProductService>();
builder.Services.AddScoped<IAdminSupplierService, AdminSupplierService>();
builder.Services.AddScoped<IAdminPaymentMethodService, AdminPaymentMethodService>();
// CUSTOMER Services (sp<73>ter Implementierungen hinzuf<75>gen)
builder.Services.AddScoped<ICustomerService, CustomerService>();

View File

@@ -16,6 +16,7 @@ using Webshop.Application.DTOs.Orders;
using Webshop.Application.DTOs.Discounts;
using Webshop.Application.DTOs.Categorys;
using Webshop.Api.Controllers.Auth;
using Webshop.Domain.Enums;
namespace Webshop.Api.SwaggerFilters
{