This commit is contained in:
Tizian.Breuch
2025-07-25 16:23:16 +02:00
parent f318340f98
commit 2d6eeb7a50
4 changed files with 65 additions and 23 deletions

View File

@@ -17,5 +17,6 @@ namespace Webshop.Application.DTOs.Products
public bool IsInStock { get; set; }
public int StockQuantity { get; set; }
public string? ImageUrl { get; set; }
public string Slug { get; set; } = string.Empty;
}
}

View File

@@ -1,12 +1,9 @@
// Auto-generiert von CreateWebshopFiles.ps1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Domain.Interfaces;
using Webshop.Domain.Entities;
using Webshop.Application.DTOs.Products;
using Webshop.Application.Services.Public.Interfaces;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Public
{
@@ -19,9 +16,47 @@ namespace Webshop.Application.Services.Public
_productRepository = productRepository;
}
// HIER KOMMT DER VORHERIGE PRODUCTSERVICE CODE HIN (GetAllProductsAsync, CreateProductAsync etc.)
// Hier sind Platzhalter-Implementierungen, die Sie durch den vollständigen Code ersetzen müssen:
public async Task<IEnumerable<ProductDto>> GetAllProductsAsync() { return new List<ProductDto>(); }
public async Task<ProductDto> CreateProductAsync(ProductDto productDto) { return null; }
// Wir verwenden jetzt den von Ihnen vorgegebenen Namen
public async Task<IEnumerable<ProductDto>> GetAllProductsAsync()
{
var products = await _productRepository.GetAllProductsAsync();
return products
.Where(p => p.IsActive) // Nur aktive Produkte anzeigen
.Select(p => new ProductDto
{
Id = p.Id,
Name = p.Name,
Description = p.ShortDescription,
Price = p.Price,
SKU = p.SKU,
ImageUrl = p.ImageUrl,
IsInStock = p.IsInStock,
Slug = p.Slug // Mapping für Slug
}).ToList();
}
// Diese Methode wird hinzugefügt, um das Interface zu erfüllen
public async Task<ProductDto?> GetProductBySlugAsync(string slug)
{
var product = await _productRepository.GetBySlugAsync(slug);
if (product == null)
{
return null;
}
return new ProductDto
{
Id = product.Id,
Name = product.Name,
Description = product.Description,
Price = product.Price,
SKU = product.SKU,
ImageUrl = product.ImageUrl,
IsInStock = product.IsInStock,
Slug = product.Slug // Mapping für Slug
};
}
}
}
}