This commit is contained in:
Tizian.Breuch
2025-08-01 10:06:00 +02:00
parent 8a4590ee5a
commit 6f86d0de87
15 changed files with 79 additions and 79 deletions

View File

@@ -1,4 +1,4 @@
// src/Webshop.Api/Controllers/Admin/AdminCategoriesController.cs
// src/Webshop.Api/Controllers/Admin/AdmincategorysController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
@@ -10,7 +10,7 @@ using Webshop.Application.Services.Admin;
namespace Webshop.Api.Controllers.Admin
{
[ApiController]
[Route("api/v1/admin/categories")]
[Route("api/v1/admin/categorys")]
[Authorize(Roles = "Admin")]
public class AdminCategorysController : ControllerBase
{
@@ -22,10 +22,10 @@ namespace Webshop.Api.Controllers.Admin
}
[HttpGet]
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetAllCategories()
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetAllcategorys()
{
var categories = await _adminCategoryService.GetAllAsync();
return Ok(categories);
var categorys = await _adminCategoryService.GetAllAsync();
return Ok(categorys);
}
[HttpGet("{id}")]

View File

@@ -1,4 +1,4 @@
// src/Webshop.Api/Controllers/Public/CategoriesController.cs
// src/Webshop.Api/Controllers/Public/categorysController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
@@ -9,22 +9,22 @@ using Webshop.Application.Services.Public;
namespace Webshop.Api.Controllers.Public
{
[ApiController]
[Route("api/v1/public/categories")]
[Route("api/v1/public/categorys")]
[AllowAnonymous]
public class CategorysController : ControllerBase
public class CategoryController : ControllerBase
{
private readonly ICategoryService _categoryService;
public CategorysController(ICategoryService categoryService)
public CategoryController(ICategoryService categoryService)
{
_categoryService = categoryService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetActiveCategories()
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetActivecategorys()
{
var categories = await _categoryService.GetAllActiveAsync();
return Ok(categories);
var categorys = await _categoryService.GetAllActiveAsync();
return Ok(categorys);
}
[HttpGet("{slug}")]

View File

@@ -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}"),
["categories"] = new OpenApiArray
["categorys"] = new OpenApiArray
{
new OpenApiObject
{

View File

@@ -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> Categories { get; set; } = new List<CategoryDto>();
public List<CategoryDto> categorys { get; set; } = new List<CategoryDto>();
}
}

View File

@@ -20,8 +20,8 @@ namespace Webshop.Application.Services.Admin
public async Task<IEnumerable<CategoryDto>> GetAllAsync()
{
var categories = await _categoryRepository.GetAllAsync();
return categories.Select(c => new CategoryDto
var categorys = await _categoryRepository.GetAllAsync();
return categorys.Select(c => new CategoryDto
{
Id = c.Id,
Name = c.Name,

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.ProductCategories)
.Include(p => p.Productcategorys)
.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.ProductCategories.Select(pc => pc.CategoryId).ToList() // << NEU >>
CategoryIds = p.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU >>
}).ToList();
}
public async Task<AdminProductDto?> GetAdminProductByIdAsync(Guid id)
{
var product = await _context.Products
.Include(p => p.ProductCategories) // << NEU: Lade die Join-Tabelle mit >>
.Include(p => p.Productcategorys) // << 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.ProductCategories.Select(pc => pc.CategoryId).ToList() // << NEU: Mappe die CategoryIds >>
CategoryIds = product.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU: Mappe die CategoryIds >>
};
}
@@ -101,13 +101,13 @@ namespace Webshop.Application.Services.Admin
CreatedDate = DateTimeOffset.UtcNow,
SupplierId = productDto.SupplierId,
PurchasePrice = productDto.PurchasePrice,
ProductCategories = new List<ProductCategory>() // Initialisiere die Collection
Productcategorys = new List<ProductCategory>() // Initialisiere die Collection
};
// << NEU: F<>ge die Kategorien hinzu >>
foreach (var categoryId in productDto.CategoryIds)
{
newProduct.ProductCategories.Add(new ProductCategory { CategoryId = categoryId });
newProduct.Productcategorys.Add(new ProductCategory { CategoryId = categoryId });
}
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.ProductCategories) // Lade die aktuellen Zuweisungen
.Include(p => p.Productcategorys) // 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.ProductCategories.Clear();
existingProduct.Productcategorys.Clear();
foreach (var categoryId in productDto.CategoryIds)
{
existingProduct.ProductCategories.Add(new ProductCategory { ProductId = existingProduct.Id, CategoryId = categoryId });
existingProduct.Productcategorys.Add(new ProductCategory { ProductId = existingProduct.Id, CategoryId = categoryId });
}
// << ENDE NEUER TEIL >>

View File

@@ -18,10 +18,10 @@ namespace Webshop.Application.Services.Public
public async Task<IEnumerable<CategoryDto>> GetAllActiveAsync()
{
var categories = await _categoryRepository.GetAllAsync();
var categorys = await _categoryRepository.GetAllAsync();
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
return categories
return categorys
.Where(c => c.IsActive)
.Select(c => new CategoryDto
{

View File

@@ -26,7 +26,7 @@ namespace Webshop.Application.Services.Public
{
// Wir verwenden den DbContext, um Produkte und ihre Kategorien zu laden
var products = await _context.Products
.Include(p => p.ProductCategories) // Lade die Join-Tabelle
.Include(p => p.Productcategorys) // Lade die Join-Tabelle
.ThenInclude(pc => pc.Category) // Lade die zugehörige Kategorie-Entität
.Where(p => p.IsActive) // Nur aktive Produkte
.ToListAsync();
@@ -41,7 +41,7 @@ namespace Webshop.Application.Services.Public
ImageUrl = p.ImageUrl,
IsInStock = p.IsInStock,
Slug = p.Slug,
Categories = p.ProductCategories.Select(pc => new CategoryDto
categorys = p.Productcategorys.Select(pc => new CategoryDto
{
Id = pc.Category.Id,
Name = pc.Category.Name,
@@ -54,7 +54,7 @@ namespace Webshop.Application.Services.Public
public async Task<ProductDto?> GetProductBySlugAsync(string slug)
{
var product = await _context.Products
.Include(p => p.ProductCategories)
.Include(p => p.Productcategorys)
.ThenInclude(pc => pc.Category)
.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); // Nur aktives Produkt finden
@@ -73,7 +73,7 @@ namespace Webshop.Application.Services.Public
ImageUrl = product.ImageUrl,
IsInStock = product.IsInStock,
Slug = product.Slug,
Categories = product.ProductCategories.Select(pc => new CategoryDto
categorys = product.Productcategorys.Select(pc => new CategoryDto
{
Id = pc.Category.Id,
Name = pc.Category.Name,

View File

@@ -44,8 +44,8 @@ namespace Webshop.Domain.Entities
// Navigation Properties
public virtual Category? ParentCategory { get; set; }
public virtual ICollection<Category> SubCategories { get; set; } = new List<Category>();
public virtual ICollection<ProductCategory> ProductCategories { get; set; } = new List<ProductCategory>();
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>();
}
}

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> ProductCategories { get; set; } = new List<ProductCategory>();
public virtual ICollection<ProductCategory> Productcategorys { get; set; } = new List<ProductCategory>();
}

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> Categories { get; set; } = default!;
public DbSet<Category> categorys { 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,7 +26,7 @@ namespace Webshop.Infrastructure.Data
public DbSet<PaymentMethod> PaymentMethods { get; set; } = default!;
public DbSet<Setting> Settings { get; set; } = default!;
public DbSet<ProductCategory> ProductCategories { get; set; } = default!;
public DbSet<ProductCategory> Productcategorys { get; set; } = default!;
public DbSet<ProductDiscount> ProductDiscounts { get; set; } = default!;
public DbSet<CategoryDiscount> CategoryDiscounts { get; set; } = default!;
@@ -101,7 +101,7 @@ namespace Webshop.Infrastructure.Data
modelBuilder.Entity<Category>()
.HasOne(c => c.ParentCategory)
.WithMany(c => c.SubCategories)
.WithMany(c => c.Subcategorys)
.HasForeignKey(c => c.ParentCategoryId)
.OnDelete(DeleteBehavior.Restrict);

View File

@@ -264,7 +264,7 @@ namespace Webshop.Infrastructure.Migrations
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Categories");
b.ToTable("categorys");
});
modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b =>
@@ -667,7 +667,7 @@ namespace Webshop.Infrastructure.Migrations
b.HasIndex("CategoryId");
b.ToTable("ProductCategories");
b.ToTable("Productcategorys");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b =>
@@ -1009,7 +1009,7 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "ParentCategory")
.WithMany("SubCategories")
.WithMany("Subcategorys")
.HasForeignKey("ParentCategoryId")
.OnDelete(DeleteBehavior.Restrict);
@@ -1120,13 +1120,13 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "Category")
.WithMany("ProductCategories")
.WithMany("Productcategorys")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Webshop.Domain.Entities.Product", "Product")
.WithMany("ProductCategories")
.WithMany("Productcategorys")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1196,9 +1196,9 @@ namespace Webshop.Infrastructure.Migrations
{
b.Navigation("CategoryDiscounts");
b.Navigation("ProductCategories");
b.Navigation("Productcategorys");
b.Navigation("SubCategories");
b.Navigation("Subcategorys");
});
modelBuilder.Entity("Webshop.Domain.Entities.Customer", b =>
@@ -1224,7 +1224,7 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Product", b =>
{
b.Navigation("ProductCategories");
b.Navigation("Productcategorys");
b.Navigation("ProductDiscounts");

View File

@@ -13,7 +13,7 @@ namespace Webshop.Infrastructure.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Categories",
name: "categorys",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
@@ -29,11 +29,11 @@ namespace Webshop.Infrastructure.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Categories", x => x.Id);
table.PrimaryKey("PK_categorys", x => x.Id);
table.ForeignKey(
name: "FK_Categories_Categories_ParentCategoryId",
name: "FK_categorys_categorys_ParentCategoryId",
column: x => x.ParentCategoryId,
principalTable: "Categories",
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
@@ -164,9 +164,9 @@ namespace Webshop.Infrastructure.Migrations
{
table.PrimaryKey("PK_CategoryDiscounts", x => new { x.CategoryId, x.DiscountId });
table.ForeignKey(
name: "FK_CategoryDiscounts_Categories_CategoryId",
name: "FK_CategoryDiscounts_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "Categories",
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
@@ -450,7 +450,7 @@ namespace Webshop.Infrastructure.Migrations
});
migrationBuilder.CreateTable(
name: "ProductCategories",
name: "Productcategorys",
columns: table => new
{
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
@@ -458,15 +458,15 @@ namespace Webshop.Infrastructure.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_ProductCategories", x => new { x.ProductId, x.CategoryId });
table.PrimaryKey("PK_Productcategorys", x => new { x.ProductId, x.CategoryId });
table.ForeignKey(
name: "FK_ProductCategories_Categories_CategoryId",
name: "FK_Productcategorys_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "Categories",
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProductCategories_Products_ProductId",
name: "FK_Productcategorys_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
@@ -594,13 +594,13 @@ namespace Webshop.Infrastructure.Migrations
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_Categories_ParentCategoryId",
table: "Categories",
name: "IX_categorys_ParentCategoryId",
table: "categorys",
column: "ParentCategoryId");
migrationBuilder.CreateIndex(
name: "IX_Categories_Slug",
table: "Categories",
name: "IX_categorys_Slug",
table: "categorys",
column: "Slug",
unique: true);
@@ -669,8 +669,8 @@ namespace Webshop.Infrastructure.Migrations
column: "ShippingMethodId");
migrationBuilder.CreateIndex(
name: "IX_ProductCategories_CategoryId",
table: "ProductCategories",
name: "IX_Productcategorys_CategoryId",
table: "Productcategorys",
column: "CategoryId");
migrationBuilder.CreateIndex(
@@ -769,7 +769,7 @@ namespace Webshop.Infrastructure.Migrations
name: "OrderItems");
migrationBuilder.DropTable(
name: "ProductCategories");
name: "Productcategorys");
migrationBuilder.DropTable(
name: "ProductDiscounts");
@@ -802,7 +802,7 @@ namespace Webshop.Infrastructure.Migrations
name: "ProductVariants");
migrationBuilder.DropTable(
name: "Categories");
name: "categorys");
migrationBuilder.DropTable(
name: "Discounts");

View File

@@ -261,7 +261,7 @@ namespace Webshop.Infrastructure.Migrations
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Categories");
b.ToTable("categorys");
});
modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b =>
@@ -664,7 +664,7 @@ namespace Webshop.Infrastructure.Migrations
b.HasIndex("CategoryId");
b.ToTable("ProductCategories");
b.ToTable("Productcategorys");
});
modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b =>
@@ -1006,7 +1006,7 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Category", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "ParentCategory")
.WithMany("SubCategories")
.WithMany("Subcategorys")
.HasForeignKey("ParentCategoryId")
.OnDelete(DeleteBehavior.Restrict);
@@ -1117,13 +1117,13 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b =>
{
b.HasOne("Webshop.Domain.Entities.Category", "Category")
.WithMany("ProductCategories")
.WithMany("Productcategorys")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Webshop.Domain.Entities.Product", "Product")
.WithMany("ProductCategories")
.WithMany("Productcategorys")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1193,9 +1193,9 @@ namespace Webshop.Infrastructure.Migrations
{
b.Navigation("CategoryDiscounts");
b.Navigation("ProductCategories");
b.Navigation("Productcategorys");
b.Navigation("SubCategories");
b.Navigation("Subcategorys");
});
modelBuilder.Entity("Webshop.Domain.Entities.Customer", b =>
@@ -1221,7 +1221,7 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Product", b =>
{
b.Navigation("ProductCategories");
b.Navigation("Productcategorys");
b.Navigation("ProductDiscounts");

View File

@@ -20,37 +20,37 @@ namespace Webshop.Infrastructure.Repositories
public async Task<IEnumerable<Category>> GetAllAsync()
{
return await _context.Categories.ToListAsync();
return await _context.categorys.ToListAsync();
}
public async Task<Category?> GetByIdAsync(Guid id)
{
return await _context.Categories.FindAsync(id);
return await _context.categorys.FindAsync(id);
}
public async Task<Category?> GetBySlugAsync(string slug)
{
return await _context.Categories.FirstOrDefaultAsync(c => c.Slug == slug);
return await _context.categorys.FirstOrDefaultAsync(c => c.Slug == slug);
}
public async Task AddAsync(Category category)
{
_context.Categories.Add(category);
_context.categorys.Add(category);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(Category category)
{
_context.Categories.Update(category);
_context.categorys.Update(category);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(Guid id)
{
var category = await _context.Categories.FindAsync(id);
var category = await _context.categorys.FindAsync(id);
if (category != null)
{
_context.Categories.Remove(category);
_context.categorys.Remove(category);
await _context.SaveChangesAsync();
}
}