Files
ShopSolution-backend/Webshop.Application/Services/Public/CategoryService.cs
Tizian.Breuch 6f86d0de87 naming
2025-08-01 10:06:00 +02:00

57 lines
1.9 KiB
C#

// src/Webshop.Application/Services/Public/CategoryService.cs
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Categorys;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Public
{
public class CategoryService : ICategoryService
{
private readonly ICategoryRepository _categoryRepository;
public CategoryService(ICategoryRepository categoryRepository)
{
_categoryRepository = categoryRepository;
}
public async Task<IEnumerable<CategoryDto>> GetAllActiveAsync()
{
var categorys = await _categoryRepository.GetAllAsync();
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
return categorys
.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
};
}
}
}