categorys

This commit is contained in:
Tizian.Breuch
2025-07-31 15:14:51 +02:00
parent b608d116f0
commit 50ae33c258
13 changed files with 377 additions and 95 deletions

View File

@@ -1,18 +1,57 @@
// Auto-generiert von CreateWebshopFiles.ps1
using System;
// src/Webshop.Application/Services/Public/CategoryService.cs
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.Services.Public.Interfaces;
using Webshop.Application.DTOs.Categorys;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Public
{
public class CategoryService : ICategoryService
{
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
private readonly ICategoryRepository _categoryRepository;
// public CategoryService(IYourRepository repository) { }
public CategoryService(ICategoryRepository categoryRepository)
{
_categoryRepository = categoryRepository;
}
// Fügen Sie hier Service-Methoden hinzu
public async Task<IEnumerable<CategoryDto>> GetAllActiveAsync()
{
var categories = await _categoryRepository.GetAllAsync();
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
return categories
.Where(c => c.IsActive)
.Select(c => new CategoryDto
{
Id = c.Id,
Name = c.Name,
Slug = c.Slug,
Description = c.Description,
ParentCategoryId = c.ParentCategoryId,
ImageUrl = c.ImageUrl,
IsActive = c.IsActive,
DisplayOrder = c.DisplayOrder
}).ToList();
}
public async Task<CategoryDto?> GetBySlugAsync(string slug)
{
var category = await _categoryRepository.GetBySlugAsync(slug);
if (category == null || !category.IsActive) return null;
return new CategoryDto
{
Id = category.Id,
Name = category.Name,
Slug = category.Slug,
Description = category.Description,
ParentCategoryId = category.ParentCategoryId,
ImageUrl = category.ImageUrl,
IsActive = category.IsActive,
DisplayOrder = category.DisplayOrder
};
}
}
}
}