This commit is contained in:
Tizian.Breuch
2025-08-01 15:21:40 +02:00
parent 4dfc50d572
commit 1317844ce5
19 changed files with 66 additions and 147 deletions

View File

@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
using Webshop.Application.Services.Admin;
namespace Webshop.Api.Controllers.Admin

View File

@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
using Webshop.Application.Services.Public;
namespace Webshop.Api.Controllers.Public

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<IcategorieRepository, categorieRepository>();
builder.Services.AddScoped<ICategorieRepository, CategorieRepository>();
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddScoped<IShippingMethodRepository, ShippingMethodRepository>();
builder.Services.AddScoped<IAddressRepository, AddressRepository>();

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.categories;
using Webshop.Application.DTOs.Categorie;
using Webshop.Application.DTOs.Customers;
using Webshop.Application.DTOs.Discounts;
using Webshop.Application.DTOs.Email;
@@ -29,27 +29,7 @@ namespace Webshop.Api.SwaggerFilters
var uniqueId = Guid.NewGuid().ToString().Substring(0, 8);
// --- Authentifizierung & Benutzer (Allgemeine Schemas) ---
if (type == typeof(LoginRequestDto))
{
// Hinweis: Dieses Beispiel wird vom LoginExampleOperationFilter für spezifische Endpunkte überschrieben.
schema.Example = new OpenApiObject
{
["email"] = new OpenApiString("user@example.com"),
["password"] = new OpenApiString("Password123!")
};
}
else if (type == typeof(RegisterRequestDto))
{
schema.Example = new OpenApiObject
{
["email"] = new OpenApiString($"neuer.kunde.{uniqueId}@example.com"),
["password"] = new OpenApiString("NeuesPasswort123!"),
["confirmPassword"] = new OpenApiString("NeuesPasswort123!"),
["firstName"] = new OpenApiString("Erika"),
["lastName"] = new OpenApiString("Musterfrau")
};
}
else if (type == typeof(AuthResponseDto))
if (type == typeof(AuthResponseDto))
{
schema.Example = new OpenApiObject
{
@@ -79,28 +59,7 @@ namespace Webshop.Api.SwaggerFilters
["defaultBillingAddressId"] = new OpenApiNull()
};
}
else if (type == typeof(ResendEmailConfirmationRequestDto))
{
schema.Example = new OpenApiObject { ["email"] = new OpenApiString("unconfirmed.user@example.com") };
}
else if (type == typeof(ChangePasswordRequestDto))
{
schema.Example = new OpenApiObject
{
["oldPassword"] = new OpenApiString("SecureCustomerPass123!"),
["newPassword"] = new OpenApiString("NewSecurePass456!"),
["confirmNewPassword"] = new OpenApiString("NewSecurePass456!")
};
}
else if (type == typeof(ChangeEmailRequestDto))
{
schema.Example = new OpenApiObject
{
["newEmail"] = new OpenApiString($"new.email.{uniqueId}@example.com"),
["currentPassword"] = new OpenApiString("SecureCustomerPass123!")
};
}
// --- Produkte & Lieferanten ---
// --- Produkte & Kategorien (Antworten) ---
else if (type == typeof(ProductDto))
{
schema.Example = new OpenApiObject
@@ -126,87 +85,47 @@ namespace Webshop.Api.SwaggerFilters
}
};
}
else if (type == typeof(AdminProductDto))
{
schema.Example = new OpenApiObject
{
["id"] = new OpenApiString(Guid.Empty.ToString()),
["name"] = new OpenApiString($"Admin Produkt (Beispiel) {uniqueId}"),
["description"] = new OpenApiString("Detaillierte Beschreibung für das Admin-Produkt."),
["sku"] = new OpenApiString($"ADM-PROD-{uniqueId}"),
["price"] = new OpenApiDouble(149.99),
["oldPrice"] = new OpenApiNull(),
["isActive"] = new OpenApiBoolean(true),
["isInStock"] = new OpenApiBoolean(true),
["stockQuantity"] = new OpenApiInteger(50),
["weight"] = new OpenApiDouble(1.2),
["imageUrl"] = new OpenApiString("https://example.com/images/admin_prod.jpg"),
["slug"] = new OpenApiString($"admin-produkt-beispiel-slug-{uniqueId}"),
["createdDate"] = new OpenApiString(DateTimeOffset.UtcNow.ToString("o")),
["lastModifiedDate"] = new OpenApiNull(),
["supplierId"] = new OpenApiNull(),
["purchasePrice"] = new OpenApiDouble(80.00),
["categorieIds"] = new OpenApiArray { new OpenApiString("EXISTING_categorie_ID_HERE") }
};
}
// --- Kategorien ---
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."),
["parentcategorieId"] = new OpenApiNull(),
["imageUrl"] = new OpenApiString("https://example.com/images/new_categorie.jpg"),
["isActive"] = new OpenApiBoolean(true),
["displayOrder"] = new OpenApiInteger(1)
};
}
// --- Adressen ---
else if (type == typeof(AddressDto))
else if (type == typeof(CategorieDto))
{
schema.Example = new OpenApiObject
{
["id"] = new OpenApiString(Guid.NewGuid().ToString()),
["street"] = new OpenApiString("Musterstraße"),
["houseNumber"] = new OpenApiString("123a"),
["city"] = new OpenApiString("Musterstadt"),
["postalCode"] = new OpenApiString("12345"),
["country"] = new OpenApiString("Deutschland"),
["type"] = new OpenApiString(AddressType.Shipping.ToString())
["name"] = new OpenApiString($"Elektronik {uniqueId}"),
["slug"] = new OpenApiString($"elektronik-{uniqueId}"),
["description"] = new OpenApiString("Produkte rund um Elektronik."),
["parentCategorieId"] = new OpenApiNull(),
["imageUrl"] = new OpenApiString("https://example.com/images/categorie_electronics.jpg"),
["isActive"] = new OpenApiBoolean(true),
["displayOrder"] = new OpenApiInteger(1)
};
}
// --- Kunden ---
else if (type == typeof(UpdateCustomerDto))
else if (type == typeof(CustomerDto))
{
schema.Example = new OpenApiObject
{
["id"] = new OpenApiString(Guid.NewGuid().ToString()),
["userId"] = new OpenApiString("EIN_IDENTITY_USER_ID_HIER"),
["firstName"] = new OpenApiString("Max"),
["lastName"] = new OpenApiString("Mustermann"),
["phoneNumber"] = new OpenApiString("+491701234567"),
["currentPassword"] = new OpenApiString("SecureCustomerPass123!"),
["email"] = new OpenApiString($"max.mustermann.{uniqueId}@example.com"),
["phoneNumber"] = new OpenApiString("+491719876543"),
["defaultShippingAddressId"] = new OpenApiNull(),
["defaultBillingAddressId"] = new OpenApiNull()
};
}
// --- Bestellungen ---
else if (type == typeof(CreateOrderDto))
else if (type == typeof(OrderSummaryDto))
{
schema.Example = new OpenApiObject
{
["shippingAddressId"] = new OpenApiString("VALID_ADDRESS_ID_HERE"),
["billingAddressId"] = new OpenApiString("VALID_ADDRESS_ID_HERE"),
["paymentMethodId"] = new OpenApiString("VALID_PAYMENT_METHOD_ID_HERE"),
["shippingMethodId"] = new OpenApiString("VALID_SHIPPING_METHOD_ID_HERE"),
["items"] = new OpenApiArray
{
new OpenApiObject
{
["productId"] = new OpenApiString("VALID_PRODUCT_ID_HERE"),
["quantity"] = new OpenApiInteger(1)
}
}
["id"] = new OpenApiString(Guid.NewGuid().ToString()),
["orderNumber"] = new OpenApiString($"WS-2025-{uniqueId}"),
["orderDate"] = new OpenApiString(DateTimeOffset.UtcNow.ToString("o")),
["status"] = new OpenApiString(OrderStatus.Processing.ToString()),
["totalAmount"] = new OpenApiDouble(123.45),
["paymentStatus"] = new OpenApiString(PaymentStatus.Paid.ToString()),
["customerName"] = new OpenApiString("Max Mustermann")
};
}
}

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs.categories
namespace Webshop.Application.DTOs.Categorie
{
public class CategorieDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs.categories
namespace Webshop.Application.DTOs.Categorie
{
public class CreatecategorieDto
{

View File

@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
namespace Webshop.Application.DTOs.Products

View File

@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
@@ -11,9 +11,9 @@ namespace Webshop.Application.Services.Admin
{
public class AdminCategorieService : IAdminCategorieService
{
private readonly IcategorieRepository _categorieRepository;
private readonly ICategorieRepository _categorieRepository;
public AdminCategorieService(IcategorieRepository categorieRepository)
public AdminCategorieService(ICategorieRepository categorieRepository)
{
_categorieRepository = categorieRepository;
}
@@ -60,7 +60,7 @@ namespace Webshop.Application.Services.Admin
return (null, "Eine Kategorie mit diesem Slug existiert bereits.");
}
var categorie = new categorie
var categorie = new Categorie
{
Id = Guid.NewGuid(),
Name = categorieDto.Name,

View File

@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
namespace Webshop.Application.Services.Admin
{

View File

@@ -2,16 +2,16 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Public
{
public class CategorieService : ICategorieService
{
private readonly IcategorieRepository _categorieRepository;
private readonly ICategorieRepository _categorieRepository;
public CategorieService(IcategorieRepository categorieRepository)
public CategorieService(ICategorieRepository categorieRepository)
{
_categorieRepository = categorieRepository;
}

View File

@@ -1,7 +1,7 @@
// src/Webshop.Application/Services/Public/Icategorieservice.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.categories;
using Webshop.Application.DTOs.Categorie;
namespace Webshop.Application.Services.Public
{

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.categories; // Für categorieDto
using Webshop.Application.DTOs.Categorie; // 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

View File

@@ -9,7 +9,7 @@ namespace Webshop.Domain.Entities
/// <summary>
/// Zum Gruppieren und Organisieren von Produkten.
/// </summary>
public class categorie
public class Categorie
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid(); // Hinzufügen von Default-Wert
@@ -43,9 +43,9 @@ namespace Webshop.Domain.Entities
// << ENDE NEUE EIGENSCHAFTEN >>
// Navigation Properties
public virtual categorie? Parentcategorie { get; set; }
public virtual ICollection<categorie> Subcategories { get; set; } = new List<categorie>();
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>();
public virtual ICollection<CategorieDiscount> categorieDiscounts { get; set; } = new List<CategorieDiscount>();
}
}

View File

@@ -7,7 +7,7 @@ namespace Webshop.Domain.Entities;
/// <summary>
/// Verknüpfungstabelle für die Viele-zu-Viele-Beziehung zwischen categorie und Discount.
/// </summary>
public class categorieDiscount
public class CategorieDiscount
{
[Required]
[ForeignKey(nameof(categorie))]
@@ -18,6 +18,6 @@ public class categorieDiscount
public Guid DiscountId { get; set; }
// Navigation Properties
public virtual categorie categorie { 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<categorieDiscount> categorieDiscounts { get; set; } = new List<categorieDiscount>();
public virtual ICollection<CategorieDiscount> categorieDiscounts { get; set; } = new List<CategorieDiscount>();
}

View File

@@ -20,5 +20,5 @@ public class Productcategorie
// Navigation Properties
public virtual Product Product { get; set; }
public virtual categorie categorie { get; set; }
public virtual Categorie categorie { get; set; }
}

View File

@@ -6,13 +6,13 @@ using Webshop.Domain.Entities;
namespace Webshop.Domain.Interfaces
{
public interface IcategorieRepository
public interface ICategorieRepository
{
Task<IEnumerable<categorie>> GetAllAsync();
Task<categorie?> GetByIdAsync(Guid id);
Task<categorie?> GetBySlugAsync(string slug);
Task AddAsync(categorie categorie);
Task UpdateAsync(categorie categorie);
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<categorie> categories { 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!;
@@ -28,7 +28,7 @@ namespace Webshop.Infrastructure.Data
public DbSet<Productcategorie> Productcategories { get; set; } = default!;
public DbSet<ProductDiscount> ProductDiscounts { get; set; } = default!;
public DbSet<categorieDiscount> categorieDiscounts { get; set; } = default!;
public DbSet<CategorieDiscount> categorieDiscounts { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
@@ -47,11 +47,11 @@ namespace Webshop.Infrastructure.Data
modelBuilder.Entity<Productcategorie>().HasKey(pc => new { pc.ProductId, pc.categorieId });
modelBuilder.Entity<ProductDiscount>().HasKey(pd => new { pd.ProductId, pd.DiscountId });
modelBuilder.Entity<categorieDiscount>().HasKey(cd => new { cd.categorieId, 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<categorie>().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,7 +99,7 @@ namespace Webshop.Infrastructure.Data
modelBuilder.Entity<PaymentMethod>()
.Property(pm => pm.ProcessingFee).HasPrecision(18, 2);
modelBuilder.Entity<categorie>()
modelBuilder.Entity<Categorie>()
.HasOne(c => c.Parentcategorie)
.WithMany(c => c.Subcategories)
.HasForeignKey(c => c.ParentcategorieId)

View File

@@ -9,37 +9,37 @@ using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Repositories
{
public class categorieRepository : IcategorieRepository
public class CategorieRepository : ICategorieRepository
{
private readonly ApplicationDbContext _context;
public categorieRepository(ApplicationDbContext context)
public CategorieRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task<IEnumerable<categorie>> GetAllAsync()
public async Task<IEnumerable<Categorie>> GetAllAsync()
{
return await _context.categories.ToListAsync();
}
public async Task<categorie?> GetByIdAsync(Guid id)
public async Task<Categorie?> GetByIdAsync(Guid id)
{
return await _context.categories.FindAsync(id);
}
public async Task<categorie?> GetBySlugAsync(string slug)
public async Task<Categorie?> GetBySlugAsync(string slug)
{
return await _context.categories.FirstOrDefaultAsync(c => c.Slug == slug);
}
public async Task AddAsync(categorie categorie)
public async Task AddAsync(Categorie categorie)
{
_context.categories.Add(categorie);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(categorie categorie)
public async Task UpdateAsync(Categorie categorie)
{
_context.categories.Update(categorie);
await _context.SaveChangesAsync();