diff --git a/Webshop.Api/Controllers/Admin/AdminCategoryController.cs b/Webshop.Api/Controllers/Admin/AdminCategoryController.cs index e840703..c89da62 100644 --- a/Webshop.Api/Controllers/Admin/AdminCategoryController.cs +++ b/Webshop.Api/Controllers/Admin/AdminCategoryController.cs @@ -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>> GetAllcategorys() + public async Task>> GetAllcategories() { - var categorys = await _adminCategoryService.GetAllAsync(); - return Ok(categorys); + var categories = await _admincategorieservice.GetAllAsync(); + return Ok(categories); } [HttpGet("{id}")] - public async Task> GetCategoryById(Guid id) + public async Task> 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> CreateCategory([FromBody] CreateCategoryDto categoryDto) + public async Task> 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 UpdateCategory(Guid id, [FromBody] CreateCategoryDto categoryDto) + public async Task 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 DeleteCategory(Guid id) + public async Task Deletecategorie(Guid id) { - var success = await _adminCategoryService.DeleteAsync(id); + var success = await _admincategorieservice.DeleteAsync(id); if (!success) return NotFound(); return NoContent(); } diff --git a/Webshop.Api/Controllers/Public/CategoryController.cs b/Webshop.Api/Controllers/Public/CategoryController.cs index bf3d38b..66352fe 100644 --- a/Webshop.Api/Controllers/Public/CategoryController.cs +++ b/Webshop.Api/Controllers/Public/CategoryController.cs @@ -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>> GetActivecategorys() + public async Task>> GetActivecategories() { - var categorys = await _categoryService.GetAllActiveAsync(); - return Ok(categorys); + var categories = await _categorieservice.GetAllActiveAsync(); + return Ok(categories); } [HttpGet("{slug}")] - public async Task> GetCategoryBySlug(string slug) + public async Task> 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); } } } \ No newline at end of file diff --git a/Webshop.Api/Program.cs b/Webshop.Api/Program.cs index 4424b58..7cf37c0 100644 --- a/Webshop.Api/Program.cs +++ b/Webshop.Api/Program.cs @@ -79,7 +79,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -91,12 +91,12 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs b/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs index 4edff89..a64a4c0 100644 --- a/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs +++ b/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs @@ -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) }; diff --git a/Webshop.Application/DTOs/Categorys/CategoryDto.cs b/Webshop.Application/DTOs/Categories/CategoryDto.cs similarity index 79% rename from Webshop.Application/DTOs/Categorys/CategoryDto.cs rename to Webshop.Application/DTOs/Categories/CategoryDto.cs index 73c635b..769a510 100644 --- a/Webshop.Application/DTOs/Categorys/CategoryDto.cs +++ b/Webshop.Application/DTOs/Categories/CategoryDto.cs @@ -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; } diff --git a/Webshop.Application/DTOs/Categorys/CreateCategoryDto.cs b/Webshop.Application/DTOs/Categories/CreateCategoryDto.cs similarity index 77% rename from Webshop.Application/DTOs/Categorys/CreateCategoryDto.cs rename to Webshop.Application/DTOs/Categories/CreateCategoryDto.cs index e3d2f74..f5d0dc6 100644 --- a/Webshop.Application/DTOs/Categorys/CreateCategoryDto.cs +++ b/Webshop.Application/DTOs/Categories/CreateCategoryDto.cs @@ -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; diff --git a/Webshop.Application/DTOs/Products/AdminProductDto.cs b/Webshop.Application/DTOs/Products/AdminProductDto.cs index f7f79bd..62248b8 100644 --- a/Webshop.Application/DTOs/Products/AdminProductDto.cs +++ b/Webshop.Application/DTOs/Products/AdminProductDto.cs @@ -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 CategoryIds { get; set; } = new List(); + public List categorieIds { get; set; } = new List(); } } diff --git a/Webshop.Application/DTOs/Products/ProductDto.cs b/Webshop.Application/DTOs/Products/ProductDto.cs index b2ab613..5a43d4f 100644 --- a/Webshop.Application/DTOs/Products/ProductDto.cs +++ b/Webshop.Application/DTOs/Products/ProductDto.cs @@ -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 categorys { get; set; } = new List(); + public List categories { get; set; } = new List(); } } diff --git a/Webshop.Application/Services/Admin/AdminCategorieService.cs b/Webshop.Application/Services/Admin/AdminCategorieService.cs new file mode 100644 index 0000000..6cbba28 --- /dev/null +++ b/Webshop.Application/Services/Admin/AdminCategorieService.cs @@ -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> 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 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 DeleteAsync(Guid id) + { + var categorie = await _categorieRepository.GetByIdAsync(id); + if (categorie == null) return false; + + await _categorieRepository.DeleteAsync(id); + return true; + } + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Admin/AdminCategoryService.cs b/Webshop.Application/Services/Admin/AdminCategoryService.cs deleted file mode 100644 index 2cbfff7..0000000 --- a/Webshop.Application/Services/Admin/AdminCategoryService.cs +++ /dev/null @@ -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> 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 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 DeleteAsync(Guid id) - { - var category = await _categoryRepository.GetByIdAsync(id); - if (category == null) return false; - - await _categoryRepository.DeleteAsync(id); - return true; - } - } -} \ No newline at end of file diff --git a/Webshop.Application/Services/Admin/AdminProductService.cs b/Webshop.Application/Services/Admin/AdminProductService.cs index e078d70..3d974dc 100644 --- a/Webshop.Application/Services/Admin/AdminProductService.cs +++ b/Webshop.Application/Services/Admin/AdminProductService.cs @@ -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 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() // Initialisiere die Collection + Productcategories = new List() // 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 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ü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 >> diff --git a/Webshop.Application/Services/Admin/Interfaces/IAdminCategorieService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminCategorieService.cs new file mode 100644 index 0000000..60b53cd --- /dev/null +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminCategorieService.cs @@ -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> GetAllAsync(); + Task GetByIdAsync(Guid id); + Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto); + Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreatecategorieDto categorieDto); + Task DeleteAsync(Guid id); + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Admin/Interfaces/IAdminCategoryService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminCategoryService.cs deleted file mode 100644 index c425709..0000000 --- a/Webshop.Application/Services/Admin/Interfaces/IAdminCategoryService.cs +++ /dev/null @@ -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> GetAllAsync(); - Task GetByIdAsync(Guid id); - Task<(CategoryDto? CreatedCategory, string? ErrorMessage)> CreateAsync(CreateCategoryDto categoryDto); - Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreateCategoryDto categoryDto); - Task DeleteAsync(Guid id); - } -} \ No newline at end of file diff --git a/Webshop.Application/Services/Public/CategorieService.cs b/Webshop.Application/Services/Public/CategorieService.cs new file mode 100644 index 0000000..9404ad7 --- /dev/null +++ b/Webshop.Application/Services/Public/CategorieService.cs @@ -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> 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 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 + }; + } + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Public/CategoryService.cs b/Webshop.Application/Services/Public/CategoryService.cs deleted file mode 100644 index 6db7e32..0000000 --- a/Webshop.Application/Services/Public/CategoryService.cs +++ /dev/null @@ -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> 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 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 - }; - } - } -} \ No newline at end of file diff --git a/Webshop.Application/Services/Public/Interfaces/ICategorieService.cs b/Webshop.Application/Services/Public/Interfaces/ICategorieService.cs new file mode 100644 index 0000000..ee3e19a --- /dev/null +++ b/Webshop.Application/Services/Public/Interfaces/ICategorieService.cs @@ -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> GetAllActiveAsync(); + Task GetBySlugAsync(string slug); + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Public/Interfaces/ICategoryService.cs b/Webshop.Application/Services/Public/Interfaces/ICategoryService.cs deleted file mode 100644 index 8be654d..0000000 --- a/Webshop.Application/Services/Public/Interfaces/ICategoryService.cs +++ /dev/null @@ -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> GetAllActiveAsync(); - Task GetBySlugAsync(string slug); - } -} \ No newline at end of file diff --git a/Webshop.Application/Services/Public/ProductService.cs b/Webshop.Application/Services/Public/ProductService.cs index 9d20c44..4524b2f 100644 --- a/Webshop.Application/Services/Public/ProductService.cs +++ b/Webshop.Application/Services/Public/ProductService.cs @@ -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 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() }; } diff --git a/Webshop.Domain/Entities/Category.cs b/Webshop.Domain/Entities/Category.cs index 6eeb838..2a7196f 100644 --- a/Webshop.Domain/Entities/Category.cs +++ b/Webshop.Domain/Entities/Category.cs @@ -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 /// /// Zum Gruppieren und Organisieren von Produkten. /// - 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 Subcategorys { get; set; } = new List(); - public virtual ICollection Productcategorys { get; set; } = new List(); - public virtual ICollection CategoryDiscounts { get; set; } = new List(); + public virtual categorie? Parentcategorie { get; set; } + public virtual ICollection Subcategories { get; set; } = new List(); + public virtual ICollection Productcategories { get; set; } = new List(); + public virtual ICollection categorieDiscounts { get; set; } = new List(); } } \ No newline at end of file diff --git a/Webshop.Domain/Entities/CategoryDiscount.cs b/Webshop.Domain/Entities/CategoryDiscount.cs index 0464794..b51f346 100644 --- a/Webshop.Domain/Entities/CategoryDiscount.cs +++ b/Webshop.Domain/Entities/CategoryDiscount.cs @@ -5,19 +5,19 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Webshop.Domain.Entities; /// -/// 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. /// -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; } } \ No newline at end of file diff --git a/Webshop.Domain/Entities/Discount.cs b/Webshop.Domain/Entities/Discount.cs index 620e895..0d9da8d 100644 --- a/Webshop.Domain/Entities/Discount.cs +++ b/Webshop.Domain/Entities/Discount.cs @@ -51,5 +51,5 @@ public class Discount // Navigation Properties public virtual ICollection ProductDiscounts { get; set; } = new List(); - public virtual ICollection CategoryDiscounts { get; set; } = new List(); + public virtual ICollection categorieDiscounts { get; set; } = new List(); } \ No newline at end of file diff --git a/Webshop.Domain/Entities/Product.cs b/Webshop.Domain/Entities/Product.cs index e5b10c1..4df2ed8 100644 --- a/Webshop.Domain/Entities/Product.cs +++ b/Webshop.Domain/Entities/Product.cs @@ -67,5 +67,5 @@ public class Product public virtual ICollection Variants { get; set; } = new List(); public virtual ICollection Reviews { get; set; } = new List(); public virtual ICollection ProductDiscounts { get; set; } = new List(); - public virtual ICollection Productcategorys { get; set; } = new List(); + public virtual ICollection Productcategories { get; set; } = new List(); } diff --git a/Webshop.Domain/Entities/ProductCategory.cs b/Webshop.Domain/Entities/ProductCategory.cs index eb679c7..b140e42 100644 --- a/Webshop.Domain/Entities/ProductCategory.cs +++ b/Webshop.Domain/Entities/ProductCategory.cs @@ -5,20 +5,20 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Webshop.Domain.Entities; /// -/// 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. /// -public class ProductCategory +public class Productcategorie { // Composite Primary Key wird via Fluent API in Ihrem DbContext konfiguriert: - // modelBuilder.Entity().HasKey(pc => new { pc.ProductId, pc.CategoryId }); + // modelBuilder.Entity().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; } } \ No newline at end of file diff --git a/Webshop.Domain/Interfaces/ICategoryRepository.cs b/Webshop.Domain/Interfaces/ICategoryRepository.cs index 9034032..3429cc5 100644 --- a/Webshop.Domain/Interfaces/ICategoryRepository.cs +++ b/Webshop.Domain/Interfaces/ICategoryRepository.cs @@ -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> GetAllAsync(); - Task GetByIdAsync(Guid id); - Task GetBySlugAsync(string slug); - Task AddAsync(Category category); - Task UpdateAsync(Category category); + Task> GetAllAsync(); + Task GetByIdAsync(Guid id); + Task GetBySlugAsync(string slug); + Task AddAsync(categorie categorie); + Task UpdateAsync(categorie categorie); Task DeleteAsync(Guid id); } } \ No newline at end of file diff --git a/Webshop.Infrastructure/Data/ApplicationDbContext.cs b/Webshop.Infrastructure/Data/ApplicationDbContext.cs index 44f50fb..a97c6a0 100644 --- a/Webshop.Infrastructure/Data/ApplicationDbContext.cs +++ b/Webshop.Infrastructure/Data/ApplicationDbContext.cs @@ -14,7 +14,7 @@ namespace Webshop.Infrastructure.Data public DbSet Products { get; set; } = default!; public DbSet ProductVariants { get; set; } = default!; - public DbSet categorys { get; set; } = default!; + public DbSet categories { get; set; } = default!; public DbSet Customers { get; set; } = default!; public DbSet
Addresses { get; set; } = default!; public DbSet Orders { get; set; } = default!; @@ -26,9 +26,9 @@ namespace Webshop.Infrastructure.Data public DbSet PaymentMethods { get; set; } = default!; public DbSet Settings { get; set; } = default!; - public DbSet Productcategorys { get; set; } = default!; + public DbSet Productcategories { get; set; } = default!; public DbSet ProductDiscounts { get; set; } = default!; - public DbSet CategoryDiscounts { get; set; } = default!; + public DbSet categorieDiscounts { get; set; } = default!; protected override void OnModelCreating(ModelBuilder modelBuilder) @@ -45,13 +45,13 @@ namespace Webshop.Infrastructure.Data } } - modelBuilder.Entity().HasKey(pc => new { pc.ProductId, pc.CategoryId }); + modelBuilder.Entity().HasKey(pc => new { pc.ProductId, pc.categorieId }); modelBuilder.Entity().HasKey(pd => new { pd.ProductId, pd.DiscountId }); - modelBuilder.Entity().HasKey(cd => new { cd.CategoryId, cd.DiscountId }); + modelBuilder.Entity().HasKey(cd => new { cd.categorieId, cd.DiscountId }); modelBuilder.Entity().HasIndex(p => p.SKU).IsUnique(); modelBuilder.Entity().HasIndex(p => p.Slug).IsUnique(); - modelBuilder.Entity().HasIndex(c => c.Slug).IsUnique(); + modelBuilder.Entity().HasIndex(c => c.Slug).IsUnique(); modelBuilder.Entity().HasIndex(d => d.CouponCode).IsUnique().HasFilter("\"CouponCode\" IS NOT NULL"); modelBuilder.Entity().HasIndex(s => s.Key).IsUnique(); modelBuilder.Entity().HasIndex(o => o.OrderNumber).IsUnique(); @@ -99,10 +99,10 @@ namespace Webshop.Infrastructure.Data modelBuilder.Entity() .Property(pm => pm.ProcessingFee).HasPrecision(18, 2); - modelBuilder.Entity() - .HasOne(c => c.ParentCategory) - .WithMany(c => c.Subcategorys) - .HasForeignKey(c => c.ParentCategoryId) + modelBuilder.Entity() + .HasOne(c => c.Parentcategorie) + .WithMany(c => c.Subcategories) + .HasForeignKey(c => c.ParentcategorieId) .OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity() diff --git a/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.Designer.cs b/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.Designer.cs index 865da9a..bb12e91 100644 --- a/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.Designer.cs +++ b/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.Designer.cs @@ -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("Id") .ValueGeneratedOnAdd() @@ -249,7 +249,7 @@ namespace Webshop.Infrastructure.Migrations .HasMaxLength(255) .HasColumnType("character varying(255)"); - b.Property("ParentCategoryId") + b.Property("ParentcategorieId") .HasColumnType("uuid"); b.Property("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("CategoryId") + b.Property("categorieId") .HasColumnType("uuid"); b.Property("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("ProductId") .HasColumnType("uuid"); - b.Property("CategoryId") + b.Property("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"); diff --git a/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.cs b/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.cs index 58701a2..b6e4a18 100644 --- a/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.cs +++ b/Webshop.Infrastructure/Migrations/20250801114205_FinalSchema.cs @@ -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(type: "uuid", nullable: false), Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), Description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), Slug = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - ParentCategoryId = table.Column(type: "uuid", nullable: true), + ParentcategorieId = table.Column(type: "uuid", nullable: true), ImageUrl = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), IsActive = table.Column(type: "boolean", nullable: false), DisplayOrder = table.Column(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(type: "uuid", nullable: false), + categorieId = table.Column(type: "uuid", nullable: false), DiscountId = table.Column(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(type: "uuid", nullable: false), - CategoryId = table.Column(type: "uuid", nullable: false) + categorieId = table.Column(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"); diff --git a/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs index 09082f2..ebc88e0 100644 --- a/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -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("Id") .ValueGeneratedOnAdd() @@ -246,7 +246,7 @@ namespace Webshop.Infrastructure.Migrations .HasMaxLength(255) .HasColumnType("character varying(255)"); - b.Property("ParentCategoryId") + b.Property("ParentcategorieId") .HasColumnType("uuid"); b.Property("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("CategoryId") + b.Property("categorieId") .HasColumnType("uuid"); b.Property("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("ProductId") .HasColumnType("uuid"); - b.Property("CategoryId") + b.Property("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"); diff --git a/Webshop.Infrastructure/Repositories/CategoryRepository.cs b/Webshop.Infrastructure/Repositories/CategoryRepository.cs index 7fc9b7d..9191aa7 100644 --- a/Webshop.Infrastructure/Repositories/CategoryRepository.cs +++ b/Webshop.Infrastructure/Repositories/CategoryRepository.cs @@ -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> GetAllAsync() + public async Task> GetAllAsync() { - return await _context.categorys.ToListAsync(); + return await _context.categories.ToListAsync(); } - public async Task GetByIdAsync(Guid id) + public async Task GetByIdAsync(Guid id) { - return await _context.categorys.FindAsync(id); + return await _context.categories.FindAsync(id); } - public async Task GetBySlugAsync(string slug) + public async Task 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(); } }