naming
This commit is contained in:
57
Webshop.Application/Services/Public/CategorieService.cs
Normal file
57
Webshop.Application/Services/Public/CategorieService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
// src/Webshop.Application/Services/Public/categorieservice.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.categories;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public class CategorieService : ICategorieService
|
||||
{
|
||||
private readonly IcategorieRepository _categorieRepository;
|
||||
|
||||
public CategorieService(IcategorieRepository categorieRepository)
|
||||
{
|
||||
_categorieRepository = categorieRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<categorieDto>> GetAllActiveAsync()
|
||||
{
|
||||
var categories = await _categorieRepository.GetAllAsync();
|
||||
|
||||
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
|
||||
return 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();
|
||||
}
|
||||
|
||||
public async Task<categorieDto?> GetBySlugAsync(string slug)
|
||||
{
|
||||
var categorie = await _categorieRepository.GetBySlugAsync(slug);
|
||||
if (categorie == null || !categorie.IsActive) return null;
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
// 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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// src/Webshop.Application/Services/Public/Icategorieservice.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.categories;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface ICategorieService
|
||||
{
|
||||
Task<IEnumerable<categorieDto>> GetAllActiveAsync();
|
||||
Task<categorieDto?> GetBySlugAsync(string slug);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// src/Webshop.Application/Services/Public/ICategoryService.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface ICategoryService
|
||||
{
|
||||
Task<IEnumerable<CategoryDto>> GetAllActiveAsync();
|
||||
Task<CategoryDto?> GetBySlugAsync(string slug);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; // << NEU: Für Include() und ThenInclude()
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys; // Für CategoryDto
|
||||
using Webshop.Application.DTOs.categories; // Für categorieDto
|
||||
using Webshop.Application.DTOs.Products; // Für ProductDto
|
||||
using Webshop.Application.Services.Public.Interfaces; // Für IProductService
|
||||
using Webshop.Domain.Interfaces; // Für IProductRepository
|
||||
@@ -26,8 +26,8 @@ namespace Webshop.Application.Services.Public
|
||||
{
|
||||
// Wir verwenden den DbContext, um Produkte und ihre Kategorien zu laden
|
||||
var products = await _context.Products
|
||||
.Include(p => p.Productcategorys) // Lade die Join-Tabelle
|
||||
.ThenInclude(pc => pc.Category) // Lade die zugehörige Kategorie-Entität
|
||||
.Include(p => p.Productcategories) // Lade die Join-Tabelle
|
||||
.ThenInclude(pc => pc.categorie) // Lade die zugehörige Kategorie-Entität
|
||||
.Where(p => p.IsActive) // Nur aktive Produkte
|
||||
.ToListAsync();
|
||||
|
||||
@@ -41,12 +41,12 @@ namespace Webshop.Application.Services.Public
|
||||
ImageUrl = p.ImageUrl,
|
||||
IsInStock = p.IsInStock,
|
||||
Slug = p.Slug,
|
||||
categorys = p.Productcategorys.Select(pc => new CategoryDto
|
||||
categories = p.Productcategories.Select(pc => new categorieDto
|
||||
{
|
||||
Id = pc.Category.Id,
|
||||
Name = pc.Category.Name,
|
||||
Slug = pc.Category.Slug
|
||||
// ... weitere CategoryDto-Felder bei Bedarf
|
||||
Id = pc.categorie.Id,
|
||||
Name = pc.categorie.Name,
|
||||
Slug = pc.categorie.Slug
|
||||
// ... weitere categorieDto-Felder bei Bedarf
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
@@ -54,8 +54,8 @@ namespace Webshop.Application.Services.Public
|
||||
public async Task<ProductDto?> GetProductBySlugAsync(string slug)
|
||||
{
|
||||
var product = await _context.Products
|
||||
.Include(p => p.Productcategorys)
|
||||
.ThenInclude(pc => pc.Category)
|
||||
.Include(p => p.Productcategories)
|
||||
.ThenInclude(pc => pc.categorie)
|
||||
.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); // Nur aktives Produkt finden
|
||||
|
||||
if (product == null)
|
||||
@@ -73,11 +73,11 @@ namespace Webshop.Application.Services.Public
|
||||
ImageUrl = product.ImageUrl,
|
||||
IsInStock = product.IsInStock,
|
||||
Slug = product.Slug,
|
||||
categorys = product.Productcategorys.Select(pc => new CategoryDto
|
||||
categories = product.Productcategories.Select(pc => new categorieDto
|
||||
{
|
||||
Id = pc.Category.Id,
|
||||
Name = pc.Category.Name,
|
||||
Slug = pc.Category.Slug
|
||||
Id = pc.categorie.Id,
|
||||
Name = pc.categorie.Name,
|
||||
Slug = pc.categorie.Slug
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user