direkt aus dem warenkorb holen
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 29s
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 29s
This commit is contained in:
@@ -9,6 +9,8 @@ using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Webshop.Application;
|
||||
using System.Collections.Generic;
|
||||
using Webshop.Application.Services.Customers;
|
||||
using Microsoft.AspNetCore.Cors.Infrastructure;
|
||||
|
||||
namespace Webshop.Api.Controllers.Customer
|
||||
{
|
||||
@@ -18,25 +20,34 @@ namespace Webshop.Api.Controllers.Customer
|
||||
public class CheckoutController : ControllerBase
|
||||
{
|
||||
private readonly ICheckoutService _checkoutService;
|
||||
private readonly ICartService _cartService;
|
||||
|
||||
public CheckoutController(ICheckoutService checkoutService)
|
||||
public CheckoutController(ICheckoutService checkoutService , ICartService cartService)
|
||||
{
|
||||
_checkoutService = checkoutService;
|
||||
_cartService = cartService;
|
||||
}
|
||||
|
||||
// --- NEU: Endpoint um verf<72>gbare Versandmethoden basierend auf dem Warenkorb zu holen ---
|
||||
[HttpPost("available-shipping-methods")]
|
||||
[HttpGet("available-shipping-methods")] // War vorher POST
|
||||
[ProducesResponseType(typeof(IEnumerable<ShippingMethodDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> GetAvailableShippingMethods([FromBody] ShippingCalculationRequestDto request)
|
||||
public async Task<IActionResult> GetAvailableShippingMethods()
|
||||
{
|
||||
var result = await _checkoutService.GetCompatibleShippingMethodsAsync(request.Items);
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
|
||||
// 1. Warenkorb laden
|
||||
var cartResult = await _cartService.GetCartAsync(userId!);
|
||||
if (cartResult.Value == null || !cartResult.Value.Items.Any())
|
||||
{
|
||||
return Ok(new List<ShippingMethodDto>()); // Leerer Korb -> keine Methoden
|
||||
}
|
||||
|
||||
// 2. Berechnung aufrufen (nutzt die Overload Methode mit List<CartItemDto>)
|
||||
var result = await _checkoutService.GetCompatibleShippingMethodsAsync(cartResult.Value.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." })
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = "Fehler." })
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user