fix
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 25s

This commit is contained in:
Tizian.Breuch
2025-11-26 17:31:28 +01:00
parent 9c48f62ff0
commit de67e01f2c
4 changed files with 28 additions and 12 deletions

View File

@@ -3,8 +3,8 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application;
using Webshop.Application.DTOs.Customers;
using Webshop.Application.DTOs.Shipping;
using Webshop.Application.DTOs.Customers; // <--- DIESE ZEILE HAT GEFEHLT (für CartDto)
using Webshop.Application.DTOs.Shipping; // (für CartItemDto)
using Webshop.Application.Services.Customers.Interfaces;
using Webshop.Domain.Entities;
using Webshop.Infrastructure.Data;
@@ -20,10 +20,16 @@ namespace Webshop.Application.Services.Customers
_context = context;
}
// Die Implementierung muss exakt so aussehen:
public async Task<ServiceResult<CartDto>> GetCartAsync(string userId)
{
var cart = await GetCartEntity(userId);
if (cart == null) return ServiceResult.Ok(new CartDto()); // Leerer Warenkorb
// Wenn kein Warenkorb da ist, geben wir einen leeren zurück (Success)
if (cart == null)
{
return ServiceResult.Ok(new CartDto { UserId = userId });
}
var dto = new CartDto
{
@@ -36,6 +42,7 @@ namespace Webshop.Application.Services.Customers
Quantity = i.Quantity
}).ToList()
};
return ServiceResult.Ok(dto);
}
@@ -63,7 +70,8 @@ namespace Webshop.Application.Services.Customers
ProductVariantId = itemDto.ProductVariantId,
Quantity = itemDto.Quantity
};
cart.Items.Add(newItem); // Wichtig: Muss in CartItems DbSet landen
// WICHTIG: Zur Collection hinzufügen UND dem Context Bescheid geben
cart.Items.Add(newItem);
_context.CartItems.Add(newItem);
}