categorie
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Categorie;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
@@ -16,41 +18,41 @@ namespace Webshop.Application.Services.Public
|
||||
_categorieRepository = categorieRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CategorieDto>> GetAllActiveAsync()
|
||||
public async Task<ServiceResult<IEnumerable<CategorieDto>>> GetAllActiveAsync()
|
||||
{
|
||||
var categories = await _categorieRepository.GetAllAsync();
|
||||
|
||||
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
|
||||
return categories
|
||||
var activeCategories = categories
|
||||
.Where(c => c.IsActive)
|
||||
.Select(c => new CategorieDto
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Slug = c.Slug,
|
||||
Description = c.Description,
|
||||
ParentcategorieId = c.ParentcategorieId,
|
||||
ImageUrl = c.ImageUrl,
|
||||
IsActive = c.IsActive,
|
||||
DisplayOrder = c.DisplayOrder
|
||||
}).ToList();
|
||||
.Select(MapToDto)
|
||||
.ToList();
|
||||
|
||||
return ServiceResult.Ok<IEnumerable<CategorieDto>>(activeCategories);
|
||||
}
|
||||
|
||||
public async Task<CategorieDto?> GetBySlugAsync(string slug)
|
||||
public async Task<ServiceResult<CategorieDto>> GetBySlugAsync(string slug)
|
||||
{
|
||||
var categorie = await _categorieRepository.GetBySlugAsync(slug);
|
||||
if (categorie == null || !categorie.IsActive) return null;
|
||||
if (categorie == null || !categorie.IsActive)
|
||||
{
|
||||
return ServiceResult.Fail<CategorieDto>(ServiceResultType.NotFound, $"Kategorie mit dem Slug '{slug}' wurde nicht gefunden oder ist nicht aktiv.");
|
||||
}
|
||||
|
||||
return ServiceResult.Ok(MapToDto(categorie));
|
||||
}
|
||||
|
||||
private CategorieDto MapToDto(Categorie c)
|
||||
{
|
||||
return new CategorieDto
|
||||
{
|
||||
Id = categorie.Id,
|
||||
Name = categorie.Name,
|
||||
Slug = categorie.Slug,
|
||||
Description = categorie.Description,
|
||||
ParentcategorieId = categorie.ParentcategorieId,
|
||||
ImageUrl = categorie.ImageUrl,
|
||||
IsActive = categorie.IsActive,
|
||||
DisplayOrder = categorie.DisplayOrder
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Slug = c.Slug,
|
||||
Description = c.Description,
|
||||
ParentcategorieId = c.ParentcategorieId,
|
||||
ImageUrl = c.ImageUrl,
|
||||
IsActive = c.IsActive,
|
||||
DisplayOrder = c.DisplayOrder
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
// src/Webshop.Application/Services/Public/Icategorieservice.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Categorie;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface ICategorieService
|
||||
{
|
||||
Task<IEnumerable<CategorieDto>> GetAllActiveAsync();
|
||||
Task<CategorieDto?> GetBySlugAsync(string slug);
|
||||
Task<ServiceResult<IEnumerable<CategorieDto>>> GetAllActiveAsync();
|
||||
Task<ServiceResult<CategorieDto>> GetBySlugAsync(string slug);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user