From 9e298a045831f07307b78b8c673d09d747dc8607 Mon Sep 17 00:00:00 2001 From: "Tizian.Breuch" Date: Fri, 25 Jul 2025 15:46:31 +0200 Subject: [PATCH] =?UTF-8?q?aufr=C3=BCumen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/AdminProductsController.cs | 4 +- .../Admin/AdminSuppliersController.cs | 4 +- .../Controllers/Admin/AdminUsersController.cs | 2 +- .../Controllers/Customer/ProfileController.cs | 18 - .../CheckoutController.cs | 2 +- .../OrdersController.cs | 2 +- .../Customers/ProfileController.cs | 51 + .../ReviewsController.cs | 2 +- .../Controllers/Public/ProductsController.cs | 2 +- Webshop.Api/Program.cs | 6 +- .../SwaggerFilters/AddExampleSchemaFilter.cs | 11 +- Webshop.Api/Webshop.Api.csproj | 45 +- .../DTOs/Auth/RegisterRequestDto.cs | 19 +- .../DTOs/{ => Categorys}/CategoryDto.cs | 2 +- .../DTOs/{ => Categorys}/CreateCategoryDto.cs | 2 +- .../DTOs/{ => Customers}/AddressDto.cs | 2 +- .../DTOs/{ => Customers}/CustomerDto.cs | 2 +- .../Customers/UpdateCustomerProfileDto.cs | 18 + .../DTOs/{ => Discounts}/DiscountDto.cs | 2 +- .../DTOs/{ => Orders}/CreateOrderDto.cs | 2 +- .../DTOs/{ => Orders}/CreateOrderItemDto.cs | 2 +- .../DTOs/{ => Orders}/OrderDetailDto.cs | 2 +- .../DTOs/{ => Orders}/OrderItemDto.cs | 2 +- .../DTOs/{ => Orders}/OrderSummaryDto.cs | 2 +- .../DTOs/{ => Payments}/PaymentMethodDto.cs | 2 +- .../DTOs/{ => Products}/AdminProductDto.cs | 2 +- .../DTOs/{ => Products}/ProductDto.cs | 2 +- .../DTOs/{ => Products}/ProductVariantDto.cs | 2 +- .../DTOs/{ => Reviews}/CreateReviewDto.cs | 2 +- .../DTOs/{ => Reviews}/ReviewDto.cs | 2 +- .../DTOs/{ => Settings}/SettingDto.cs | 0 .../DTOs/{ => Shipping}/ShippingMethodDto.cs | 2 +- .../DTOs/{ => Suppliers}/SupplierDto.cs | 2 +- Webshop.Application/DTOs/Users/UserDto.cs | 14 +- .../Services/Admin/AdminCategoryService.cs | 1 + .../Services/Admin/AdminDiscountService.cs | 1 + .../Services/Admin/AdminOrderService.cs | 1 + .../Services/Admin/AdminProductService.cs | 5 +- .../Services/Admin/AdminSettingService.cs | 1 + .../Services/Admin/AdminSupplierService.cs | 3 +- .../Services/Admin/AdminUserService.cs | 93 +- .../Services/Admin/IAdminUserService.cs | 15 - .../{ => Interfaces}/IAdminCategoryService.cs | 4 +- .../{ => Interfaces}/IAdminDiscountService.cs | 4 +- .../{ => Interfaces}/IAdminOrderService.cs | 4 +- .../{ => Interfaces}/IAdminProductService.cs | 4 +- .../{ => Interfaces}/IAdminSettingService.cs | 4 +- .../{ => Interfaces}/IAdminSupplierService.cs | 4 +- .../Admin/Interfaces/IAdminUserService.cs | 32 + .../Services/Auth/AuthService.cs | 39 +- .../Services/Auth/IAuthService.cs | 18 +- .../Services/Customer/CustomerService.cs | 17 - .../Services/Customer/ICustomerService.cs | 16 - .../CheckoutService.cs | 3 +- .../Services/Customers/CustomerService.cs | 52 + .../Interfaces}/ICheckoutService.cs | 4 +- .../Customers/Interfaces/ICustomerService.cs | 11 + .../Interfaces}/IOrderService.cs | 4 +- .../Interfaces}/IReviewService.cs | 4 +- .../{Customer => Customers}/OrderService.cs | 3 +- .../{Customer => Customers}/ReviewService.cs | 3 +- .../Services/Public/CategoryService.cs | 1 + .../{ => Interfaces}/ICategoryService.cs | 4 +- .../{ => Interfaces}/IProductService.cs | 4 +- .../Services/Public/ProductService.cs | 3 +- .../Webshop.Application.csproj | 39 +- Webshop.Domain/Entities/ApplicationUser.cs | 15 +- Webshop.Domain/Entities/Customer.cs | 65 +- .../Interfaces/ICustomerRepository.cs | 8 +- Webshop.Domain/Webshop.Domain.csproj | 2 +- .../20250725095503_InitalCreate.Designer.cs | 1223 ----------------- .../Migrations/20250725095503_InitalCreate.cs | 819 ----------- .../ApplicationDbContextModelSnapshot.cs | 1220 ---------------- .../Repositories/CustomerRepository.cs | 21 +- 74 files changed, 453 insertions(+), 3557 deletions(-) delete mode 100644 Webshop.Api/Controllers/Customer/ProfileController.cs rename Webshop.Api/Controllers/{Customer => Customers}/CheckoutController.cs (89%) rename Webshop.Api/Controllers/{Customer => Customers}/OrdersController.cs (92%) create mode 100644 Webshop.Api/Controllers/Customers/ProfileController.cs rename Webshop.Api/Controllers/{Customer => Customers}/ReviewsController.cs (89%) rename Webshop.Application/DTOs/{ => Categorys}/CategoryDto.cs (92%) rename Webshop.Application/DTOs/{ => Categorys}/CreateCategoryDto.cs (92%) rename Webshop.Application/DTOs/{ => Customers}/AddressDto.cs (92%) rename Webshop.Application/DTOs/{ => Customers}/CustomerDto.cs (93%) create mode 100644 Webshop.Application/DTOs/Customers/UpdateCustomerProfileDto.cs rename Webshop.Application/DTOs/{ => Discounts}/DiscountDto.cs (93%) rename Webshop.Application/DTOs/{ => Orders}/CreateOrderDto.cs (93%) rename Webshop.Application/DTOs/{ => Orders}/CreateOrderItemDto.cs (88%) rename Webshop.Application/DTOs/{ => Orders}/OrderDetailDto.cs (95%) rename Webshop.Application/DTOs/{ => Orders}/OrderItemDto.cs (93%) rename Webshop.Application/DTOs/{ => Orders}/OrderSummaryDto.cs (93%) rename Webshop.Application/DTOs/{ => Payments}/PaymentMethodDto.cs (91%) rename Webshop.Application/DTOs/{ => Products}/AdminProductDto.cs (95%) rename Webshop.Application/DTOs/{ => Products}/ProductDto.cs (93%) rename Webshop.Application/DTOs/{ => Products}/ProductVariantDto.cs (93%) rename Webshop.Application/DTOs/{ => Reviews}/CreateReviewDto.cs (89%) rename Webshop.Application/DTOs/{ => Reviews}/ReviewDto.cs (92%) rename Webshop.Application/DTOs/{ => Settings}/SettingDto.cs (100%) rename Webshop.Application/DTOs/{ => Shipping}/ShippingMethodDto.cs (91%) rename Webshop.Application/DTOs/{ => Suppliers}/SupplierDto.cs (91%) delete mode 100644 Webshop.Application/Services/Admin/IAdminUserService.cs rename Webshop.Application/Services/Admin/{ => Interfaces}/IAdminCategoryService.cs (72%) rename Webshop.Application/Services/Admin/{ => Interfaces}/IAdminDiscountService.cs (72%) rename Webshop.Application/Services/Admin/{ => Interfaces}/IAdminOrderService.cs (72%) rename Webshop.Application/Services/Admin/{ => Interfaces}/IAdminProductService.cs (84%) rename Webshop.Application/Services/Admin/{ => Interfaces}/IAdminSettingService.cs (72%) rename Webshop.Application/Services/Admin/{ => Interfaces}/IAdminSupplierService.cs (86%) create mode 100644 Webshop.Application/Services/Admin/Interfaces/IAdminUserService.cs delete mode 100644 Webshop.Application/Services/Customer/CustomerService.cs delete mode 100644 Webshop.Application/Services/Customer/ICustomerService.cs rename Webshop.Application/Services/{Customer => Customers}/CheckoutService.cs (79%) create mode 100644 Webshop.Application/Services/Customers/CustomerService.cs rename Webshop.Application/Services/{Customer => Customers/Interfaces}/ICheckoutService.cs (71%) create mode 100644 Webshop.Application/Services/Customers/Interfaces/ICustomerService.cs rename Webshop.Application/Services/{Customer => Customers/Interfaces}/IOrderService.cs (71%) rename Webshop.Application/Services/{Customer => Customers/Interfaces}/IReviewService.cs (71%) rename Webshop.Application/Services/{Customer => Customers}/OrderService.cs (78%) rename Webshop.Application/Services/{Customer => Customers}/ReviewService.cs (79%) rename Webshop.Application/Services/Public/{ => Interfaces}/ICategoryService.cs (72%) rename Webshop.Application/Services/Public/{ => Interfaces}/IProductService.cs (83%) delete mode 100644 Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.Designer.cs delete mode 100644 Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.cs delete mode 100644 Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs diff --git a/Webshop.Api/Controllers/Admin/AdminProductsController.cs b/Webshop.Api/Controllers/Admin/AdminProductsController.cs index e847af7..dc1ae23 100644 --- a/Webshop.Api/Controllers/Admin/AdminProductsController.cs +++ b/Webshop.Api/Controllers/Admin/AdminProductsController.cs @@ -1,12 +1,12 @@ // Auto-generiert von CreateWebshopFiles.ps1 using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; -using Webshop.Application.DTOs; -using Webshop.Application.Services.Admin; using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.DTOs.Products; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Api.Controllers.Admin { diff --git a/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs b/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs index c4225fb..c949d7a 100644 --- a/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs +++ b/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs @@ -1,11 +1,11 @@ // src/Webshop.Api/Controllers/Admin/AdminSuppliersController.cs using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Webshop.Application.DTOs; -using Webshop.Application.Services.Admin; // Wichtig für IAdminSupplierService using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.DTOs.Suppliers; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Api.Controllers.Admin { diff --git a/Webshop.Api/Controllers/Admin/AdminUsersController.cs b/Webshop.Api/Controllers/Admin/AdminUsersController.cs index 73b3385..1b80ba8 100644 --- a/Webshop.Api/Controllers/Admin/AdminUsersController.cs +++ b/Webshop.Api/Controllers/Admin/AdminUsersController.cs @@ -2,11 +2,11 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using Webshop.Application.DTOs.Users; -using Webshop.Application.Services.Admin; using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Api.Controllers.Admin { diff --git a/Webshop.Api/Controllers/Customer/ProfileController.cs b/Webshop.Api/Controllers/Customer/ProfileController.cs deleted file mode 100644 index f37bf38..0000000 --- a/Webshop.Api/Controllers/Customer/ProfileController.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Auto-generiert von CreateWebshopFiles.ps1 -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Webshop.Api.Controllers.Customer -{ - [ApiController] - [Route("api/v1/customer/[controller]")] - [Authorize(Roles = "Customer")] - public class ProfileController : ControllerBase - { - - } -} diff --git a/Webshop.Api/Controllers/Customer/CheckoutController.cs b/Webshop.Api/Controllers/Customers/CheckoutController.cs similarity index 89% rename from Webshop.Api/Controllers/Customer/CheckoutController.cs rename to Webshop.Api/Controllers/Customers/CheckoutController.cs index 80fa208..30756e5 100644 --- a/Webshop.Api/Controllers/Customer/CheckoutController.cs +++ b/Webshop.Api/Controllers/Customers/CheckoutController.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Api.Controllers.Customer +namespace Webshop.Api.Controllers.Customers { [ApiController] [Route("api/v1/customer/[controller]")] diff --git a/Webshop.Api/Controllers/Customer/OrdersController.cs b/Webshop.Api/Controllers/Customers/OrdersController.cs similarity index 92% rename from Webshop.Api/Controllers/Customer/OrdersController.cs rename to Webshop.Api/Controllers/Customers/OrdersController.cs index 346e435..26a0cf3 100644 --- a/Webshop.Api/Controllers/Customer/OrdersController.cs +++ b/Webshop.Api/Controllers/Customers/OrdersController.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Api.Controllers.Customer +namespace Webshop.Api.Controllers.Customers { [ApiController] [Route("api/v1/customer/[controller]")] diff --git a/Webshop.Api/Controllers/Customers/ProfileController.cs b/Webshop.Api/Controllers/Customers/ProfileController.cs new file mode 100644 index 0000000..1dfea20 --- /dev/null +++ b/Webshop.Api/Controllers/Customers/ProfileController.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Security.Claims; +using System.Threading.Tasks; +using Webshop.Application.DTOs.Customers; +using Webshop.Application.Services.Customers.Interfaces; + +namespace Webshop.Api.Controllers.Customers +{ + [ApiController] + [Route("api/v1/customer/profile")] // Eindeutige Route für das Profil + [Authorize(Roles = "Customer")] // Nur für eingeloggte Kunden! + public class ProfileController : ControllerBase + { + private readonly ICustomerService _customerService; + + public ProfileController(ICustomerService customerService) + { + _customerService = customerService; + } + + // Hilfsmethode, um die ID des eingeloggten Benutzers aus dem Token zu holen + private string GetUserId() => User.FindFirstValue(ClaimTypes.NameIdentifier)!; + + [HttpGet("me")] // GET /api/v1/customer/profile/me + public async Task> GetMyProfile() + { + var userId = GetUserId(); + var profile = await _customerService.GetMyProfileAsync(userId); + + if (profile == null) + { + return NotFound("Kundenprofil nicht gefunden."); + } + return Ok(profile); + } + + [HttpPut("me")] // PUT /api/v1/customer/profile/me + public async Task UpdateMyProfile([FromBody] UpdateCustomerProfileDto profileDto) + { + var userId = GetUserId(); + var success = await _customerService.UpdateMyProfileAsync(userId, profileDto); + + if (!success) + { + return NotFound("Kundenprofil nicht gefunden."); + } + return NoContent(); // Standardantwort für ein erfolgreiches Update + } + } +} \ No newline at end of file diff --git a/Webshop.Api/Controllers/Customer/ReviewsController.cs b/Webshop.Api/Controllers/Customers/ReviewsController.cs similarity index 89% rename from Webshop.Api/Controllers/Customer/ReviewsController.cs rename to Webshop.Api/Controllers/Customers/ReviewsController.cs index 36be3d0..3cf0149 100644 --- a/Webshop.Api/Controllers/Customer/ReviewsController.cs +++ b/Webshop.Api/Controllers/Customers/ReviewsController.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Api.Controllers.Customer +namespace Webshop.Api.Controllers.Customers { [ApiController] [Route("api/v1/customer/[controller]")] diff --git a/Webshop.Api/Controllers/Public/ProductsController.cs b/Webshop.Api/Controllers/Public/ProductsController.cs index eabe6e1..855af42 100644 --- a/Webshop.Api/Controllers/Public/ProductsController.cs +++ b/Webshop.Api/Controllers/Public/ProductsController.cs @@ -1,12 +1,12 @@ // Auto-generiert von CreateWebshopFiles.ps1 using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; -using Webshop.Application.DTOs; using Webshop.Application.Services.Public; using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.DTOs.Products; namespace Webshop.Api.Controllers.Public { diff --git a/Webshop.Api/Program.cs b/Webshop.Api/Program.cs index aa1bb88..4289275 100644 --- a/Webshop.Api/Program.cs +++ b/Webshop.Api/Program.cs @@ -14,6 +14,10 @@ using Microsoft.Extensions.Logging; // For ILogger using Microsoft.OpenApi.Models; // For Swagger OpenAPI models using Webshop.Api.SwaggerFilters; // For AuthorizeOperationFilter using Webshop.Domain.Entities; +using Webshop.Application.Services.Admin.Interfaces; +using Webshop.Application.Services.Public.Interfaces; +using Webshop.Application.Services.Customers.Interfaces; +using Webshop.Application.Services.Customers; var builder = WebApplication.CreateBuilder(args); @@ -85,7 +89,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); // CUSTOMER Services (später Implementierungen hinzufügen) -// builder.Services.AddScoped(); +builder.Services.AddScoped(); // 5. Controller und Swagger/OpenAPI hinzufügen diff --git a/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs b/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs index 2214bd5..97d095e 100644 --- a/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs +++ b/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs @@ -5,7 +5,16 @@ using Microsoft.OpenApi.Any; using Webshop.Application.DTOs; using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -using System; // Für Guid.NewGuid() +using System; +using Webshop.Application.DTOs.Customers; +using Webshop.Application.DTOs.Shipping; +using Webshop.Application.DTOs.Suppliers; +using Webshop.Application.DTOs.Reviews; +using Webshop.Application.DTOs.Products; +using Webshop.Application.DTOs.Payments; +using Webshop.Application.DTOs.Orders; +using Webshop.Application.DTOs.Discounts; +using Webshop.Application.DTOs.Categorys; // Für Guid.NewGuid() namespace Webshop.Api.SwaggerFilters { diff --git a/Webshop.Api/Webshop.Api.csproj b/Webshop.Api/Webshop.Api.csproj index 60843ce..702967d 100644 --- a/Webshop.Api/Webshop.Api.csproj +++ b/Webshop.Api/Webshop.Api.csproj @@ -1,26 +1,29 @@  - - net8.0 - enable - enable - 461c56b2-b056-42a9-8ce5-ccc441ef8a37 - Linux - + + net8.0 + enable + enable + 461c56b2-b056-42a9-8ce5-ccc441ef8a37 + Linux + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + - - - - + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + \ No newline at end of file diff --git a/Webshop.Application/DTOs/Auth/RegisterRequestDto.cs b/Webshop.Application/DTOs/Auth/RegisterRequestDto.cs index 15ecf78..eddac5f 100644 --- a/Webshop.Application/DTOs/Auth/RegisterRequestDto.cs +++ b/Webshop.Application/DTOs/Auth/RegisterRequestDto.cs @@ -9,19 +9,10 @@ namespace Webshop.Application.DTOs.Auth { public class RegisterRequestDto { - [Required(ErrorMessage = "E-Mail ist erforderlich.")] - [EmailAddress(ErrorMessage = "Ungültiges E-Mail-Format.")] - public string Email { get; set; } = string.Empty; - - [Required(ErrorMessage = "Passwort ist erforderlich.")] - [MinLength(6, ErrorMessage = "Passwort muss mindestens 6 Zeichen lang sein.")] - public string Password { get; set; } = string.Empty; - - [Required(ErrorMessage = "Passwortbestätigung ist erforderlich.")] - [Compare("Password", ErrorMessage = "Passwörter stimmen nicht überein.")] - public string ConfirmPassword { get; set; } = string.Empty; - - public string? FirstName { get; set; } - public string? LastName { get; set; } + [Required][EmailAddress] public string Email { get; set; } = string.Empty; + [Required][MinLength(6)] public string Password { get; set; } = string.Empty; + [Required][Compare("Password")] public string ConfirmPassword { get; set; } = string.Empty; + [Required] public string FirstName { get; set; } = string.Empty; + [Required] public string LastName { get; set; } = string.Empty; } } diff --git a/Webshop.Application/DTOs/CategoryDto.cs b/Webshop.Application/DTOs/Categorys/CategoryDto.cs similarity index 92% rename from Webshop.Application/DTOs/CategoryDto.cs rename to Webshop.Application/DTOs/Categorys/CategoryDto.cs index 08c49e6..73c635b 100644 --- a/Webshop.Application/DTOs/CategoryDto.cs +++ b/Webshop.Application/DTOs/Categorys/CategoryDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Categorys { public class CategoryDto { diff --git a/Webshop.Application/DTOs/CreateCategoryDto.cs b/Webshop.Application/DTOs/Categorys/CreateCategoryDto.cs similarity index 92% rename from Webshop.Application/DTOs/CreateCategoryDto.cs rename to Webshop.Application/DTOs/Categorys/CreateCategoryDto.cs index a5ac9fe..e3d2f74 100644 --- a/Webshop.Application/DTOs/CreateCategoryDto.cs +++ b/Webshop.Application/DTOs/Categorys/CreateCategoryDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Categorys { public class CreateCategoryDto { diff --git a/Webshop.Application/DTOs/AddressDto.cs b/Webshop.Application/DTOs/Customers/AddressDto.cs similarity index 92% rename from Webshop.Application/DTOs/AddressDto.cs rename to Webshop.Application/DTOs/Customers/AddressDto.cs index 5c9a03a..449c334 100644 --- a/Webshop.Application/DTOs/AddressDto.cs +++ b/Webshop.Application/DTOs/Customers/AddressDto.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Customers { public class AddressDto { diff --git a/Webshop.Application/DTOs/CustomerDto.cs b/Webshop.Application/DTOs/Customers/CustomerDto.cs similarity index 93% rename from Webshop.Application/DTOs/CustomerDto.cs rename to Webshop.Application/DTOs/Customers/CustomerDto.cs index 65b72db..7b3f0a6 100644 --- a/Webshop.Application/DTOs/CustomerDto.cs +++ b/Webshop.Application/DTOs/Customers/CustomerDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Customers { public class CustomerDto { diff --git a/Webshop.Application/DTOs/Customers/UpdateCustomerProfileDto.cs b/Webshop.Application/DTOs/Customers/UpdateCustomerProfileDto.cs new file mode 100644 index 0000000..db76a3f --- /dev/null +++ b/Webshop.Application/DTOs/Customers/UpdateCustomerProfileDto.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace Webshop.Application.DTOs.Customers +{ + public class UpdateCustomerProfileDto + { + [Required] + [MaxLength(100)] + public string FirstName { get; set; } = string.Empty; + + [Required] + [MaxLength(100)] + public string LastName { get; set; } = string.Empty; + + // PhoneNumber könnte auch hier sein, falls der User das ändern darf + // public string? PhoneNumber { get; set; } + } +} \ No newline at end of file diff --git a/Webshop.Application/DTOs/DiscountDto.cs b/Webshop.Application/DTOs/Discounts/DiscountDto.cs similarity index 93% rename from Webshop.Application/DTOs/DiscountDto.cs rename to Webshop.Application/DTOs/Discounts/DiscountDto.cs index 83867c7..934cb39 100644 --- a/Webshop.Application/DTOs/DiscountDto.cs +++ b/Webshop.Application/DTOs/Discounts/DiscountDto.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Discounts { public class DiscountDto { diff --git a/Webshop.Application/DTOs/CreateOrderDto.cs b/Webshop.Application/DTOs/Orders/CreateOrderDto.cs similarity index 93% rename from Webshop.Application/DTOs/CreateOrderDto.cs rename to Webshop.Application/DTOs/Orders/CreateOrderDto.cs index e048f97..f1e75b6 100644 --- a/Webshop.Application/DTOs/CreateOrderDto.cs +++ b/Webshop.Application/DTOs/Orders/CreateOrderDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Orders { public class CreateOrderDto { diff --git a/Webshop.Application/DTOs/CreateOrderItemDto.cs b/Webshop.Application/DTOs/Orders/CreateOrderItemDto.cs similarity index 88% rename from Webshop.Application/DTOs/CreateOrderItemDto.cs rename to Webshop.Application/DTOs/Orders/CreateOrderItemDto.cs index 447e109..d49e99a 100644 --- a/Webshop.Application/DTOs/CreateOrderItemDto.cs +++ b/Webshop.Application/DTOs/Orders/CreateOrderItemDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Orders { public class CreateOrderItemDto { diff --git a/Webshop.Application/DTOs/OrderDetailDto.cs b/Webshop.Application/DTOs/Orders/OrderDetailDto.cs similarity index 95% rename from Webshop.Application/DTOs/OrderDetailDto.cs rename to Webshop.Application/DTOs/Orders/OrderDetailDto.cs index bce361b..bf7f15e 100644 --- a/Webshop.Application/DTOs/OrderDetailDto.cs +++ b/Webshop.Application/DTOs/Orders/OrderDetailDto.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Orders { public class OrderDetailDto { diff --git a/Webshop.Application/DTOs/OrderItemDto.cs b/Webshop.Application/DTOs/Orders/OrderItemDto.cs similarity index 93% rename from Webshop.Application/DTOs/OrderItemDto.cs rename to Webshop.Application/DTOs/Orders/OrderItemDto.cs index 7db8b58..a83bf57 100644 --- a/Webshop.Application/DTOs/OrderItemDto.cs +++ b/Webshop.Application/DTOs/Orders/OrderItemDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Orders { public class OrderItemDto { diff --git a/Webshop.Application/DTOs/OrderSummaryDto.cs b/Webshop.Application/DTOs/Orders/OrderSummaryDto.cs similarity index 93% rename from Webshop.Application/DTOs/OrderSummaryDto.cs rename to Webshop.Application/DTOs/Orders/OrderSummaryDto.cs index 9df0d5a..7985caa 100644 --- a/Webshop.Application/DTOs/OrderSummaryDto.cs +++ b/Webshop.Application/DTOs/Orders/OrderSummaryDto.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Orders { public class OrderSummaryDto { diff --git a/Webshop.Application/DTOs/PaymentMethodDto.cs b/Webshop.Application/DTOs/Payments/PaymentMethodDto.cs similarity index 91% rename from Webshop.Application/DTOs/PaymentMethodDto.cs rename to Webshop.Application/DTOs/Payments/PaymentMethodDto.cs index b82c879..d029639 100644 --- a/Webshop.Application/DTOs/PaymentMethodDto.cs +++ b/Webshop.Application/DTOs/Payments/PaymentMethodDto.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Payments { public class PaymentMethodDto { diff --git a/Webshop.Application/DTOs/AdminProductDto.cs b/Webshop.Application/DTOs/Products/AdminProductDto.cs similarity index 95% rename from Webshop.Application/DTOs/AdminProductDto.cs rename to Webshop.Application/DTOs/Products/AdminProductDto.cs index 01aaf27..7d4e8d5 100644 --- a/Webshop.Application/DTOs/AdminProductDto.cs +++ b/Webshop.Application/DTOs/Products/AdminProductDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Products { public class AdminProductDto { diff --git a/Webshop.Application/DTOs/ProductDto.cs b/Webshop.Application/DTOs/Products/ProductDto.cs similarity index 93% rename from Webshop.Application/DTOs/ProductDto.cs rename to Webshop.Application/DTOs/Products/ProductDto.cs index 08b2e2b..123837c 100644 --- a/Webshop.Application/DTOs/ProductDto.cs +++ b/Webshop.Application/DTOs/Products/ProductDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Products { public class ProductDto { diff --git a/Webshop.Application/DTOs/ProductVariantDto.cs b/Webshop.Application/DTOs/Products/ProductVariantDto.cs similarity index 93% rename from Webshop.Application/DTOs/ProductVariantDto.cs rename to Webshop.Application/DTOs/Products/ProductVariantDto.cs index b73f79f..5d95eeb 100644 --- a/Webshop.Application/DTOs/ProductVariantDto.cs +++ b/Webshop.Application/DTOs/Products/ProductVariantDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Products { public class ProductVariantDto { diff --git a/Webshop.Application/DTOs/CreateReviewDto.cs b/Webshop.Application/DTOs/Reviews/CreateReviewDto.cs similarity index 89% rename from Webshop.Application/DTOs/CreateReviewDto.cs rename to Webshop.Application/DTOs/Reviews/CreateReviewDto.cs index b4081fd..d5a31ba 100644 --- a/Webshop.Application/DTOs/CreateReviewDto.cs +++ b/Webshop.Application/DTOs/Reviews/CreateReviewDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Reviews { public class CreateReviewDto { diff --git a/Webshop.Application/DTOs/ReviewDto.cs b/Webshop.Application/DTOs/Reviews/ReviewDto.cs similarity index 92% rename from Webshop.Application/DTOs/ReviewDto.cs rename to Webshop.Application/DTOs/Reviews/ReviewDto.cs index ad36b04..3a56542 100644 --- a/Webshop.Application/DTOs/ReviewDto.cs +++ b/Webshop.Application/DTOs/Reviews/ReviewDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Reviews { public class ReviewDto { diff --git a/Webshop.Application/DTOs/SettingDto.cs b/Webshop.Application/DTOs/Settings/SettingDto.cs similarity index 100% rename from Webshop.Application/DTOs/SettingDto.cs rename to Webshop.Application/DTOs/Settings/SettingDto.cs diff --git a/Webshop.Application/DTOs/ShippingMethodDto.cs b/Webshop.Application/DTOs/Shipping/ShippingMethodDto.cs similarity index 91% rename from Webshop.Application/DTOs/ShippingMethodDto.cs rename to Webshop.Application/DTOs/Shipping/ShippingMethodDto.cs index 1d6f3a9..822a93a 100644 --- a/Webshop.Application/DTOs/ShippingMethodDto.cs +++ b/Webshop.Application/DTOs/Shipping/ShippingMethodDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Shipping { public class ShippingMethodDto { diff --git a/Webshop.Application/DTOs/SupplierDto.cs b/Webshop.Application/DTOs/Suppliers/SupplierDto.cs similarity index 91% rename from Webshop.Application/DTOs/SupplierDto.cs rename to Webshop.Application/DTOs/Suppliers/SupplierDto.cs index ccc4c9e..4aad1a8 100644 --- a/Webshop.Application/DTOs/SupplierDto.cs +++ b/Webshop.Application/DTOs/Suppliers/SupplierDto.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Webshop.Application.DTOs +namespace Webshop.Application.DTOs.Suppliers { public class SupplierDto { diff --git a/Webshop.Application/DTOs/Users/UserDto.cs b/Webshop.Application/DTOs/Users/UserDto.cs index cd031f5..5d36b33 100644 --- a/Webshop.Application/DTOs/Users/UserDto.cs +++ b/Webshop.Application/DTOs/Users/UserDto.cs @@ -1,9 +1,4 @@ -// Auto-generiert von CreateWebshopFiles.ps1 -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - - +// src/Webshop.Application/DTOs/Users/UserDto.cs namespace Webshop.Application.DTOs.Users { public class UserDto @@ -14,5 +9,10 @@ namespace Webshop.Application.DTOs.Users public List Roles { get; set; } = new List(); public DateTimeOffset CreatedDate { get; set; } public bool EmailConfirmed { get; set; } + + // Hinzugefügte Felder + public DateTimeOffset? LastActive { get; set; } + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; } -} +} \ No newline at end of file diff --git a/Webshop.Application/Services/Admin/AdminCategoryService.cs b/Webshop.Application/Services/Admin/AdminCategoryService.cs index df964eb..6615d23 100644 --- a/Webshop.Application/Services/Admin/AdminCategoryService.cs +++ b/Webshop.Application/Services/Admin/AdminCategoryService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Application.Services.Admin diff --git a/Webshop.Application/Services/Admin/AdminDiscountService.cs b/Webshop.Application/Services/Admin/AdminDiscountService.cs index f74f951..bb1b78d 100644 --- a/Webshop.Application/Services/Admin/AdminDiscountService.cs +++ b/Webshop.Application/Services/Admin/AdminDiscountService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Application.Services.Admin diff --git a/Webshop.Application/Services/Admin/AdminOrderService.cs b/Webshop.Application/Services/Admin/AdminOrderService.cs index c31b721..b047775 100644 --- a/Webshop.Application/Services/Admin/AdminOrderService.cs +++ b/Webshop.Application/Services/Admin/AdminOrderService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Application.Services.Admin diff --git a/Webshop.Application/Services/Admin/AdminProductService.cs b/Webshop.Application/Services/Admin/AdminProductService.cs index 234fd3a..6eb944c 100644 --- a/Webshop.Application/Services/Admin/AdminProductService.cs +++ b/Webshop.Application/Services/Admin/AdminProductService.cs @@ -1,11 +1,12 @@ // src/Webshop.Application/Services/Admin/AdminProductService.cs -using Webshop.Application.DTOs; // AdminProductDto using Webshop.Domain.Entities; using Webshop.Domain.Interfaces; using System.Collections.Generic; using System.Threading.Tasks; using System; // Für Guid -using System.Linq; // Für Select +using System.Linq; +using Webshop.Application.DTOs.Products; +using Webshop.Application.Services.Admin.Interfaces; // Für Select namespace Webshop.Application.Services.Admin { diff --git a/Webshop.Application/Services/Admin/AdminSettingService.cs b/Webshop.Application/Services/Admin/AdminSettingService.cs index a84bbcd..053c8b8 100644 --- a/Webshop.Application/Services/Admin/AdminSettingService.cs +++ b/Webshop.Application/Services/Admin/AdminSettingService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Application.Services.Admin diff --git a/Webshop.Application/Services/Admin/AdminSupplierService.cs b/Webshop.Application/Services/Admin/AdminSupplierService.cs index 532cb85..00090fd 100644 --- a/Webshop.Application/Services/Admin/AdminSupplierService.cs +++ b/Webshop.Application/Services/Admin/AdminSupplierService.cs @@ -1,11 +1,12 @@ // src/Webshop.Application/Services/Admin/AdminSupplierService.cs -using Webshop.Application.DTOs; using Webshop.Domain.Entities; using Webshop.Domain.Interfaces; // Wichtig für ISupplierRepository using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Webshop.Application.DTOs.Suppliers; +using Webshop.Application.Services.Admin.Interfaces; namespace Webshop.Application.Services.Admin { diff --git a/Webshop.Application/Services/Admin/AdminUserService.cs b/Webshop.Application/Services/Admin/AdminUserService.cs index 8161440..6d94bd9 100644 --- a/Webshop.Application/Services/Admin/AdminUserService.cs +++ b/Webshop.Application/Services/Admin/AdminUserService.cs @@ -5,27 +5,34 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Webshop.Application.DTOs.Users; -using Webshop.Domain.Entities; // Wichtiges using für ApplicationUser +using Webshop.Application.Services.Admin.Interfaces; +using Webshop.Domain.Entities; +using Webshop.Infrastructure.Data; // WICHTIG: Stellt sicher, dass ApplicationDbContext gefunden wird. namespace Webshop.Application.Services.Admin { + // --- SCHRITT 1: Die fehlende Klassendeklaration --- public class AdminUserService : IAdminUserService { - // Wir verwenden nun den UserManager mit unserer neuen ApplicationUser-Klasse + // --- SCHRITT 2: Die fehlenden Feld-Deklarationen --- private readonly UserManager _userManager; + private readonly ApplicationDbContext _context; - public AdminUserService(UserManager userManager) + // --- SCHRITT 3: Der Konstruktor, der die Felder zuweist --- + public AdminUserService(UserManager userManager, ApplicationDbContext context) { _userManager = userManager; + _context = context; } + // --- AB HIER: Alle Ihre Methoden, unverändert --- public async Task> GetAllUsersAsync() { - // Alle Benutzer aus der Datenbank laden - var users = await _userManager.Users.ToListAsync(); - var userDtos = new List(); + var users = await _userManager.Users + .Include(u => u.Customer) + .ToListAsync(); - // Für jeden Benutzer ein DTO erstellen und die Daten mappen + var userDtos = new List(); foreach (var user in users) { userDtos.Add(new UserDto @@ -33,24 +40,28 @@ namespace Webshop.Application.Services.Admin Id = user.Id, Email = user.Email ?? string.Empty, UserName = user.UserName ?? string.Empty, - CreatedDate = user.CreatedDate, // Dieses Feld ist jetzt verfügbar! + CreatedDate = user.CreatedDate, EmailConfirmed = user.EmailConfirmed, - Roles = (await _userManager.GetRolesAsync(user)).ToList() // Rollen des Benutzers abrufen + Roles = (await _userManager.GetRolesAsync(user)).ToList(), + LastActive = user.LastActive, + FirstName = user.Customer?.FirstName ?? string.Empty, + LastName = user.Customer?.LastName ?? string.Empty }); } - return userDtos; } public async Task GetUserByIdAsync(string userId) { - var user = await _userManager.FindByIdAsync(userId); + var user = await _userManager.Users + .Include(u => u.Customer) + .FirstOrDefaultAsync(u => u.Id == userId); + if (user == null) { return null; } - // Den gefundenen Benutzer in ein DTO umwandeln return new UserDto { Id = user.Id, @@ -58,8 +69,60 @@ namespace Webshop.Application.Services.Admin UserName = user.UserName ?? string.Empty, CreatedDate = user.CreatedDate, EmailConfirmed = user.EmailConfirmed, - Roles = (await _userManager.GetRolesAsync(user)).ToList() + Roles = (await _userManager.GetRolesAsync(user)).ToList(), + LastActive = user.LastActive, + FirstName = user.Customer?.FirstName ?? string.Empty, + LastName = user.Customer?.LastName ?? string.Empty }; } - } -} \ No newline at end of file + + public async Task UpdateUserRolesAsync(string userId, List newRoles) + { + var user = await _userManager.FindByIdAsync(userId); + if (user == null) + { + return false; + } + + var existingRoles = await _userManager.GetRolesAsync(user); + var removeResult = await _userManager.RemoveFromRolesAsync(user, existingRoles); + if (!removeResult.Succeeded) + { + return false; + } + + var addResult = await _userManager.AddToRolesAsync(user, newRoles); + return addResult.Succeeded; + } + + public async Task DeleteUserAsync(string userId) + { + var user = await _userManager.FindByIdAsync(userId); + if (user == null) + { + return false; + } + + // Kaskadierendes Löschen der abhängigen Daten + var customer = await _context.Customers + .Include(c => c.Orders) + .Include(c => c.Reviews) + .Include(c => c.Addresses) + .FirstOrDefaultAsync(c => c.AspNetUserId == userId); + + if (customer != null) + { + _context.Reviews.RemoveRange(customer.Reviews); + _context.Orders.RemoveRange(customer.Orders); + _context.Addresses.RemoveRange(customer.Addresses); + _context.Customers.Remove(customer); + await _context.SaveChangesAsync(); + } + + // Zum Schluss den Identity-Benutzer löschen + var result = await _userManager.DeleteAsync(user); + return result.Succeeded; + } + + } // <-- Schließende Klammer für die Klasse +} // <-- Schließende Klammer für den Namespace \ No newline at end of file diff --git a/Webshop.Application/Services/Admin/IAdminUserService.cs b/Webshop.Application/Services/Admin/IAdminUserService.cs deleted file mode 100644 index a81d1d0..0000000 --- a/Webshop.Application/Services/Admin/IAdminUserService.cs +++ /dev/null @@ -1,15 +0,0 @@ -// src/Webshop.Application/Services/Admin/IAdminUserService.cs -using System.Collections.Generic; -using System.Threading.Tasks; -using Webshop.Application.DTOs.Users; // UserDto - -namespace Webshop.Application.Services.Admin -{ - public interface IAdminUserService - { - Task> GetAllUsersAsync(); - Task GetUserByIdAsync(string userId); - // Task UpdateUserRolesAsync(string userId, List newRoles); // Beispiel für zukünftige Methode - // Task DeleteUserAsync(string userId); // Beispiel für zukünftige Methode - } -} \ No newline at end of file diff --git a/Webshop.Application/Services/Admin/IAdminCategoryService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminCategoryService.cs similarity index 72% rename from Webshop.Application/Services/Admin/IAdminCategoryService.cs rename to Webshop.Application/Services/Admin/Interfaces/IAdminCategoryService.cs index 51deaaf..4025c9d 100644 --- a/Webshop.Application/Services/Admin/IAdminCategoryService.cs +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminCategoryService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Admin +namespace Webshop.Application.Services.Admin.Interfaces { public interface IAdminCategoryService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Admin/IAdminDiscountService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminDiscountService.cs similarity index 72% rename from Webshop.Application/Services/Admin/IAdminDiscountService.cs rename to Webshop.Application/Services/Admin/Interfaces/IAdminDiscountService.cs index f581e01..ba0aa1a 100644 --- a/Webshop.Application/Services/Admin/IAdminDiscountService.cs +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminDiscountService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Admin +namespace Webshop.Application.Services.Admin.Interfaces { public interface IAdminDiscountService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Admin/IAdminOrderService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminOrderService.cs similarity index 72% rename from Webshop.Application/Services/Admin/IAdminOrderService.cs rename to Webshop.Application/Services/Admin/Interfaces/IAdminOrderService.cs index 26256c6..03f3a4c 100644 --- a/Webshop.Application/Services/Admin/IAdminOrderService.cs +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminOrderService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Admin +namespace Webshop.Application.Services.Admin.Interfaces { public interface IAdminOrderService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Admin/IAdminProductService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminProductService.cs similarity index 84% rename from Webshop.Application/Services/Admin/IAdminProductService.cs rename to Webshop.Application/Services/Admin/Interfaces/IAdminProductService.cs index fbe3817..e5a9124 100644 --- a/Webshop.Application/Services/Admin/IAdminProductService.cs +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminProductService.cs @@ -1,9 +1,9 @@ // src/Webshop.Application/Services/Admin/IAdminProductService.cs using System.Collections.Generic; using System.Threading.Tasks; -using Webshop.Application.DTOs; // AdminProductDto +using Webshop.Application.DTOs.Products; -namespace Webshop.Application.Services.Admin +namespace Webshop.Application.Services.Admin.Interfaces { public interface IAdminProductService { diff --git a/Webshop.Application/Services/Admin/IAdminSettingService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminSettingService.cs similarity index 72% rename from Webshop.Application/Services/Admin/IAdminSettingService.cs rename to Webshop.Application/Services/Admin/Interfaces/IAdminSettingService.cs index 92da1b5..50b9f34 100644 --- a/Webshop.Application/Services/Admin/IAdminSettingService.cs +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminSettingService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Admin +namespace Webshop.Application.Services.Admin.Interfaces { public interface IAdminSettingService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Admin/IAdminSupplierService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminSupplierService.cs similarity index 86% rename from Webshop.Application/Services/Admin/IAdminSupplierService.cs rename to Webshop.Application/Services/Admin/Interfaces/IAdminSupplierService.cs index 5429fd3..bf6d643 100644 --- a/Webshop.Application/Services/Admin/IAdminSupplierService.cs +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminSupplierService.cs @@ -3,9 +3,9 @@ using System; // Für Guid using System.Collections.Generic; using System.Threading.Tasks; -using Webshop.Application.DTOs; // Für SupplierDto +using Webshop.Application.DTOs.Suppliers; -namespace Webshop.Application.Services.Admin +namespace Webshop.Application.Services.Admin.Interfaces { public interface IAdminSupplierService { diff --git a/Webshop.Application/Services/Admin/Interfaces/IAdminUserService.cs b/Webshop.Application/Services/Admin/Interfaces/IAdminUserService.cs new file mode 100644 index 0000000..5525aec --- /dev/null +++ b/Webshop.Application/Services/Admin/Interfaces/IAdminUserService.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Webshop.Application.DTOs.Users; + +namespace Webshop.Application.Services.Admin.Interfaces +{ + /// + /// Definiert den Vertrag für den Dienst zur Verwaltung von Benutzern durch einen Admin. + /// + public interface IAdminUserService + { + /// + /// Ruft eine Liste aller Benutzer mit ihren zugehörigen Daten ab. + /// + Task> GetAllUsersAsync(); + + /// + /// Ruft einen einzelnen Benutzer anhand seiner ID ab. + /// + Task GetUserByIdAsync(string userId); + + /// + /// Aktualisiert die Rollen eines bestimmten Benutzers. + /// + Task UpdateUserRolesAsync(string userId, List newRoles); + + /// + /// Löscht einen Benutzer und alle seine abhängigen Daten (Kundenprofil, Bestellungen etc.). + /// + Task DeleteUserAsync(string userId); + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Auth/AuthService.cs b/Webshop.Application/Services/Auth/AuthService.cs index 0b02838..e5bcc5f 100644 --- a/Webshop.Application/Services/Auth/AuthService.cs +++ b/Webshop.Application/Services/Auth/AuthService.cs @@ -1,36 +1,36 @@ -// src/Webshop.Application/Services/Auth/AuthService.cs -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Webshop.Application.DTOs.Auth; -using System.Threading.Tasks; -using System.Collections.Generic; -using Webshop.Domain.Entities; // <-- WICHTIG: Das Using für Ihre neue Klasse hinzufügen +using Webshop.Domain.Entities; +using Webshop.Infrastructure.Data; + namespace Webshop.Application.Services.Auth { public class AuthService : IAuthService { - // Ändern Sie hier IdentityUser zu ApplicationUser private readonly UserManager _userManager; private readonly SignInManager _signInManager; private readonly IConfiguration _configuration; private readonly RoleManager _roleManager; + private readonly ApplicationDbContext _context; public AuthService( - // Ändern Sie auch hier die Typen im Konstruktor UserManager userManager, SignInManager signInManager, IConfiguration configuration, - RoleManager roleManager) + RoleManager roleManager, + ApplicationDbContext context) { _userManager = userManager; _signInManager = signInManager; _configuration = configuration; _roleManager = roleManager; + _context = context; } public async Task RegisterUserAsync(RegisterRequestDto request) @@ -41,12 +41,11 @@ namespace Webshop.Application.Services.Auth return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = "E-Mail ist bereits registriert." }; } - // Erstellen Sie hier eine Instanz Ihrer neuen ApplicationUser-Klasse var user = new ApplicationUser { Email = request.Email, UserName = request.Email, - CreatedDate = DateTimeOffset.UtcNow // Setzen Sie das neue Feld! + CreatedDate = DateTimeOffset.UtcNow }; var result = await _userManager.CreateAsync(user, request.Password); @@ -56,7 +55,17 @@ namespace Webshop.Application.Services.Auth return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = errors }; } - // Der Rest der Logik bleibt gleich, da die Rollenverwaltung nicht vom User-Typ abhängt + // Zugehöriges kaufmännisches Kundenprofil erstellen + var customer = new Customer + { + AspNetUserId = user.Id, + FirstName = request.FirstName, + LastName = request.LastName + }; + _context.Customers.Add(customer); + await _context.SaveChangesAsync(); + + // Dem Benutzer die "Customer"-Rolle zuweisen if (!await _roleManager.RoleExistsAsync("Customer")) { await _roleManager.CreateAsync(new IdentityRole("Customer")); @@ -78,7 +87,6 @@ namespace Webshop.Application.Services.Auth public async Task LoginUserAsync(LoginRequestDto request) { - // Diese Methode funktioniert ohne Änderungen, da der _userManager jetzt vom richtigen Typ ist. var user = await _userManager.FindByEmailAsync(request.Email); if (user == null) { @@ -91,6 +99,10 @@ namespace Webshop.Application.Services.Auth return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = "Ungültige Anmeldeinformationen." }; } + // Zeitstempel für "Zuletzt aktiv" aktualisieren + user.LastActive = DateTimeOffset.UtcNow; + await _userManager.UpdateAsync(user); + var roles = await _userManager.GetRolesAsync(user); var token = await GenerateJwtToken(user, roles); @@ -106,7 +118,6 @@ namespace Webshop.Application.Services.Auth public async Task LoginAdminAsync(LoginRequestDto request) { - // Diese Methode profitiert direkt von der Korrektur in LoginUserAsync. var authResponse = await LoginUserAsync(request); if (!authResponse.IsAuthSuccessful) { @@ -114,7 +125,6 @@ namespace Webshop.Application.Services.Auth } var user = await _userManager.FindByEmailAsync(request.Email); - // Stellt sicher, dass der User gefunden wurde und die Rolle "Admin" hat. if (user == null || !await _userManager.IsInRoleAsync(user, "Admin")) { return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = "Keine Berechtigung." }; @@ -123,7 +133,6 @@ namespace Webshop.Application.Services.Auth return authResponse; } - // Ändern Sie hier den Parameter-Typ zu ApplicationUser private async Task GenerateJwtToken(ApplicationUser user, IList roles) { var claims = new List diff --git a/Webshop.Application/Services/Auth/IAuthService.cs b/Webshop.Application/Services/Auth/IAuthService.cs index c0c4ec6..9276cff 100644 --- a/Webshop.Application/Services/Auth/IAuthService.cs +++ b/Webshop.Application/Services/Auth/IAuthService.cs @@ -1,14 +1,26 @@ -// src/Webshop.Application/Services/Auth/IAuthService.cs +using System.Threading.Tasks; using Webshop.Application.DTOs.Auth; -using System.Threading.Tasks; // Sicherstellen, dass für Task vorhanden -using System.Collections.Generic; // Sicherstellen, dass für IList vorhanden namespace Webshop.Application.Services.Auth { + /// + /// Definiert den Vertrag für den Authentifizierungsdienst. + /// public interface IAuthService { + /// + /// Registriert einen neuen Benutzer und erstellt ein zugehöriges Kundenprofil. + /// Task RegisterUserAsync(RegisterRequestDto request); + + /// + /// Meldet einen Benutzer an und gibt einen JWT zurück. + /// Task LoginUserAsync(LoginRequestDto request); + + /// + /// Meldet einen Benutzer an und überprüft, ob er die Admin-Rolle hat. + /// Task LoginAdminAsync(LoginRequestDto request); } } \ No newline at end of file diff --git a/Webshop.Application/Services/Customer/CustomerService.cs b/Webshop.Application/Services/Customer/CustomerService.cs deleted file mode 100644 index 314b69e..0000000 --- a/Webshop.Application/Services/Customer/CustomerService.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Auto-generiert von CreateWebshopFiles.ps1 -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - - -namespace Webshop.Application.Services.Customer -{ - public class CustomerService : ICustomerService - { - // Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories) - - // public CustomerService(IYourRepository repository) { } - - // Fügen Sie hier Service-Methoden hinzu - } -} diff --git a/Webshop.Application/Services/Customer/ICustomerService.cs b/Webshop.Application/Services/Customer/ICustomerService.cs deleted file mode 100644 index 2eaf461..0000000 --- a/Webshop.Application/Services/Customer/ICustomerService.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Auto-generiert von CreateWebshopFiles.ps1 -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Webshop.Application.DTOs; -using Webshop.Application.DTOs.Auth; -using Webshop.Application.DTOs.Users; - - -namespace Webshop.Application.Services.Customer -{ - public interface ICustomerService - { -// Fügen Sie hier Methodensignaturen hinzu - } -} diff --git a/Webshop.Application/Services/Customer/CheckoutService.cs b/Webshop.Application/Services/Customers/CheckoutService.cs similarity index 79% rename from Webshop.Application/Services/Customer/CheckoutService.cs rename to Webshop.Application/Services/Customers/CheckoutService.cs index 9eeb88f..e61f9e7 100644 --- a/Webshop.Application/Services/Customer/CheckoutService.cs +++ b/Webshop.Application/Services/Customers/CheckoutService.cs @@ -2,9 +2,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Customers.Interfaces; -namespace Webshop.Application.Services.Customer +namespace Webshop.Application.Services.Customers { public class CheckoutService : ICheckoutService { diff --git a/Webshop.Application/Services/Customers/CustomerService.cs b/Webshop.Application/Services/Customers/CustomerService.cs new file mode 100644 index 0000000..56645c7 --- /dev/null +++ b/Webshop.Application/Services/Customers/CustomerService.cs @@ -0,0 +1,52 @@ +using System.Threading.Tasks; +using Webshop.Application.DTOs.Customers; +using Webshop.Application.Services.Customers.Interfaces; +using Webshop.Domain.Interfaces; // Wichtig für ICustomerRepository + +namespace Webshop.Application.Services.Customers +{ + public class CustomerService : ICustomerService + { + private readonly ICustomerRepository _customerRepository; + + public CustomerService(ICustomerRepository customerRepository) + { + _customerRepository = customerRepository; + } + + public async Task GetMyProfileAsync(string userId) + { + var customer = await _customerRepository.GetByUserIdAsync(userId); + if (customer == null) + { + return null; + } + + // Mappe die Entity auf das CustomerDto + return new CustomerDto + { + Id = customer.Id, + UserId = customer.AspNetUserId, + FirstName = customer.FirstName, + LastName = customer.LastName, + // Fügen Sie hier weitere Felder hinzu, die der Kunde sehen soll (Email, Phone etc.) + }; + } + + public async Task UpdateMyProfileAsync(string userId, UpdateCustomerProfileDto profileDto) + { + var customer = await _customerRepository.GetByUserIdAsync(userId); + if (customer == null) + { + return false; // Kunde nicht gefunden + } + + // Aktualisiere die Felder + customer.FirstName = profileDto.FirstName; + customer.LastName = profileDto.LastName; + + await _customerRepository.UpdateAsync(customer); + return true; + } + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Customer/ICheckoutService.cs b/Webshop.Application/Services/Customers/Interfaces/ICheckoutService.cs similarity index 71% rename from Webshop.Application/Services/Customer/ICheckoutService.cs rename to Webshop.Application/Services/Customers/Interfaces/ICheckoutService.cs index e1dc023..32ce9ba 100644 --- a/Webshop.Application/Services/Customer/ICheckoutService.cs +++ b/Webshop.Application/Services/Customers/Interfaces/ICheckoutService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Customer +namespace Webshop.Application.Services.Customers.Interfaces { public interface ICheckoutService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Customers/Interfaces/ICustomerService.cs b/Webshop.Application/Services/Customers/Interfaces/ICustomerService.cs new file mode 100644 index 0000000..9020bd9 --- /dev/null +++ b/Webshop.Application/Services/Customers/Interfaces/ICustomerService.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Webshop.Application.DTOs.Customers; // Korrektes Using für DTOs + +namespace Webshop.Application.Services.Customers.Interfaces +{ + public interface ICustomerService + { + Task GetMyProfileAsync(string userId); + Task UpdateMyProfileAsync(string userId, UpdateCustomerProfileDto profileDto); + } +} \ No newline at end of file diff --git a/Webshop.Application/Services/Customer/IOrderService.cs b/Webshop.Application/Services/Customers/Interfaces/IOrderService.cs similarity index 71% rename from Webshop.Application/Services/Customer/IOrderService.cs rename to Webshop.Application/Services/Customers/Interfaces/IOrderService.cs index df4b29e..acd51bd 100644 --- a/Webshop.Application/Services/Customer/IOrderService.cs +++ b/Webshop.Application/Services/Customers/Interfaces/IOrderService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Customer +namespace Webshop.Application.Services.Customers.Interfaces { public interface IOrderService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Customer/IReviewService.cs b/Webshop.Application/Services/Customers/Interfaces/IReviewService.cs similarity index 71% rename from Webshop.Application/Services/Customer/IReviewService.cs rename to Webshop.Application/Services/Customers/Interfaces/IReviewService.cs index 314803e..5b37b34 100644 --- a/Webshop.Application/Services/Customer/IReviewService.cs +++ b/Webshop.Application/Services/Customers/Interfaces/IReviewService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Customer +namespace Webshop.Application.Services.Customers.Interfaces { public interface IReviewService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Customer/OrderService.cs b/Webshop.Application/Services/Customers/OrderService.cs similarity index 78% rename from Webshop.Application/Services/Customer/OrderService.cs rename to Webshop.Application/Services/Customers/OrderService.cs index c9d06b3..e6dc28c 100644 --- a/Webshop.Application/Services/Customer/OrderService.cs +++ b/Webshop.Application/Services/Customers/OrderService.cs @@ -2,9 +2,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Customers.Interfaces; -namespace Webshop.Application.Services.Customer +namespace Webshop.Application.Services.Customers { public class OrderService : IOrderService { diff --git a/Webshop.Application/Services/Customer/ReviewService.cs b/Webshop.Application/Services/Customers/ReviewService.cs similarity index 79% rename from Webshop.Application/Services/Customer/ReviewService.cs rename to Webshop.Application/Services/Customers/ReviewService.cs index 5c3ab1d..7f12bae 100644 --- a/Webshop.Application/Services/Customer/ReviewService.cs +++ b/Webshop.Application/Services/Customers/ReviewService.cs @@ -2,9 +2,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Customers.Interfaces; -namespace Webshop.Application.Services.Customer +namespace Webshop.Application.Services.Customers { public class ReviewService : IReviewService { diff --git a/Webshop.Application/Services/Public/CategoryService.cs b/Webshop.Application/Services/Public/CategoryService.cs index b672196..df8d106 100644 --- a/Webshop.Application/Services/Public/CategoryService.cs +++ b/Webshop.Application/Services/Public/CategoryService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.Services.Public.Interfaces; namespace Webshop.Application.Services.Public diff --git a/Webshop.Application/Services/Public/ICategoryService.cs b/Webshop.Application/Services/Public/Interfaces/ICategoryService.cs similarity index 72% rename from Webshop.Application/Services/Public/ICategoryService.cs rename to Webshop.Application/Services/Public/Interfaces/ICategoryService.cs index 52ab8a9..185e0a2 100644 --- a/Webshop.Application/Services/Public/ICategoryService.cs +++ b/Webshop.Application/Services/Public/Interfaces/ICategoryService.cs @@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth; using Webshop.Application.DTOs.Users; -namespace Webshop.Application.Services.Public +namespace Webshop.Application.Services.Public.Interfaces { public interface ICategoryService { -// Fügen Sie hier Methodensignaturen hinzu + // Fügen Sie hier Methodensignaturen hinzu } } diff --git a/Webshop.Application/Services/Public/IProductService.cs b/Webshop.Application/Services/Public/Interfaces/IProductService.cs similarity index 83% rename from Webshop.Application/Services/Public/IProductService.cs rename to Webshop.Application/Services/Public/Interfaces/IProductService.cs index 59d0c4a..ae04b7b 100644 --- a/Webshop.Application/Services/Public/IProductService.cs +++ b/Webshop.Application/Services/Public/Interfaces/IProductService.cs @@ -1,9 +1,9 @@ // src/Webshop.Application/Services/Public/IProductService.cs using System.Collections.Generic; using System.Threading.Tasks; -using Webshop.Application.DTOs; // ProductDto +using Webshop.Application.DTOs.Products; -namespace Webshop.Application.Services.Public +namespace Webshop.Application.Services.Public.Interfaces { public interface IProductService { diff --git a/Webshop.Application/Services/Public/ProductService.cs b/Webshop.Application/Services/Public/ProductService.cs index 67d13c5..2c9182a 100644 --- a/Webshop.Application/Services/Public/ProductService.cs +++ b/Webshop.Application/Services/Public/ProductService.cs @@ -2,9 +2,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Webshop.Application.DTOs; using Webshop.Domain.Interfaces; using Webshop.Domain.Entities; +using Webshop.Application.DTOs.Products; +using Webshop.Application.Services.Public.Interfaces; namespace Webshop.Application.Services.Public diff --git a/Webshop.Application/Webshop.Application.csproj b/Webshop.Application/Webshop.Application.csproj index 46fc073..6a8d599 100644 --- a/Webshop.Application/Webshop.Application.csproj +++ b/Webshop.Application/Webshop.Application.csproj @@ -1,32 +1,25 @@  + + net8.0 + enable + enable + - - net8.0 - enable - enable - - - - - - - - - + + + + + + + - - - - - - - - - - + + + + \ No newline at end of file diff --git a/Webshop.Domain/Entities/ApplicationUser.cs b/Webshop.Domain/Entities/ApplicationUser.cs index 711d688..84f59b5 100644 --- a/Webshop.Domain/Entities/ApplicationUser.cs +++ b/Webshop.Domain/Entities/ApplicationUser.cs @@ -1,22 +1,13 @@ using Microsoft.AspNetCore.Identity; using System; +using System.Collections.Generic; namespace Webshop.Domain.Entities { - /// - /// Erweitert die Standard-Identity-Klasse, um anwendungsspezifische - /// Eigenschaften für einen Benutzer zu speichern. - /// public class ApplicationUser : IdentityUser { - // Hinzugefügtes Feld, das in der Standard-IdentityUser-Klasse fehlt. - // Wird benötigt, um die Anforderung Ihrer UserDto zu erfüllen. public DateTimeOffset CreatedDate { get; set; } - - // BEISPIELE FÜR WEITERE NÜTZLICHE FELDER (können bei Bedarf einkommentiert werden): - // public string? FirstName { get; set; } - // public string? LastName { get; set; } - // public byte[]? ProfilePicture { get; set; } - // public DateTimeOffset? LastLoginDate { get; set; } + public DateTimeOffset? LastActive { get; set; } + public virtual Customer Customer { get; set; } } } \ No newline at end of file diff --git a/Webshop.Domain/Entities/Customer.cs b/Webshop.Domain/Entities/Customer.cs index cb306f9..f877346 100644 --- a/Webshop.Domain/Entities/Customer.cs +++ b/Webshop.Domain/Entities/Customer.cs @@ -1,50 +1,25 @@ using System; -using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; -namespace Webshop.Domain.Entities; - -/// -/// Für registrierte Nutzer des Webshops. Dies ist die Schnittstelle zu ASP.NET Core Identity. -/// -public class Customer +namespace Webshop.Domain.Entities { - [Key] - public Guid Id { get; set; } + public class Customer + { + [Key] + public Guid Id { get; set; } + [Required] + public string AspNetUserId { get; set; } + [Required] + [MaxLength(100)] + public string FirstName { get; set; } + [Required] + [MaxLength(100)] + public string LastName { get; set; } - // Unique-Constraint und Foreign Key werden via Fluent API konfiguriert - [Required] - [MaxLength(450)] - public string AspNetUserId { get; set; } - - [Required] - [MaxLength(100)] - public string FirstName { get; set; } - - [Required] - [MaxLength(100)] - public string LastName { get; set; } - - // Unique-Constraint wird von Identity verwaltet - [Required] - [MaxLength(256)] - [EmailAddress] - public string Email { get; set; } - - [MaxLength(20)] - [Phone] - public string? PhoneNumber { get; set; } - - [Required] - public DateTimeOffset CreatedDate { get; set; } - - public DateTimeOffset? LastLoginDate { get; set; } - - [Required] - public bool IsActive { get; set; } - - // Navigation Properties - public virtual ICollection
Addresses { get; set; } = new List
(); - public virtual ICollection Orders { get; set; } = new List(); - public virtual ICollection Reviews { get; set; } = new List(); -} \ No newline at end of file + public virtual ApplicationUser User { get; set; } + public virtual ICollection
Addresses { get; set; } = new List
(); + public virtual ICollection Orders { get; set; } = new List(); + public virtual ICollection Reviews { get; set; } = new List(); + } +} diff --git a/Webshop.Domain/Interfaces/ICustomerRepository.cs b/Webshop.Domain/Interfaces/ICustomerRepository.cs index 81ddcfd..14789a1 100644 --- a/Webshop.Domain/Interfaces/ICustomerRepository.cs +++ b/Webshop.Domain/Interfaces/ICustomerRepository.cs @@ -1,14 +1,12 @@ -// Auto-generiert von CreateWebshopFiles.ps1 using System; -using System.Collections.Generic; using System.Threading.Tasks; using Webshop.Domain.Entities; - namespace Webshop.Domain.Interfaces { public interface ICustomerRepository { -// Fügen Sie hier Methodensignaturen hinzu + Task GetByUserIdAsync(string userId); + Task UpdateAsync(Customer customer); } -} +} \ No newline at end of file diff --git a/Webshop.Domain/Webshop.Domain.csproj b/Webshop.Domain/Webshop.Domain.csproj index 997858e..a015e30 100644 --- a/Webshop.Domain/Webshop.Domain.csproj +++ b/Webshop.Domain/Webshop.Domain.csproj @@ -7,7 +7,7 @@ - + diff --git a/Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.Designer.cs b/Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.Designer.cs deleted file mode 100644 index 5445b65..0000000 --- a/Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.Designer.cs +++ /dev/null @@ -1,1223 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Webshop.Infrastructure.Data; - -#nullable disable - -namespace Webshop.Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20250725095503_InitalCreate")] - partial class InitalCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.18") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("Roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("RoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("UserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("UserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("UserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("UserTokens", (string)null); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AddressType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("City") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("CompanyName") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("CustomerId") - .HasColumnType("uuid"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PostalCode") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("State") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Street") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Street2") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.HasKey("Id"); - - b.HasIndex("CustomerId"); - - b.ToTable("Addresses"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ApplicationUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DisplayOrder") - .HasColumnType("integer"); - - b.Property("ImageUrl") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("ParentCategoryId") - .HasColumnType("uuid"); - - b.Property("Slug") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.HasKey("Id"); - - b.HasIndex("ParentCategoryId"); - - b.HasIndex("Slug") - .IsUnique(); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b => - { - b.Property("CategoryId") - .HasColumnType("uuid"); - - b.Property("DiscountId") - .HasColumnType("uuid"); - - b.HasKey("CategoryId", "DiscountId"); - - b.HasIndex("DiscountId"); - - b.ToTable("CategoryDiscounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Customer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AspNetUserId") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("character varying(450)"); - - b.Property("CreatedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("LastLoginDate") - .HasColumnType("timestamp with time zone"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PhoneNumber") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.HasKey("Id"); - - b.ToTable("Customers"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Discount", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CouponCode") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("CurrentUsageCount") - .HasColumnType("integer"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DiscountType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("DiscountValue") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("EndDate") - .HasColumnType("timestamp with time zone"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("MaximumUsageCount") - .HasColumnType("integer"); - - b.Property("MinimumOrderAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("RequiresCouponCode") - .HasColumnType("boolean"); - - b.Property("StartDate") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("CouponCode") - .IsUnique() - .HasFilter("\"CouponCode\" IS NOT NULL"); - - b.ToTable("Discounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AdminNotes") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("BillingAddressId") - .HasColumnType("uuid"); - - b.Property("CustomerId") - .HasColumnType("uuid"); - - b.Property("CustomerNotes") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DiscountAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("GuestEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("GuestPhoneNumber") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("OrderDate") - .HasColumnType("timestamp with time zone"); - - b.Property("OrderNumber") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("OrderStatus") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("OrderTotal") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("PaymentMethod") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PaymentMethodId") - .HasColumnType("uuid"); - - b.Property("PaymentStatus") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ShippingAddressId") - .HasColumnType("uuid"); - - b.Property("ShippingCost") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("ShippingMethodId") - .HasColumnType("uuid"); - - b.Property("TaxAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("TransactionId") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("CustomerId"); - - b.HasIndex("OrderNumber") - .IsUnique(); - - b.HasIndex("PaymentMethodId"); - - b.HasIndex("ShippingAddressId"); - - b.HasIndex("ShippingMethodId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("ProductName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("ProductSKU") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ProductVariantId") - .HasColumnType("uuid"); - - b.Property("Quantity") - .HasColumnType("integer"); - - b.Property("TotalPrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("UnitPrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.HasIndex("ProductId"); - - b.HasIndex("ProductVariantId"); - - b.ToTable("OrderItems"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.PaymentMethod", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PaymentGatewayType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ProcessingFee") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.HasKey("Id"); - - b.ToTable("PaymentMethods"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(4000) - .HasColumnType("character varying(4000)"); - - b.Property("Height") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("ImageUrl") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("IsInStock") - .HasColumnType("boolean"); - - b.Property("LastModifiedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Length") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("OldPrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Price") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("PurchasePrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("SKU") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ShortDescription") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("Slug") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("StockQuantity") - .HasColumnType("integer"); - - b.Property("SupplierId") - .HasColumnType("uuid"); - - b.Property("Weight") - .HasPrecision(18, 3) - .HasColumnType("numeric(18,3)"); - - b.Property("Width") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("SKU") - .IsUnique(); - - b.HasIndex("Slug") - .IsUnique(); - - b.HasIndex("SupplierId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b => - { - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("CategoryId") - .HasColumnType("uuid"); - - b.HasKey("ProductId", "CategoryId"); - - b.HasIndex("CategoryId"); - - b.ToTable("ProductCategories"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b => - { - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("DiscountId") - .HasColumnType("uuid"); - - b.HasKey("ProductId", "DiscountId"); - - b.HasIndex("DiscountId"); - - b.ToTable("ProductDiscounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductVariant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ImageUrl") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PriceAdjustment") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("SKU") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("StockQuantity") - .HasColumnType("integer"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.ToTable("ProductVariants"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Review", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Comment") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("CustomerId") - .HasColumnType("uuid"); - - b.Property("IsApproved") - .HasColumnType("boolean"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("Rating") - .HasColumnType("integer"); - - b.Property("ReviewDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Title") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("CustomerId"); - - b.HasIndex("ProductId"); - - b.ToTable("Reviews"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Setting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("Group") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Value") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("Settings"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ShippingMethod", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("BaseCost") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("EstimatedDeliveryTime") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("MinimumOrderAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("RequiresTracking") - .HasColumnType("boolean"); - - b.HasKey("Id"); - - b.ToTable("ShippingMethods"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Supplier", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AddressId") - .HasColumnType("uuid"); - - b.Property("ContactPerson") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Notes") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("PhoneNumber") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("AddressId"); - - b.ToTable("Suppliers"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Address", b => - { - b.HasOne("Webshop.Domain.Entities.Customer", "Customer") - .WithMany("Addresses") - .HasForeignKey("CustomerId"); - - b.Navigation("Customer"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Category", b => - { - b.HasOne("Webshop.Domain.Entities.Category", "ParentCategory") - .WithMany("SubCategories") - .HasForeignKey("ParentCategoryId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("ParentCategory"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b => - { - b.HasOne("Webshop.Domain.Entities.Category", "Category") - .WithMany("CategoryDiscounts") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Discount", "Discount") - .WithMany("CategoryDiscounts") - .HasForeignKey("DiscountId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - - b.Navigation("Discount"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Order", b => - { - b.HasOne("Webshop.Domain.Entities.Address", "BillingAddress") - .WithMany() - .HasForeignKey("BillingAddressId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Customer", "Customer") - .WithMany("Orders") - .HasForeignKey("CustomerId"); - - b.HasOne("Webshop.Domain.Entities.PaymentMethod", "PaymentMethodInfo") - .WithMany() - .HasForeignKey("PaymentMethodId"); - - b.HasOne("Webshop.Domain.Entities.Address", "ShippingAddress") - .WithMany() - .HasForeignKey("ShippingAddressId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.ShippingMethod", "ShippingMethodInfo") - .WithMany() - .HasForeignKey("ShippingMethodId"); - - b.Navigation("BillingAddress"); - - b.Navigation("Customer"); - - b.Navigation("PaymentMethodInfo"); - - b.Navigation("ShippingAddress"); - - b.Navigation("ShippingMethodInfo"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.OrderItem", b => - { - b.HasOne("Webshop.Domain.Entities.Order", "Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Webshop.Domain.Entities.ProductVariant", "ProductVariant") - .WithMany() - .HasForeignKey("ProductVariantId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("Order"); - - b.Navigation("Product"); - - b.Navigation("ProductVariant"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Product", b => - { - b.HasOne("Webshop.Domain.Entities.Supplier", "Supplier") - .WithMany("Products") - .HasForeignKey("SupplierId"); - - b.Navigation("Supplier"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b => - { - b.HasOne("Webshop.Domain.Entities.Category", "Category") - .WithMany("ProductCategories") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("ProductCategories") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b => - { - b.HasOne("Webshop.Domain.Entities.Discount", "Discount") - .WithMany("ProductDiscounts") - .HasForeignKey("DiscountId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("ProductDiscounts") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Discount"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductVariant", b => - { - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("Variants") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Review", b => - { - b.HasOne("Webshop.Domain.Entities.Customer", "Customer") - .WithMany("Reviews") - .HasForeignKey("CustomerId"); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("Reviews") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Customer"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Supplier", b => - { - b.HasOne("Webshop.Domain.Entities.Address", "Address") - .WithMany() - .HasForeignKey("AddressId"); - - b.Navigation("Address"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Category", b => - { - b.Navigation("CategoryDiscounts"); - - b.Navigation("ProductCategories"); - - b.Navigation("SubCategories"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Customer", b => - { - b.Navigation("Addresses"); - - b.Navigation("Orders"); - - b.Navigation("Reviews"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Discount", b => - { - b.Navigation("CategoryDiscounts"); - - b.Navigation("ProductDiscounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Order", b => - { - b.Navigation("OrderItems"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Product", b => - { - b.Navigation("ProductCategories"); - - b.Navigation("ProductDiscounts"); - - b.Navigation("Reviews"); - - b.Navigation("Variants"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Supplier", b => - { - b.Navigation("Products"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.cs b/Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.cs deleted file mode 100644 index 48653b8..0000000 --- a/Webshop.Infrastructure/Migrations/20250725095503_InitalCreate.cs +++ /dev/null @@ -1,819 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Webshop.Infrastructure.Migrations -{ - /// - public partial class InitalCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - 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), - 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) - }, - constraints: table => - { - table.PrimaryKey("PK_Categories", x => x.Id); - table.ForeignKey( - name: "FK_Categories_Categories_ParentCategoryId", - column: x => x.ParentCategoryId, - principalTable: "Categories", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "Customers", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - AspNetUserId = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), - FirstName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - LastName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), - PhoneNumber = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), - CreatedDate = table.Column(type: "timestamp with time zone", nullable: false), - LastLoginDate = table.Column(type: "timestamp with time zone", nullable: true), - IsActive = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Customers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Discounts", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - DiscountType = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - DiscountValue = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - StartDate = table.Column(type: "timestamp with time zone", nullable: false), - EndDate = table.Column(type: "timestamp with time zone", nullable: true), - IsActive = table.Column(type: "boolean", nullable: false), - RequiresCouponCode = table.Column(type: "boolean", nullable: false), - CouponCode = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - MinimumOrderAmount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true), - MaximumUsageCount = table.Column(type: "integer", nullable: true), - CurrentUsageCount = table.Column(type: "integer", nullable: false), - Description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Discounts", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "PaymentMethods", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - IsActive = table.Column(type: "boolean", nullable: false), - PaymentGatewayType = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - ProcessingFee = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PaymentMethods", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Roles", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Roles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Settings", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Key = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - Value = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), - Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - IsActive = table.Column(type: "boolean", nullable: false), - Group = table.Column(type: "character varying(100)", maxLength: 100, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Settings", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "ShippingMethods", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - BaseCost = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - MinimumOrderAmount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true), - IsActive = table.Column(type: "boolean", nullable: false), - EstimatedDeliveryTime = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - RequiresTracking = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ShippingMethods", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - CreatedDate = table.Column(type: "timestamp with time zone", nullable: false), - UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "boolean", nullable: false), - PasswordHash = table.Column(type: "text", nullable: true), - SecurityStamp = table.Column(type: "text", nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true), - PhoneNumber = table.Column(type: "text", nullable: true), - PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), - TwoFactorEnabled = table.Column(type: "boolean", nullable: false), - LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), - LockoutEnabled = table.Column(type: "boolean", nullable: false), - AccessFailedCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Addresses", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - CustomerId = table.Column(type: "uuid", nullable: true), - AddressType = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - Street = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - Street2 = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - City = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - State = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - PostalCode = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), - Country = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - CompanyName = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - FirstName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - LastName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Addresses", x => x.Id); - table.ForeignKey( - name: "FK_Addresses_Customers_CustomerId", - column: x => x.CustomerId, - principalTable: "Customers", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "CategoryDiscounts", - columns: table => new - { - CategoryId = 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.ForeignKey( - name: "FK_CategoryDiscounts_Categories_CategoryId", - column: x => x.CategoryId, - principalTable: "Categories", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_CategoryDiscounts_Discounts_DiscountId", - column: x => x.DiscountId, - principalTable: "Discounts", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "RoleClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "text", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_RoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_RoleClaims_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "text", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserClaims", x => x.Id); - table.ForeignKey( - name: "FK_UserClaims_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "text", nullable: false), - ProviderKey = table.Column(type: "text", nullable: false), - ProviderDisplayName = table.Column(type: "text", nullable: true), - UserId = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_UserLogins_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserRoles", - columns: table => new - { - UserId = table.Column(type: "text", nullable: false), - RoleId = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_UserRoles_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserRoles_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserTokens", - columns: table => new - { - UserId = table.Column(type: "text", nullable: false), - LoginProvider = table.Column(type: "text", nullable: false), - Name = table.Column(type: "text", nullable: false), - Value = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_UserTokens_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderNumber = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - CustomerId = table.Column(type: "uuid", nullable: true), - GuestEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - GuestPhoneNumber = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), - OrderDate = table.Column(type: "timestamp with time zone", nullable: false), - OrderStatus = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - OrderTotal = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - ShippingCost = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - TaxAmount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - DiscountAmount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - PaymentStatus = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - PaymentMethod = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - PaymentMethodId = table.Column(type: "uuid", nullable: true), - ShippingMethodId = table.Column(type: "uuid", nullable: true), - TransactionId = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - BillingAddressId = table.Column(type: "uuid", nullable: false), - ShippingAddressId = table.Column(type: "uuid", nullable: false), - CustomerNotes = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), - AdminNotes = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Addresses_BillingAddressId", - column: x => x.BillingAddressId, - principalTable: "Addresses", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Orders_Addresses_ShippingAddressId", - column: x => x.ShippingAddressId, - principalTable: "Addresses", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Orders_Customers_CustomerId", - column: x => x.CustomerId, - principalTable: "Customers", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Orders_PaymentMethods_PaymentMethodId", - column: x => x.PaymentMethodId, - principalTable: "PaymentMethods", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Orders_ShippingMethods_ShippingMethodId", - column: x => x.ShippingMethodId, - principalTable: "ShippingMethods", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "Suppliers", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - ContactPerson = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - PhoneNumber = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - AddressId = table.Column(type: "uuid", nullable: true), - Notes = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Suppliers", x => x.Id); - table.ForeignKey( - name: "FK_Suppliers_Addresses_AddressId", - column: x => x.AddressId, - principalTable: "Addresses", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "Products", - 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(4000)", maxLength: 4000, nullable: true), - ShortDescription = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - SKU = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - Price = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - OldPrice = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true), - IsActive = table.Column(type: "boolean", nullable: false), - IsInStock = table.Column(type: "boolean", nullable: false), - StockQuantity = table.Column(type: "integer", nullable: false), - Weight = table.Column(type: "numeric(18,3)", precision: 18, scale: 3, nullable: true), - Width = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true), - Height = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true), - Length = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true), - ImageUrl = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), - Slug = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - CreatedDate = table.Column(type: "timestamp with time zone", nullable: false), - LastModifiedDate = table.Column(type: "timestamp with time zone", nullable: true), - SupplierId = table.Column(type: "uuid", nullable: true), - PurchasePrice = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Products", x => x.Id); - table.ForeignKey( - name: "FK_Products_Suppliers_SupplierId", - column: x => x.SupplierId, - principalTable: "Suppliers", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "ProductCategories", - columns: table => new - { - ProductId = table.Column(type: "uuid", nullable: false), - CategoryId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ProductCategories", x => new { x.ProductId, x.CategoryId }); - table.ForeignKey( - name: "FK_ProductCategories_Categories_CategoryId", - column: x => x.CategoryId, - principalTable: "Categories", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ProductCategories_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ProductDiscounts", - columns: table => new - { - ProductId = table.Column(type: "uuid", nullable: false), - DiscountId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ProductDiscounts", x => new { x.ProductId, x.DiscountId }); - table.ForeignKey( - name: "FK_ProductDiscounts_Discounts_DiscountId", - column: x => x.DiscountId, - principalTable: "Discounts", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ProductDiscounts_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ProductVariants", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - ProductId = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Value = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - SKU = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - PriceAdjustment = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - StockQuantity = table.Column(type: "integer", nullable: false), - ImageUrl = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), - IsActive = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ProductVariants", x => x.Id); - table.ForeignKey( - name: "FK_ProductVariants_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Reviews", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - ProductId = table.Column(type: "uuid", nullable: false), - CustomerId = table.Column(type: "uuid", nullable: true), - Rating = table.Column(type: "integer", nullable: false), - Title = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - Comment = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), - ReviewDate = table.Column(type: "timestamp with time zone", nullable: false), - IsApproved = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Reviews", x => x.Id); - table.ForeignKey( - name: "FK_Reviews_Customers_CustomerId", - column: x => x.CustomerId, - principalTable: "Customers", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Reviews_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "OrderItems", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false), - ProductId = table.Column(type: "uuid", nullable: true), - ProductVariantId = table.Column(type: "uuid", nullable: true), - ProductName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - ProductSKU = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - Quantity = table.Column(type: "integer", nullable: false), - UnitPrice = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), - TotalPrice = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderItems", x => x.Id); - table.ForeignKey( - name: "FK_OrderItems_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrderItems_ProductVariants_ProductVariantId", - column: x => x.ProductVariantId, - principalTable: "ProductVariants", - principalColumn: "Id", - onDelete: ReferentialAction.SetNull); - table.ForeignKey( - name: "FK_OrderItems_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.SetNull); - }); - - migrationBuilder.CreateIndex( - name: "IX_Addresses_CustomerId", - table: "Addresses", - column: "CustomerId"); - - migrationBuilder.CreateIndex( - name: "IX_Categories_ParentCategoryId", - table: "Categories", - column: "ParentCategoryId"); - - migrationBuilder.CreateIndex( - name: "IX_Categories_Slug", - table: "Categories", - column: "Slug", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_CategoryDiscounts_DiscountId", - table: "CategoryDiscounts", - column: "DiscountId"); - - migrationBuilder.CreateIndex( - name: "IX_Discounts_CouponCode", - table: "Discounts", - column: "CouponCode", - unique: true, - filter: "\"CouponCode\" IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItems_OrderId", - table: "OrderItems", - column: "OrderId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItems_ProductId", - table: "OrderItems", - column: "ProductId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItems_ProductVariantId", - table: "OrderItems", - column: "ProductVariantId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_BillingAddressId", - table: "Orders", - column: "BillingAddressId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_CustomerId", - table: "Orders", - column: "CustomerId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_OrderNumber", - table: "Orders", - column: "OrderNumber", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Orders_PaymentMethodId", - table: "Orders", - column: "PaymentMethodId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ShippingAddressId", - table: "Orders", - column: "ShippingAddressId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ShippingMethodId", - table: "Orders", - column: "ShippingMethodId"); - - migrationBuilder.CreateIndex( - name: "IX_ProductCategories_CategoryId", - table: "ProductCategories", - column: "CategoryId"); - - migrationBuilder.CreateIndex( - name: "IX_ProductDiscounts_DiscountId", - table: "ProductDiscounts", - column: "DiscountId"); - - migrationBuilder.CreateIndex( - name: "IX_Products_SKU", - table: "Products", - column: "SKU", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Products_Slug", - table: "Products", - column: "Slug", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Products_SupplierId", - table: "Products", - column: "SupplierId"); - - migrationBuilder.CreateIndex( - name: "IX_ProductVariants_ProductId", - table: "ProductVariants", - column: "ProductId"); - - migrationBuilder.CreateIndex( - name: "IX_Reviews_CustomerId", - table: "Reviews", - column: "CustomerId"); - - migrationBuilder.CreateIndex( - name: "IX_Reviews_ProductId", - table: "Reviews", - column: "ProductId"); - - migrationBuilder.CreateIndex( - name: "IX_RoleClaims_RoleId", - table: "RoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "Roles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Settings_Key", - table: "Settings", - column: "Key", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Suppliers_AddressId", - table: "Suppliers", - column: "AddressId"); - - migrationBuilder.CreateIndex( - name: "IX_UserClaims_UserId", - table: "UserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserLogins_UserId", - table: "UserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserRoles_RoleId", - table: "UserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "Users", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "Users", - column: "NormalizedUserName", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CategoryDiscounts"); - - migrationBuilder.DropTable( - name: "OrderItems"); - - migrationBuilder.DropTable( - name: "ProductCategories"); - - migrationBuilder.DropTable( - name: "ProductDiscounts"); - - migrationBuilder.DropTable( - name: "Reviews"); - - migrationBuilder.DropTable( - name: "RoleClaims"); - - migrationBuilder.DropTable( - name: "Settings"); - - migrationBuilder.DropTable( - name: "UserClaims"); - - migrationBuilder.DropTable( - name: "UserLogins"); - - migrationBuilder.DropTable( - name: "UserRoles"); - - migrationBuilder.DropTable( - name: "UserTokens"); - - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "ProductVariants"); - - migrationBuilder.DropTable( - name: "Categories"); - - migrationBuilder.DropTable( - name: "Discounts"); - - migrationBuilder.DropTable( - name: "Roles"); - - migrationBuilder.DropTable( - name: "Users"); - - migrationBuilder.DropTable( - name: "PaymentMethods"); - - migrationBuilder.DropTable( - name: "ShippingMethods"); - - migrationBuilder.DropTable( - name: "Products"); - - migrationBuilder.DropTable( - name: "Suppliers"); - - migrationBuilder.DropTable( - name: "Addresses"); - - migrationBuilder.DropTable( - name: "Customers"); - } - } -} diff --git a/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs deleted file mode 100644 index f7d9fdd..0000000 --- a/Webshop.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ /dev/null @@ -1,1220 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Webshop.Infrastructure.Data; - -#nullable disable - -namespace Webshop.Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.18") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("Roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("RoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("UserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("UserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("UserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("UserTokens", (string)null); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AddressType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("City") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("CompanyName") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("CustomerId") - .HasColumnType("uuid"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PostalCode") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("State") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Street") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Street2") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.HasKey("Id"); - - b.HasIndex("CustomerId"); - - b.ToTable("Addresses"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ApplicationUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DisplayOrder") - .HasColumnType("integer"); - - b.Property("ImageUrl") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("ParentCategoryId") - .HasColumnType("uuid"); - - b.Property("Slug") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.HasKey("Id"); - - b.HasIndex("ParentCategoryId"); - - b.HasIndex("Slug") - .IsUnique(); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b => - { - b.Property("CategoryId") - .HasColumnType("uuid"); - - b.Property("DiscountId") - .HasColumnType("uuid"); - - b.HasKey("CategoryId", "DiscountId"); - - b.HasIndex("DiscountId"); - - b.ToTable("CategoryDiscounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Customer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AspNetUserId") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("character varying(450)"); - - b.Property("CreatedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("LastLoginDate") - .HasColumnType("timestamp with time zone"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PhoneNumber") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.HasKey("Id"); - - b.ToTable("Customers"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Discount", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CouponCode") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("CurrentUsageCount") - .HasColumnType("integer"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DiscountType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("DiscountValue") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("EndDate") - .HasColumnType("timestamp with time zone"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("MaximumUsageCount") - .HasColumnType("integer"); - - b.Property("MinimumOrderAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("RequiresCouponCode") - .HasColumnType("boolean"); - - b.Property("StartDate") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("CouponCode") - .IsUnique() - .HasFilter("\"CouponCode\" IS NOT NULL"); - - b.ToTable("Discounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AdminNotes") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("BillingAddressId") - .HasColumnType("uuid"); - - b.Property("CustomerId") - .HasColumnType("uuid"); - - b.Property("CustomerNotes") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DiscountAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("GuestEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("GuestPhoneNumber") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("OrderDate") - .HasColumnType("timestamp with time zone"); - - b.Property("OrderNumber") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("OrderStatus") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("OrderTotal") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("PaymentMethod") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PaymentMethodId") - .HasColumnType("uuid"); - - b.Property("PaymentStatus") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ShippingAddressId") - .HasColumnType("uuid"); - - b.Property("ShippingCost") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("ShippingMethodId") - .HasColumnType("uuid"); - - b.Property("TaxAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("TransactionId") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("CustomerId"); - - b.HasIndex("OrderNumber") - .IsUnique(); - - b.HasIndex("PaymentMethodId"); - - b.HasIndex("ShippingAddressId"); - - b.HasIndex("ShippingMethodId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("ProductName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("ProductSKU") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ProductVariantId") - .HasColumnType("uuid"); - - b.Property("Quantity") - .HasColumnType("integer"); - - b.Property("TotalPrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("UnitPrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.HasIndex("ProductId"); - - b.HasIndex("ProductVariantId"); - - b.ToTable("OrderItems"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.PaymentMethod", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PaymentGatewayType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ProcessingFee") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.HasKey("Id"); - - b.ToTable("PaymentMethods"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(4000) - .HasColumnType("character varying(4000)"); - - b.Property("Height") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("ImageUrl") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("IsInStock") - .HasColumnType("boolean"); - - b.Property("LastModifiedDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Length") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("OldPrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Price") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("PurchasePrice") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("SKU") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ShortDescription") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("Slug") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("StockQuantity") - .HasColumnType("integer"); - - b.Property("SupplierId") - .HasColumnType("uuid"); - - b.Property("Weight") - .HasPrecision(18, 3) - .HasColumnType("numeric(18,3)"); - - b.Property("Width") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("SKU") - .IsUnique(); - - b.HasIndex("Slug") - .IsUnique(); - - b.HasIndex("SupplierId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b => - { - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("CategoryId") - .HasColumnType("uuid"); - - b.HasKey("ProductId", "CategoryId"); - - b.HasIndex("CategoryId"); - - b.ToTable("ProductCategories"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b => - { - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("DiscountId") - .HasColumnType("uuid"); - - b.HasKey("ProductId", "DiscountId"); - - b.HasIndex("DiscountId"); - - b.ToTable("ProductDiscounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductVariant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ImageUrl") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("PriceAdjustment") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("SKU") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("StockQuantity") - .HasColumnType("integer"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.ToTable("ProductVariants"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Review", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Comment") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("CustomerId") - .HasColumnType("uuid"); - - b.Property("IsApproved") - .HasColumnType("boolean"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("Rating") - .HasColumnType("integer"); - - b.Property("ReviewDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Title") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("CustomerId"); - - b.HasIndex("ProductId"); - - b.ToTable("Reviews"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Setting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("Group") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Value") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("Settings"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ShippingMethod", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("BaseCost") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("EstimatedDeliveryTime") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("MinimumOrderAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("RequiresTracking") - .HasColumnType("boolean"); - - b.HasKey("Id"); - - b.ToTable("ShippingMethods"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Supplier", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AddressId") - .HasColumnType("uuid"); - - b.Property("ContactPerson") - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("Notes") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("PhoneNumber") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("AddressId"); - - b.ToTable("Suppliers"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Webshop.Domain.Entities.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Address", b => - { - b.HasOne("Webshop.Domain.Entities.Customer", "Customer") - .WithMany("Addresses") - .HasForeignKey("CustomerId"); - - b.Navigation("Customer"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Category", b => - { - b.HasOne("Webshop.Domain.Entities.Category", "ParentCategory") - .WithMany("SubCategories") - .HasForeignKey("ParentCategoryId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("ParentCategory"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.CategoryDiscount", b => - { - b.HasOne("Webshop.Domain.Entities.Category", "Category") - .WithMany("CategoryDiscounts") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Discount", "Discount") - .WithMany("CategoryDiscounts") - .HasForeignKey("DiscountId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - - b.Navigation("Discount"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Order", b => - { - b.HasOne("Webshop.Domain.Entities.Address", "BillingAddress") - .WithMany() - .HasForeignKey("BillingAddressId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Customer", "Customer") - .WithMany("Orders") - .HasForeignKey("CustomerId"); - - b.HasOne("Webshop.Domain.Entities.PaymentMethod", "PaymentMethodInfo") - .WithMany() - .HasForeignKey("PaymentMethodId"); - - b.HasOne("Webshop.Domain.Entities.Address", "ShippingAddress") - .WithMany() - .HasForeignKey("ShippingAddressId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.ShippingMethod", "ShippingMethodInfo") - .WithMany() - .HasForeignKey("ShippingMethodId"); - - b.Navigation("BillingAddress"); - - b.Navigation("Customer"); - - b.Navigation("PaymentMethodInfo"); - - b.Navigation("ShippingAddress"); - - b.Navigation("ShippingMethodInfo"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.OrderItem", b => - { - b.HasOne("Webshop.Domain.Entities.Order", "Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Webshop.Domain.Entities.ProductVariant", "ProductVariant") - .WithMany() - .HasForeignKey("ProductVariantId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("Order"); - - b.Navigation("Product"); - - b.Navigation("ProductVariant"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Product", b => - { - b.HasOne("Webshop.Domain.Entities.Supplier", "Supplier") - .WithMany("Products") - .HasForeignKey("SupplierId"); - - b.Navigation("Supplier"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductCategory", b => - { - b.HasOne("Webshop.Domain.Entities.Category", "Category") - .WithMany("ProductCategories") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("ProductCategories") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductDiscount", b => - { - b.HasOne("Webshop.Domain.Entities.Discount", "Discount") - .WithMany("ProductDiscounts") - .HasForeignKey("DiscountId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("ProductDiscounts") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Discount"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.ProductVariant", b => - { - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("Variants") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Review", b => - { - b.HasOne("Webshop.Domain.Entities.Customer", "Customer") - .WithMany("Reviews") - .HasForeignKey("CustomerId"); - - b.HasOne("Webshop.Domain.Entities.Product", "Product") - .WithMany("Reviews") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Customer"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Supplier", b => - { - b.HasOne("Webshop.Domain.Entities.Address", "Address") - .WithMany() - .HasForeignKey("AddressId"); - - b.Navigation("Address"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Category", b => - { - b.Navigation("CategoryDiscounts"); - - b.Navigation("ProductCategories"); - - b.Navigation("SubCategories"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Customer", b => - { - b.Navigation("Addresses"); - - b.Navigation("Orders"); - - b.Navigation("Reviews"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Discount", b => - { - b.Navigation("CategoryDiscounts"); - - b.Navigation("ProductDiscounts"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Order", b => - { - b.Navigation("OrderItems"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Product", b => - { - b.Navigation("ProductCategories"); - - b.Navigation("ProductDiscounts"); - - b.Navigation("Reviews"); - - b.Navigation("Variants"); - }); - - modelBuilder.Entity("Webshop.Domain.Entities.Supplier", b => - { - b.Navigation("Products"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Webshop.Infrastructure/Repositories/CustomerRepository.cs b/Webshop.Infrastructure/Repositories/CustomerRepository.cs index 04984a8..e26277c 100644 --- a/Webshop.Infrastructure/Repositories/CustomerRepository.cs +++ b/Webshop.Infrastructure/Repositories/CustomerRepository.cs @@ -1,10 +1,8 @@ -// Auto-generiert von CreateWebshopFiles.ps1 using Microsoft.EntityFrameworkCore; using Webshop.Domain.Entities; using Webshop.Domain.Interfaces; using Webshop.Infrastructure.Data; using System; -using System.Collections.Generic; using System.Threading.Tasks; namespace Webshop.Infrastructure.Repositories @@ -18,12 +16,15 @@ namespace Webshop.Infrastructure.Repositories _context = context; } - // Fügen Sie hier Repository-Methoden hinzu - // Beispiel: - // public async Task> GetAllAsync() { return await _context.Set().ToListAsync(); } - // public async Task GetByIdAsync(Guid id) { return await _context.Set().FindAsync(id); } - // public async Task AddAsync(T entity) { _context.Set().Add(entity); await _context.SaveChangesAsync(); } - // public async Task UpdateAsync(T entity) { _context.Set().Update(entity); await _context.SaveChangesAsync(); } - // public async Task DeleteAsync(Guid id) { var entity = await _context.Set().FindAsync(id); if (entity != null) { _context.Set().Remove(entity); await _context.SaveChangesAsync(); } } + public async Task GetByUserIdAsync(string userId) + { + return await _context.Customers.FirstOrDefaultAsync(c => c.AspNetUserId == userId); + } + + public async Task UpdateAsync(Customer customer) + { + _context.Customers.Update(customer); + await _context.SaveChangesAsync(); + } } -} +} \ No newline at end of file