This commit is contained in:
Tizian.Breuch
2025-08-01 15:11:42 +02:00
parent 96f082b38f
commit 55eeaca7f4
29 changed files with 452 additions and 452 deletions

View File

@@ -1,10 +1,10 @@
// src/Webshop.Api/Controllers/Admin/AdmincategorysController.cs
// src/Webshop.Api/Controllers/Admin/AdmincategoriesController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Categorys;
using Webshop.Application.DTOs.categories;
using Webshop.Application.Services.Admin;
namespace Webshop.Api.Controllers.Admin
@@ -12,51 +12,51 @@ namespace Webshop.Api.Controllers.Admin
[ApiController]
[Route("api/v1/admin/[controller]")]
[Authorize(Roles = "Admin")]
public class AdminCategorysController : ControllerBase
public class AdmincategoriesController : ControllerBase
{
private readonly IAdminCategoryService _adminCategoryService;
private readonly IAdminCategorieService _admincategorieservice;
public AdminCategorysController(IAdminCategoryService adminCategoryService)
public AdmincategoriesController(IAdminCategorieService admincategorieservice)
{
_adminCategoryService = adminCategoryService;
_admincategorieservice = admincategorieservice;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetAllcategorys()
public async Task<ActionResult<IEnumerable<categorieDto>>> GetAllcategories()
{
var categorys = await _adminCategoryService.GetAllAsync();
return Ok(categorys);
var categories = await _admincategorieservice.GetAllAsync();
return Ok(categories);
}
[HttpGet("{id}")]
public async Task<ActionResult<CategoryDto>> GetCategoryById(Guid id)
public async Task<ActionResult<categorieDto>> GetcategorieById(Guid id)
{
var category = await _adminCategoryService.GetByIdAsync(id);
if (category == null) return NotFound();
return Ok(category);
var categorie = await _admincategorieservice.GetByIdAsync(id);
if (categorie == null) return NotFound();
return Ok(categorie);
}
[HttpPost]
public async Task<ActionResult<CategoryDto>> CreateCategory([FromBody] CreateCategoryDto categoryDto)
public async Task<ActionResult<categorieDto>> Createcategorie([FromBody] CreatecategorieDto categorieDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var (createdCategory, errorMessage) = await _adminCategoryService.CreateAsync(categoryDto);
var (createdcategorie, errorMessage) = await _admincategorieservice.CreateAsync(categorieDto);
if (createdCategory == null)
if (createdcategorie == null)
{
return BadRequest(new { Message = errorMessage });
}
return CreatedAtAction(nameof(GetCategoryById), new { id = createdCategory.Id }, createdCategory);
return CreatedAtAction(nameof(GetcategorieById), new { id = createdcategorie.Id }, createdcategorie);
}
[HttpPut("{id}")]
public async Task<IActionResult> UpdateCategory(Guid id, [FromBody] CreateCategoryDto categoryDto)
public async Task<IActionResult> Updatecategorie(Guid id, [FromBody] CreatecategorieDto categorieDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var (success, errorMessage) = await _adminCategoryService.UpdateAsync(id, categoryDto);
var (success, errorMessage) = await _admincategorieservice.UpdateAsync(id, categorieDto);
if (!success)
{
@@ -67,9 +67,9 @@ namespace Webshop.Api.Controllers.Admin
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteCategory(Guid id)
public async Task<IActionResult> Deletecategorie(Guid id)
{
var success = await _adminCategoryService.DeleteAsync(id);
var success = await _admincategorieservice.DeleteAsync(id);
if (!success) return NotFound();
return NoContent();
}

View File

@@ -1,9 +1,9 @@
// src/Webshop.Api/Controllers/Public/categorysController.cs
// src/Webshop.Api/Controllers/Public/categoriesController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Categorys;
using Webshop.Application.DTOs.categories;
using Webshop.Application.Services.Public;
namespace Webshop.Api.Controllers.Public
@@ -11,28 +11,28 @@ namespace Webshop.Api.Controllers.Public
[ApiController]
[Route("api/v1/public/[controller]")]
[AllowAnonymous]
public class CategoryController : ControllerBase
public class categorieController : ControllerBase
{
private readonly ICategoryService _categoryService;
private readonly ICategorieService _categorieservice;
public CategoryController(ICategoryService categoryService)
public categorieController(ICategorieService categorieservice)
{
_categoryService = categoryService;
_categorieservice = categorieservice;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetActivecategorys()
public async Task<ActionResult<IEnumerable<categorieDto>>> GetActivecategories()
{
var categorys = await _categoryService.GetAllActiveAsync();
return Ok(categorys);
var categories = await _categorieservice.GetAllActiveAsync();
return Ok(categories);
}
[HttpGet("{slug}")]
public async Task<ActionResult<CategoryDto>> GetCategoryBySlug(string slug)
public async Task<ActionResult<categorieDto>> GetcategorieBySlug(string slug)
{
var category = await _categoryService.GetBySlugAsync(slug);
if (category == null) return NotFound();
return Ok(category);
var categorie = await _categorieservice.GetBySlugAsync(slug);
if (categorie == null) return NotFound();
return Ok(categorie);
}
}
}

View File

@@ -79,7 +79,7 @@ builder.Services.AddScoped<IProductRepository, ProductRepository>();
builder.Services.AddScoped<ISupplierRepository, SupplierRepository>();
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
builder.Services.AddScoped<IPaymentMethodRepository, PaymentMethodRepository>();
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
builder.Services.AddScoped<IcategorieRepository, categorieRepository>();
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddScoped<IShippingMethodRepository, ShippingMethodRepository>();
builder.Services.AddScoped<IAddressRepository, AddressRepository>();
@@ -91,12 +91,12 @@ builder.Services.AddScoped<ISettingRepository, SettingRepository>();
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddScoped<IProductService, ProductService>();
builder.Services.AddScoped<IPaymentMethodService, PaymentMethodService>();
builder.Services.AddScoped<ICategoryService, CategoryService>();
builder.Services.AddScoped<ICategorieService, CategorieService>();
builder.Services.AddScoped<IAdminUserService, AdminUserService>();
builder.Services.AddScoped<IAdminProductService, AdminProductService>();
builder.Services.AddScoped<IAdminSupplierService, AdminSupplierService>();
builder.Services.AddScoped<IAdminPaymentMethodService, AdminPaymentMethodService>();
builder.Services.AddScoped<IAdminCategoryService, AdminCategoryService>();
builder.Services.AddScoped<IAdminCategorieService, AdminCategorieService>();
builder.Services.AddScoped<IAdminOrderService, AdminOrderService>();
builder.Services.AddScoped<IAdminShippingMethodService, AdminShippingMethodService>();
builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>();

View File

@@ -6,7 +6,7 @@ using System;
using System.Collections.Generic;
using Webshop.Application.DTOs;
using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Categorys;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Customers;
using Webshop.Application.DTOs.Discounts;
using Webshop.Application.DTOs.Email;
@@ -115,7 +115,7 @@ namespace Webshop.Api.SwaggerFilters
["stockQuantity"] = new OpenApiInteger(100),
["imageUrl"] = new OpenApiString("https://example.com/images/public_prod.jpg"),
["slug"] = new OpenApiString($"public-produkt-beispiel-{uniqueId}"),
["categorys"] = new OpenApiArray
["categories"] = new OpenApiArray
{
new OpenApiObject
{
@@ -146,19 +146,19 @@ namespace Webshop.Api.SwaggerFilters
["lastModifiedDate"] = new OpenApiNull(),
["supplierId"] = new OpenApiNull(),
["purchasePrice"] = new OpenApiDouble(80.00),
["categoryIds"] = new OpenApiArray { new OpenApiString("EXISTING_CATEGORY_ID_HERE") }
["categorieIds"] = new OpenApiArray { new OpenApiString("EXISTING_categorie_ID_HERE") }
};
}
// --- Kategorien ---
else if (type == typeof(CreateCategoryDto))
else if (type == typeof(CreatecategorieDto))
{
schema.Example = new OpenApiObject
{
["name"] = new OpenApiString($"Neue Kategorie {uniqueId}"),
["slug"] = new OpenApiString($"neue-kategorie-{uniqueId}"),
["description"] = new OpenApiString("Eine Beschreibung für die neue Kategorie."),
["parentCategoryId"] = new OpenApiNull(),
["imageUrl"] = new OpenApiString("https://example.com/images/new_category.jpg"),
["parentcategorieId"] = new OpenApiNull(),
["imageUrl"] = new OpenApiString("https://example.com/images/new_categorie.jpg"),
["isActive"] = new OpenApiBoolean(true),
["displayOrder"] = new OpenApiInteger(1)
};

View File

@@ -4,15 +4,15 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs.Categorys
namespace Webshop.Application.DTOs.categories
{
public class CategoryDto
public class categorieDto
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public Guid? ParentCategoryId { get; set; }
public Guid? ParentcategorieId { get; set; }
public string? ImageUrl { get; set; }
public bool IsActive { get; set; }
public int DisplayOrder { get; set; }

View File

@@ -4,14 +4,14 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs.Categorys
namespace Webshop.Application.DTOs.categories
{
public class CreateCategoryDto
public class CreatecategorieDto
{
public string Name { get; set; } = string.Empty;
public string Slug { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public Guid? ParentCategoryId { get; set; }
public Guid? ParentcategorieId { get; set; }
public string? ImageUrl { get; set; }
public bool IsActive { get; set; } = true;
public int DisplayOrder { get; set; } = 0;

View File

@@ -24,6 +24,6 @@ namespace Webshop.Application.DTOs.Products
public DateTimeOffset? LastModifiedDate { get; set; }
public Guid? SupplierId { get; set; }
public decimal? PurchasePrice { get; set; }
public List<Guid> CategoryIds { get; set; } = new List<Guid>();
public List<Guid> categorieIds { get; set; } = new List<Guid>();
}
}

View File

@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Categorys;
using Webshop.Application.DTOs.categories;
namespace Webshop.Application.DTOs.Products
@@ -19,6 +19,6 @@ namespace Webshop.Application.DTOs.Products
public int StockQuantity { get; set; }
public string? ImageUrl { get; set; }
public string Slug { get; set; } = string.Empty;
public List<CategoryDto> categorys { get; set; } = new List<CategoryDto>();
public List<categorieDto> categories { get; set; } = new List<categorieDto>();
}
}

View File

@@ -0,0 +1,129 @@
// src/Webshop.Application/Services/Admin/Admincategorieservice.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Admin
{
public class AdminCategorieService : IAdminCategorieService
{
private readonly IcategorieRepository _categorieRepository;
public AdminCategorieService(IcategorieRepository categorieRepository)
{
_categorieRepository = categorieRepository;
}
public async Task<IEnumerable<categorieDto>> GetAllAsync()
{
var categories = await _categorieRepository.GetAllAsync();
return categories.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?> GetByIdAsync(Guid id)
{
var categorie = await _categorieRepository.GetByIdAsync(id);
if (categorie == null) 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
};
}
public async Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto)
{
var existingcategorie = await _categorieRepository.GetBySlugAsync(categorieDto.Slug);
if (existingcategorie != null)
{
return (null, "Eine Kategorie mit diesem Slug existiert bereits.");
}
var categorie = new categorie
{
Id = Guid.NewGuid(),
Name = categorieDto.Name,
Slug = categorieDto.Slug,
Description = categorieDto.Description,
ParentcategorieId = categorieDto.ParentcategorieId,
ImageUrl = categorieDto.ImageUrl,
IsActive = categorieDto.IsActive,
DisplayOrder = categorieDto.DisplayOrder,
CreatedDate = DateTimeOffset.UtcNow
};
await _categorieRepository.AddAsync(categorie);
var createdDto = 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
};
return (createdDto, null);
}
public async Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreatecategorieDto categorieDto)
{
var existingcategorie = await _categorieRepository.GetByIdAsync(id);
if (existingcategorie == null)
{
return (false, "Kategorie nicht gefunden.");
}
var categorieWithSameSlug = await _categorieRepository.GetBySlugAsync(categorieDto.Slug);
if (categorieWithSameSlug != null && categorieWithSameSlug.Id != id)
{
return (false, "Eine andere Kategorie mit diesem Slug existiert bereits.");
}
existingcategorie.Name = categorieDto.Name;
existingcategorie.Slug = categorieDto.Slug;
existingcategorie.Description = categorieDto.Description;
existingcategorie.ParentcategorieId = categorieDto.ParentcategorieId;
existingcategorie.ImageUrl = categorieDto.ImageUrl;
existingcategorie.IsActive = categorieDto.IsActive;
existingcategorie.DisplayOrder = categorieDto.DisplayOrder;
existingcategorie.LastModifiedDate = DateTimeOffset.UtcNow;
await _categorieRepository.UpdateAsync(existingcategorie);
return (true, null);
}
public async Task<bool> DeleteAsync(Guid id)
{
var categorie = await _categorieRepository.GetByIdAsync(id);
if (categorie == null) return false;
await _categorieRepository.DeleteAsync(id);
return true;
}
}
}

View File

@@ -1,129 +0,0 @@
// src/Webshop.Application/Services/Admin/AdminCategoryService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Categorys;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Admin
{
public class AdminCategoryService : IAdminCategoryService
{
private readonly ICategoryRepository _categoryRepository;
public AdminCategoryService(ICategoryRepository categoryRepository)
{
_categoryRepository = categoryRepository;
}
public async Task<IEnumerable<CategoryDto>> GetAllAsync()
{
var categorys = await _categoryRepository.GetAllAsync();
return categorys.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?> GetByIdAsync(Guid id)
{
var category = await _categoryRepository.GetByIdAsync(id);
if (category == null) 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
};
}
public async Task<(CategoryDto? CreatedCategory, string? ErrorMessage)> CreateAsync(CreateCategoryDto categoryDto)
{
var existingCategory = await _categoryRepository.GetBySlugAsync(categoryDto.Slug);
if (existingCategory != null)
{
return (null, "Eine Kategorie mit diesem Slug existiert bereits.");
}
var category = new Category
{
Id = Guid.NewGuid(),
Name = categoryDto.Name,
Slug = categoryDto.Slug,
Description = categoryDto.Description,
ParentCategoryId = categoryDto.ParentCategoryId,
ImageUrl = categoryDto.ImageUrl,
IsActive = categoryDto.IsActive,
DisplayOrder = categoryDto.DisplayOrder,
CreatedDate = DateTimeOffset.UtcNow
};
await _categoryRepository.AddAsync(category);
var createdDto = 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
};
return (createdDto, null);
}
public async Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreateCategoryDto categoryDto)
{
var existingCategory = await _categoryRepository.GetByIdAsync(id);
if (existingCategory == null)
{
return (false, "Kategorie nicht gefunden.");
}
var categoryWithSameSlug = await _categoryRepository.GetBySlugAsync(categoryDto.Slug);
if (categoryWithSameSlug != null && categoryWithSameSlug.Id != id)
{
return (false, "Eine andere Kategorie mit diesem Slug existiert bereits.");
}
existingCategory.Name = categoryDto.Name;
existingCategory.Slug = categoryDto.Slug;
existingCategory.Description = categoryDto.Description;
existingCategory.ParentCategoryId = categoryDto.ParentCategoryId;
existingCategory.ImageUrl = categoryDto.ImageUrl;
existingCategory.IsActive = categoryDto.IsActive;
existingCategory.DisplayOrder = categoryDto.DisplayOrder;
existingCategory.LastModifiedDate = DateTimeOffset.UtcNow;
await _categoryRepository.UpdateAsync(existingCategory);
return (true, null);
}
public async Task<bool> DeleteAsync(Guid id)
{
var category = await _categoryRepository.GetByIdAsync(id);
if (category == null) return false;
await _categoryRepository.DeleteAsync(id);
return true;
}
}
}

View File

@@ -27,7 +27,7 @@ namespace Webshop.Application.Services.Admin
{
// Wir verwenden den DbContext, um auch die Kategorien effizient mitzuladen
var products = await _context.Products
.Include(p => p.Productcategorys)
.Include(p => p.Productcategories)
.ToListAsync();
return products.Select(p => new AdminProductDto
@@ -48,14 +48,14 @@ namespace Webshop.Application.Services.Admin
LastModifiedDate = p.LastModifiedDate,
SupplierId = p.SupplierId,
PurchasePrice = p.PurchasePrice,
CategoryIds = p.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU >>
categorieIds = p.Productcategories.Select(pc => pc.categorieId).ToList() // << NEU >>
}).ToList();
}
public async Task<AdminProductDto?> GetAdminProductByIdAsync(Guid id)
{
var product = await _context.Products
.Include(p => p.Productcategorys) // << NEU: Lade die Join-Tabelle mit >>
.Include(p => p.Productcategories) // << NEU: Lade die Join-Tabelle mit >>
.FirstOrDefaultAsync(p => p.Id == id);
if (product == null) return null;
@@ -78,7 +78,7 @@ namespace Webshop.Application.Services.Admin
LastModifiedDate = product.LastModifiedDate,
SupplierId = product.SupplierId,
PurchasePrice = product.PurchasePrice,
CategoryIds = product.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU: Mappe die CategoryIds >>
categorieIds = product.Productcategories.Select(pc => pc.categorieId).ToList() // << NEU: Mappe die categorieIds >>
};
}
@@ -101,13 +101,13 @@ namespace Webshop.Application.Services.Admin
CreatedDate = DateTimeOffset.UtcNow,
SupplierId = productDto.SupplierId,
PurchasePrice = productDto.PurchasePrice,
Productcategorys = new List<ProductCategory>() // Initialisiere die Collection
Productcategories = new List<Productcategorie>() // Initialisiere die Collection
};
// << NEU: F<>ge die Kategorien hinzu >>
foreach (var categoryId in productDto.CategoryIds)
foreach (var categorieId in productDto.categorieIds)
{
newProduct.Productcategorys.Add(new ProductCategory { CategoryId = categoryId });
newProduct.Productcategories.Add(new Productcategorie { categorieId = categorieId });
}
await _productRepository.AddProductAsync(newProduct); // << KORREKT: VERWENDET AddProductAsync >>
@@ -119,7 +119,7 @@ namespace Webshop.Application.Services.Admin
public async Task<bool> UpdateAdminProductAsync(AdminProductDto productDto)
{
var existingProduct = await _context.Products
.Include(p => p.Productcategorys) // Lade die aktuellen Zuweisungen
.Include(p => p.Productcategories) // Lade die aktuellen Zuweisungen
.FirstOrDefaultAsync(p => p.Id == productDto.Id);
if (existingProduct == null) return false;
@@ -141,10 +141,10 @@ namespace Webshop.Application.Services.Admin
existingProduct.LastModifiedDate = DateTimeOffset.UtcNow;
// << NEU: Kategorien synchronisieren (alte l<>schen, neue hinzuf<75>gen) >>
existingProduct.Productcategorys.Clear();
foreach (var categoryId in productDto.CategoryIds)
existingProduct.Productcategories.Clear();
foreach (var categorieId in productDto.categorieIds)
{
existingProduct.Productcategorys.Add(new ProductCategory { ProductId = existingProduct.Id, CategoryId = categoryId });
existingProduct.Productcategories.Add(new Productcategorie { ProductId = existingProduct.Id, categorieId = categorieId });
}
// << ENDE NEUER TEIL >>

View File

@@ -0,0 +1,17 @@
// src/Webshop.Application/Services/Admin/IAdmincategorieservice.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
namespace Webshop.Application.Services.Admin
{
public interface IAdminCategorieService
{
Task<IEnumerable<categorieDto>> GetAllAsync();
Task<categorieDto?> GetByIdAsync(Guid id);
Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto);
Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreatecategorieDto categorieDto);
Task<bool> DeleteAsync(Guid id);
}
}

View File

@@ -1,17 +0,0 @@
// src/Webshop.Application/Services/Admin/IAdminCategoryService.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Categorys;
namespace Webshop.Application.Services.Admin
{
public interface IAdminCategoryService
{
Task<IEnumerable<CategoryDto>> GetAllAsync();
Task<CategoryDto?> GetByIdAsync(Guid id);
Task<(CategoryDto? CreatedCategory, string? ErrorMessage)> CreateAsync(CreateCategoryDto categoryDto);
Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreateCategoryDto categoryDto);
Task<bool> DeleteAsync(Guid id);
}
}

View 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
};
}
}
}

View File

@@ -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
};
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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()
};
}

View File

@@ -1,4 +1,4 @@
// src/Webshop.Domain/Entities/Category.cs
// src/Webshop.Domain/Entities/categorie.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@@ -9,7 +9,7 @@ namespace Webshop.Domain.Entities
/// <summary>
/// Zum Gruppieren und Organisieren von Produkten.
/// </summary>
public class Category
public class categorie
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid(); // Hinzufügen von Default-Wert
@@ -25,8 +25,8 @@ namespace Webshop.Domain.Entities
[MaxLength(255)]
public string Slug { get; set; } = string.Empty; // Hinzufügen von Default-Wert
[ForeignKey(nameof(ParentCategory))]
public Guid? ParentCategoryId { get; set; }
[ForeignKey(nameof(Parentcategorie))]
public Guid? ParentcategorieId { get; set; }
[MaxLength(2000)]
public string? ImageUrl { get; set; }
@@ -43,9 +43,9 @@ namespace Webshop.Domain.Entities
// << ENDE NEUE EIGENSCHAFTEN >>
// Navigation Properties
public virtual Category? ParentCategory { get; set; }
public virtual ICollection<Category> Subcategorys { get; set; } = new List<Category>();
public virtual ICollection<ProductCategory> Productcategorys { get; set; } = new List<ProductCategory>();
public virtual ICollection<CategoryDiscount> CategoryDiscounts { get; set; } = new List<CategoryDiscount>();
public virtual categorie? Parentcategorie { get; set; }
public virtual ICollection<categorie> Subcategories { get; set; } = new List<categorie>();
public virtual ICollection<Productcategorie> Productcategories { get; set; } = new List<Productcategorie>();
public virtual ICollection<categorieDiscount> categorieDiscounts { get; set; } = new List<categorieDiscount>();
}
}

View File

@@ -5,19 +5,19 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Webshop.Domain.Entities;
/// <summary>
/// Verknüpfungstabelle für die Viele-zu-Viele-Beziehung zwischen Category und Discount.
/// Verknüpfungstabelle für die Viele-zu-Viele-Beziehung zwischen categorie und Discount.
/// </summary>
public class CategoryDiscount
public class categorieDiscount
{
[Required]
[ForeignKey(nameof(Category))]
public Guid CategoryId { get; set; }
[ForeignKey(nameof(categorie))]
public Guid categorieId { get; set; }
[Required]
[ForeignKey(nameof(Discount))]
public Guid DiscountId { get; set; }
// Navigation Properties
public virtual Category Category { get; set; }
public virtual categorie categorie { get; set; }
public virtual Discount Discount { get; set; }
}

View File

@@ -51,5 +51,5 @@ public class Discount
// Navigation Properties
public virtual ICollection<ProductDiscount> ProductDiscounts { get; set; } = new List<ProductDiscount>();
public virtual ICollection<CategoryDiscount> CategoryDiscounts { get; set; } = new List<CategoryDiscount>();
public virtual ICollection<categorieDiscount> categorieDiscounts { get; set; } = new List<categorieDiscount>();
}

View File

@@ -67,5 +67,5 @@ public class Product
public virtual ICollection<ProductVariant> Variants { get; set; } = new List<ProductVariant>();
public virtual ICollection<Review> Reviews { get; set; } = new List<Review>();
public virtual ICollection<ProductDiscount> ProductDiscounts { get; set; } = new List<ProductDiscount>();
public virtual ICollection<ProductCategory> Productcategorys { get; set; } = new List<ProductCategory>();
public virtual ICollection<Productcategorie> Productcategories { get; set; } = new List<Productcategorie>();
}

View File

@@ -5,20 +5,20 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Webshop.Domain.Entities;
/// <summary>
/// Verknüpfungstabelle für die Viele-zu-Viele-Beziehung zwischen Category und Discount.
/// Verknüpfungstabelle für die Viele-zu-Viele-Beziehung zwischen categorie und Discount.
/// </summary>
public class ProductCategory
public class Productcategorie
{
// Composite Primary Key wird via Fluent API in Ihrem DbContext konfiguriert:
// modelBuilder.Entity<ProductCategory>().HasKey(pc => new { pc.ProductId, pc.CategoryId });
// modelBuilder.Entity<Productcategorie>().HasKey(pc => new { pc.ProductId, pc.categorieId });
[ForeignKey(nameof(Product))]
public Guid ProductId { get; set; }
[ForeignKey(nameof(Category))]
public Guid CategoryId { get; set; }
[ForeignKey(nameof(categorie))]
public Guid categorieId { get; set; }
// Navigation Properties
public virtual Product Product { get; set; }
public virtual Category Category { get; set; }
public virtual categorie categorie { get; set; }
}

View File

@@ -1,4 +1,4 @@
// src/Webshop.Domain/Interfaces/ICategoryRepository.cs
// src/Webshop.Domain/Interfaces/IcategorieRepository.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -6,13 +6,13 @@ using Webshop.Domain.Entities;
namespace Webshop.Domain.Interfaces
{
public interface ICategoryRepository
public interface IcategorieRepository
{
Task<IEnumerable<Category>> GetAllAsync();
Task<Category?> GetByIdAsync(Guid id);
Task<Category?> GetBySlugAsync(string slug);
Task AddAsync(Category category);
Task UpdateAsync(Category category);
Task<IEnumerable<categorie>> GetAllAsync();
Task<categorie?> GetByIdAsync(Guid id);
Task<categorie?> GetBySlugAsync(string slug);
Task AddAsync(categorie categorie);
Task UpdateAsync(categorie categorie);
Task DeleteAsync(Guid id);
}
}

View File

@@ -14,7 +14,7 @@ namespace Webshop.Infrastructure.Data
public DbSet<Product> Products { get; set; } = default!;
public DbSet<ProductVariant> ProductVariants { get; set; } = default!;
public DbSet<Category> categorys { get; set; } = default!;
public DbSet<categorie> categories { get; set; } = default!;
public DbSet<Customer> Customers { get; set; } = default!;
public DbSet<Address> Addresses { get; set; } = default!;
public DbSet<Order> Orders { get; set; } = default!;
@@ -26,9 +26,9 @@ namespace Webshop.Infrastructure.Data
public DbSet<PaymentMethod> PaymentMethods { get; set; } = default!;
public DbSet<Setting> Settings { get; set; } = default!;
public DbSet<ProductCategory> Productcategorys { get; set; } = default!;
public DbSet<Productcategorie> Productcategories { get; set; } = default!;
public DbSet<ProductDiscount> ProductDiscounts { get; set; } = default!;
public DbSet<CategoryDiscount> CategoryDiscounts { get; set; } = default!;
public DbSet<categorieDiscount> categorieDiscounts { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
@@ -45,13 +45,13 @@ namespace Webshop.Infrastructure.Data
}
}
modelBuilder.Entity<ProductCategory>().HasKey(pc => new { pc.ProductId, pc.CategoryId });
modelBuilder.Entity<Productcategorie>().HasKey(pc => new { pc.ProductId, pc.categorieId });
modelBuilder.Entity<ProductDiscount>().HasKey(pd => new { pd.ProductId, pd.DiscountId });
modelBuilder.Entity<CategoryDiscount>().HasKey(cd => new { cd.CategoryId, cd.DiscountId });
modelBuilder.Entity<categorieDiscount>().HasKey(cd => new { cd.categorieId, cd.DiscountId });
modelBuilder.Entity<Product>().HasIndex(p => p.SKU).IsUnique();
modelBuilder.Entity<Product>().HasIndex(p => p.Slug).IsUnique();
modelBuilder.Entity<Category>().HasIndex(c => c.Slug).IsUnique();
modelBuilder.Entity<categorie>().HasIndex(c => c.Slug).IsUnique();
modelBuilder.Entity<Discount>().HasIndex(d => d.CouponCode).IsUnique().HasFilter("\"CouponCode\" IS NOT NULL");
modelBuilder.Entity<Setting>().HasIndex(s => s.Key).IsUnique();
modelBuilder.Entity<Order>().HasIndex(o => o.OrderNumber).IsUnique();
@@ -99,10 +99,10 @@ namespace Webshop.Infrastructure.Data
modelBuilder.Entity<PaymentMethod>()
.Property(pm => pm.ProcessingFee).HasPrecision(18, 2);
modelBuilder.Entity<Category>()
.HasOne(c => c.ParentCategory)
.WithMany(c => c.Subcategorys)
.HasForeignKey(c => c.ParentCategoryId)
modelBuilder.Entity<categorie>()
.HasOne(c => c.Parentcategorie)
.WithMany(c => c.Subcategories)
.HasForeignKey(c => c.ParentcategorieId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<OrderItem>()

View File

@@ -218,7 +218,7 @@ namespace Webshop.Infrastructure.Migrations
b.ToTable("Addresses");
});
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorie", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
@@ -249,7 +249,7 @@ namespace Webshop.Infrastructure.Migrations
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<Guid?>("ParentCategoryId")
b.Property<Guid?>("ParentcategorieId")
.HasColumnType("uuid");
b.Property<string>("Slug")
@@ -259,27 +259,27 @@ namespace Webshop.Infrastructure.Migrations
b.HasKey("Id");
b.HasIndex("ParentCategoryId");
b.HasIndex("ParentcategorieId");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("categorys");
b.ToTable("categories");
});
modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorieDiscount", b =>
{
b.Property<Guid>("CategoryId")
b.Property<Guid>("categorieId")
.HasColumnType("uuid");
b.Property<Guid>("DiscountId")
.HasColumnType("uuid");
b.HasKey("CategoryId", "DiscountId");
b.HasKey("categorieId", "DiscountId");
b.HasIndex("DiscountId");
b.ToTable("CategoryDiscounts");
b.ToTable("categorieDiscounts");
});
modelBuilder.Entity("Webshop.Domain.Entities.Customer", b =>
@@ -655,19 +655,19 @@ namespace Webshop.Infrastructure.Migrations
b.ToTable("Products");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b =>
modelBuilder.Entity("Webshop.Domain.Entities.Productcategorie", b =>
{
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("CategoryId")
b.Property<Guid>("categorieId")
.HasColumnType("uuid");
b.HasKey("ProductId", "CategoryId");
b.HasKey("ProductId", "categorieId");
b.HasIndex("CategoryId");
b.HasIndex("categorieId");
b.ToTable("Productcategorys");
b.ToTable("Productcategories");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b =>
@@ -1006,31 +1006,31 @@ namespace Webshop.Infrastructure.Migrations
b.Navigation("Customer");
});
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorie", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "ParentCategory")
.WithMany("Subcategorys")
.HasForeignKey("ParentCategoryId")
b.HasOne("Webshop.Domain.Entities.categorie", "Parentcategorie")
.WithMany("Subcategories")
.HasForeignKey("ParentcategorieId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("ParentCategory");
b.Navigation("Parentcategorie");
});
modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorieDiscount", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "Category")
.WithMany("CategoryDiscounts")
.HasForeignKey("CategoryId")
b.HasOne("Webshop.Domain.Entities.categorie", "categorie")
.WithMany("categorieDiscounts")
.HasForeignKey("categorieId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Webshop.Domain.Entities.Discount", "Discount")
.WithMany("CategoryDiscounts")
.WithMany("categorieDiscounts")
.HasForeignKey("DiscountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
b.Navigation("categorie");
b.Navigation("Discount");
});
@@ -1117,21 +1117,21 @@ namespace Webshop.Infrastructure.Migrations
b.Navigation("Supplier");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b =>
modelBuilder.Entity("Webshop.Domain.Entities.Productcategorie", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "Category")
.WithMany("Productcategorys")
.HasForeignKey("CategoryId")
b.HasOne("Webshop.Domain.Entities.categorie", "categorie")
.WithMany("Productcategories")
.HasForeignKey("categorieId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Webshop.Domain.Entities.Product", "Product")
.WithMany("Productcategorys")
.WithMany("Productcategories")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
b.Navigation("categorie");
b.Navigation("Product");
});
@@ -1192,13 +1192,13 @@ namespace Webshop.Infrastructure.Migrations
b.Navigation("Address");
});
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorie", b =>
{
b.Navigation("CategoryDiscounts");
b.Navigation("categorieDiscounts");
b.Navigation("Productcategorys");
b.Navigation("Productcategories");
b.Navigation("Subcategorys");
b.Navigation("Subcategories");
});
modelBuilder.Entity("Webshop.Domain.Entities.Customer", b =>
@@ -1212,7 +1212,7 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Discount", b =>
{
b.Navigation("CategoryDiscounts");
b.Navigation("categorieDiscounts");
b.Navigation("ProductDiscounts");
});
@@ -1226,7 +1226,7 @@ namespace Webshop.Infrastructure.Migrations
{
b.Navigation("ProductDiscounts");
b.Navigation("Productcategorys");
b.Navigation("Productcategories");
b.Navigation("Reviews");

View File

@@ -13,14 +13,14 @@ namespace Webshop.Infrastructure.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "categorys",
name: "categories",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
Slug = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
ParentCategoryId = table.Column<Guid>(type: "uuid", nullable: true),
ParentcategorieId = table.Column<Guid>(type: "uuid", nullable: true),
ImageUrl = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
@@ -29,11 +29,11 @@ namespace Webshop.Infrastructure.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_categorys", x => x.Id);
table.PrimaryKey("PK_categories", x => x.Id);
table.ForeignKey(
name: "FK_categorys_categorys_ParentCategoryId",
column: x => x.ParentCategoryId,
principalTable: "categorys",
name: "FK_categories_categories_ParentcategorieId",
column: x => x.ParentcategorieId,
principalTable: "categories",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
@@ -154,25 +154,25 @@ namespace Webshop.Infrastructure.Migrations
});
migrationBuilder.CreateTable(
name: "CategoryDiscounts",
name: "categorieDiscounts",
columns: table => new
{
CategoryId = table.Column<Guid>(type: "uuid", nullable: false),
categorieId = table.Column<Guid>(type: "uuid", nullable: false),
DiscountId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CategoryDiscounts", x => new { x.CategoryId, x.DiscountId });
table.PrimaryKey("PK_categorieDiscounts", x => new { x.categorieId, x.DiscountId });
table.ForeignKey(
name: "FK_CategoryDiscounts_Discounts_DiscountId",
name: "FK_categorieDiscounts_Discounts_DiscountId",
column: x => x.DiscountId,
principalTable: "Discounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CategoryDiscounts_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "categorys",
name: "FK_categorieDiscounts_categories_categorieId",
column: x => x.categorieId,
principalTable: "categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@@ -450,25 +450,25 @@ namespace Webshop.Infrastructure.Migrations
});
migrationBuilder.CreateTable(
name: "Productcategorys",
name: "Productcategories",
columns: table => new
{
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
CategoryId = table.Column<Guid>(type: "uuid", nullable: false)
categorieId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Productcategorys", x => new { x.ProductId, x.CategoryId });
table.PrimaryKey("PK_Productcategories", x => new { x.ProductId, x.categorieId });
table.ForeignKey(
name: "FK_Productcategorys_Products_ProductId",
name: "FK_Productcategories_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Productcategorys_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "categorys",
name: "FK_Productcategories_categories_categorieId",
column: x => x.categorieId,
principalTable: "categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@@ -594,18 +594,18 @@ namespace Webshop.Infrastructure.Migrations
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_CategoryDiscounts_DiscountId",
table: "CategoryDiscounts",
name: "IX_categorieDiscounts_DiscountId",
table: "categorieDiscounts",
column: "DiscountId");
migrationBuilder.CreateIndex(
name: "IX_categorys_ParentCategoryId",
table: "categorys",
column: "ParentCategoryId");
name: "IX_categories_ParentcategorieId",
table: "categories",
column: "ParentcategorieId");
migrationBuilder.CreateIndex(
name: "IX_categorys_Slug",
table: "categorys",
name: "IX_categories_Slug",
table: "categories",
column: "Slug",
unique: true);
@@ -669,9 +669,9 @@ namespace Webshop.Infrastructure.Migrations
column: "ShippingMethodId");
migrationBuilder.CreateIndex(
name: "IX_Productcategorys_CategoryId",
table: "Productcategorys",
column: "CategoryId");
name: "IX_Productcategories_categorieId",
table: "Productcategories",
column: "categorieId");
migrationBuilder.CreateIndex(
name: "IX_ProductDiscounts_DiscountId",
@@ -763,13 +763,13 @@ namespace Webshop.Infrastructure.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CategoryDiscounts");
name: "categorieDiscounts");
migrationBuilder.DropTable(
name: "OrderItems");
migrationBuilder.DropTable(
name: "Productcategorys");
name: "Productcategories");
migrationBuilder.DropTable(
name: "ProductDiscounts");
@@ -802,7 +802,7 @@ namespace Webshop.Infrastructure.Migrations
name: "ProductVariants");
migrationBuilder.DropTable(
name: "categorys");
name: "categories");
migrationBuilder.DropTable(
name: "Discounts");

View File

@@ -215,7 +215,7 @@ namespace Webshop.Infrastructure.Migrations
b.ToTable("Addresses");
});
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorie", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
@@ -246,7 +246,7 @@ namespace Webshop.Infrastructure.Migrations
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<Guid?>("ParentCategoryId")
b.Property<Guid?>("ParentcategorieId")
.HasColumnType("uuid");
b.Property<string>("Slug")
@@ -256,27 +256,27 @@ namespace Webshop.Infrastructure.Migrations
b.HasKey("Id");
b.HasIndex("ParentCategoryId");
b.HasIndex("ParentcategorieId");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("categorys");
b.ToTable("categories");
});
modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorieDiscount", b =>
{
b.Property<Guid>("CategoryId")
b.Property<Guid>("categorieId")
.HasColumnType("uuid");
b.Property<Guid>("DiscountId")
.HasColumnType("uuid");
b.HasKey("CategoryId", "DiscountId");
b.HasKey("categorieId", "DiscountId");
b.HasIndex("DiscountId");
b.ToTable("CategoryDiscounts");
b.ToTable("categorieDiscounts");
});
modelBuilder.Entity("Webshop.Domain.Entities.Customer", b =>
@@ -652,19 +652,19 @@ namespace Webshop.Infrastructure.Migrations
b.ToTable("Products");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b =>
modelBuilder.Entity("Webshop.Domain.Entities.Productcategorie", b =>
{
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("CategoryId")
b.Property<Guid>("categorieId")
.HasColumnType("uuid");
b.HasKey("ProductId", "CategoryId");
b.HasKey("ProductId", "categorieId");
b.HasIndex("CategoryId");
b.HasIndex("categorieId");
b.ToTable("Productcategorys");
b.ToTable("Productcategories");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b =>
@@ -1003,31 +1003,31 @@ namespace Webshop.Infrastructure.Migrations
b.Navigation("Customer");
});
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorie", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "ParentCategory")
.WithMany("Subcategorys")
.HasForeignKey("ParentCategoryId")
b.HasOne("Webshop.Domain.Entities.categorie", "Parentcategorie")
.WithMany("Subcategories")
.HasForeignKey("ParentcategorieId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("ParentCategory");
b.Navigation("Parentcategorie");
});
modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorieDiscount", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "Category")
.WithMany("CategoryDiscounts")
.HasForeignKey("CategoryId")
b.HasOne("Webshop.Domain.Entities.categorie", "categorie")
.WithMany("categorieDiscounts")
.HasForeignKey("categorieId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Webshop.Domain.Entities.Discount", "Discount")
.WithMany("CategoryDiscounts")
.WithMany("categorieDiscounts")
.HasForeignKey("DiscountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
b.Navigation("categorie");
b.Navigation("Discount");
});
@@ -1114,21 +1114,21 @@ namespace Webshop.Infrastructure.Migrations
b.Navigation("Supplier");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b =>
modelBuilder.Entity("Webshop.Domain.Entities.Productcategorie", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "Category")
.WithMany("Productcategorys")
.HasForeignKey("CategoryId")
b.HasOne("Webshop.Domain.Entities.categorie", "categorie")
.WithMany("Productcategories")
.HasForeignKey("categorieId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Webshop.Domain.Entities.Product", "Product")
.WithMany("Productcategorys")
.WithMany("Productcategories")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
b.Navigation("categorie");
b.Navigation("Product");
});
@@ -1189,13 +1189,13 @@ namespace Webshop.Infrastructure.Migrations
b.Navigation("Address");
});
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
modelBuilder.Entity("Webshop.Domain.Entities.categorie", b =>
{
b.Navigation("CategoryDiscounts");
b.Navigation("categorieDiscounts");
b.Navigation("Productcategorys");
b.Navigation("Productcategories");
b.Navigation("Subcategorys");
b.Navigation("Subcategories");
});
modelBuilder.Entity("Webshop.Domain.Entities.Customer", b =>
@@ -1209,7 +1209,7 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Discount", b =>
{
b.Navigation("CategoryDiscounts");
b.Navigation("categorieDiscounts");
b.Navigation("ProductDiscounts");
});
@@ -1223,7 +1223,7 @@ namespace Webshop.Infrastructure.Migrations
{
b.Navigation("ProductDiscounts");
b.Navigation("Productcategorys");
b.Navigation("Productcategories");
b.Navigation("Reviews");

View File

@@ -1,4 +1,4 @@
// src/Webshop.Infrastructure/Repositories/CategoryRepository.cs
// src/Webshop.Infrastructure/Repositories/categorieRepository.cs
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
@@ -9,48 +9,48 @@ using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Repositories
{
public class CategoryRepository : ICategoryRepository
public class categorieRepository : IcategorieRepository
{
private readonly ApplicationDbContext _context;
public CategoryRepository(ApplicationDbContext context)
public categorieRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task<IEnumerable<Category>> GetAllAsync()
public async Task<IEnumerable<categorie>> GetAllAsync()
{
return await _context.categorys.ToListAsync();
return await _context.categories.ToListAsync();
}
public async Task<Category?> GetByIdAsync(Guid id)
public async Task<categorie?> GetByIdAsync(Guid id)
{
return await _context.categorys.FindAsync(id);
return await _context.categories.FindAsync(id);
}
public async Task<Category?> GetBySlugAsync(string slug)
public async Task<categorie?> GetBySlugAsync(string slug)
{
return await _context.categorys.FirstOrDefaultAsync(c => c.Slug == slug);
return await _context.categories.FirstOrDefaultAsync(c => c.Slug == slug);
}
public async Task AddAsync(Category category)
public async Task AddAsync(categorie categorie)
{
_context.categorys.Add(category);
_context.categories.Add(categorie);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(Category category)
public async Task UpdateAsync(categorie categorie)
{
_context.categorys.Update(category);
_context.categories.Update(categorie);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(Guid id)
{
var category = await _context.categorys.FindAsync(id);
if (category != null)
var categorie = await _context.categories.FindAsync(id);
if (categorie != null)
{
_context.categorys.Remove(category);
_context.categories.Remove(categorie);
await _context.SaveChangesAsync();
}
}