66 lines
2.6 KiB
C#
66 lines
2.6 KiB
C#
// 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/[controller]")] // 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();
|
|
}
|
|
}
|
|
} |