This commit is contained in:
Tizian.Breuch
2025-11-26 17:02:18 +01:00
parent 2e30755901
commit ee5abfd829
18 changed files with 1968 additions and 208 deletions

View File

@@ -4,9 +4,11 @@ using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
using Webshop.Application.Services.Customers.Interfaces;
using Webshop.Application.DTOs.Orders;
using Webshop.Application.DTOs.Shipping; // Neu
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Webshop.Application;
using System.Collections.Generic;
namespace Webshop.Api.Controllers.Customer
{
@@ -22,11 +24,26 @@ namespace Webshop.Api.Controllers.Customer
_checkoutService = checkoutService;
}
// --- NEU: Endpoint um verf<72>gbare Versandmethoden basierend auf dem Warenkorb zu holen ---
[HttpPost("available-shipping-methods")]
[ProducesResponseType(typeof(IEnumerable<ShippingMethodDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> GetAvailableShippingMethods([FromBody] ShippingCalculationRequestDto request)
{
var result = await _checkoutService.GetCompatibleShippingMethodsAsync(request.Items);
return result.Type switch
{
ServiceResultType.Success => Ok(result.Value),
ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }),
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = "Fehler beim Laden der Versandmethoden." })
};
}
[HttpPost("create-order")]
[ProducesResponseType(typeof(OrderDetailDto), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderDto orderDto)
{
@@ -35,7 +52,6 @@ namespace Webshop.Api.Controllers.Customer
return BadRequest(ModelState);
}
// UserId aus dem JWT-Token des eingeloggten Kunden extrahieren
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrEmpty(userId))
{
@@ -50,7 +66,7 @@ namespace Webshop.Api.Controllers.Customer
ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }),
ServiceResultType.Conflict => Conflict(new { Message = result.ErrorMessage }),
ServiceResultType.Unauthorized => Unauthorized(new { Message = result.ErrorMessage }),
ServiceResultType.Forbidden => Forbid(), // Forbid returns 403 without a body
ServiceResultType.Forbidden => Forbid(),
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
};
}