adminorder
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminOrdersController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Orders;
|
||||
using Webshop.Application.Services.Admin;
|
||||
using Webshop.Domain.Enums;
|
||||
@@ -23,29 +25,48 @@ namespace Webshop.Api.Controllers.Admin
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<OrderSummaryDto>>> GetAllOrders()
|
||||
[ProducesResponseType(typeof(IEnumerable<OrderSummaryDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAllOrders()
|
||||
{
|
||||
var orders = await _adminOrderService.GetAllOrdersAsync();
|
||||
return Ok(orders);
|
||||
var result = await _adminOrderService.GetAllOrdersAsync();
|
||||
return Ok(result.Value);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<OrderDetailDto>> GetOrderById(Guid id)
|
||||
[ProducesResponseType(typeof(OrderDetailDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetOrderById(Guid id)
|
||||
{
|
||||
var order = await _adminOrderService.GetOrderByIdAsync(id);
|
||||
if (order == null) return NotFound();
|
||||
return Ok(order);
|
||||
var result = await _adminOrderService.GetOrderByIdAsync(id);
|
||||
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => Ok(result.Value),
|
||||
ServiceResultType.NotFound => NotFound(new { Message = result.ErrorMessage }),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPut("{id}/status")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> UpdateOrderStatus(Guid id, [FromBody] UpdateOrderStatusRequest request)
|
||||
{
|
||||
var (success, errorMessage) = await _adminOrderService.UpdateOrderStatusAsync(id, request.NewStatus);
|
||||
if (!success)
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(new { Message = errorMessage });
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
return NoContent();
|
||||
|
||||
var result = await _adminOrderService.UpdateOrderStatusAsync(id, request.NewStatus);
|
||||
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => NoContent(),
|
||||
ServiceResultType.NotFound => NotFound(new { Message = result.ErrorMessage }),
|
||||
ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
|
||||
};
|
||||
}
|
||||
|
||||
// Ein kleines DTO f<>r die Status-Update-Anfrage
|
||||
|
||||
Reference in New Issue
Block a user