57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
// src/Webshop.Api/Controllers/Admin/AdminOrdersController.cs
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Webshop.Application.DTOs.Orders;
|
|
using Webshop.Application.Services.Admin;
|
|
using Webshop.Domain.Enums;
|
|
|
|
namespace Webshop.Api.Controllers.Admin
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/admin/[controller]")]
|
|
[Authorize(Roles = "Admin")]
|
|
public class AdminOrdersController : ControllerBase
|
|
{
|
|
private readonly IAdminOrderService _adminOrderService;
|
|
|
|
public AdminOrdersController(IAdminOrderService adminOrderService)
|
|
{
|
|
_adminOrderService = adminOrderService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<OrderSummaryDto>>> GetAllOrders()
|
|
{
|
|
var orders = await _adminOrderService.GetAllOrdersAsync();
|
|
return Ok(orders);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<OrderDetailDto>> GetOrderById(Guid id)
|
|
{
|
|
var order = await _adminOrderService.GetOrderByIdAsync(id);
|
|
if (order == null) return NotFound();
|
|
return Ok(order);
|
|
}
|
|
|
|
[HttpPut("{id}/status")]
|
|
public async Task<IActionResult> UpdateOrderStatus(Guid id, [FromBody] UpdateOrderStatusRequest request)
|
|
{
|
|
var (success, errorMessage) = await _adminOrderService.UpdateOrderStatusAsync(id, request.NewStatus);
|
|
if (!success)
|
|
{
|
|
return BadRequest(new { Message = errorMessage });
|
|
}
|
|
return NoContent();
|
|
}
|
|
|
|
// Ein kleines DTO für die Status-Update-Anfrage
|
|
public class UpdateOrderStatusRequest
|
|
{
|
|
public OrderStatus NewStatus { get; set; }
|
|
}
|
|
}
|
|
} |