payment
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Webshop.Api/Controllers/Public/PaymentMethodsController.cs
Normal file
30
Webshop.Api/Controllers/Public/PaymentMethodsController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user