This commit is contained in:
Tizian.Breuch
2025-07-31 16:37:35 +02:00
parent 2d93fda7e9
commit 3858375b66
9 changed files with 290 additions and 3349 deletions

View File

@@ -1,22 +1,71 @@
// Auto-generiert von CreateWebshopFiles.ps1
using Microsoft.AspNetCore.Mvc;
// src/Webshop.Api/Controllers/Customer/OrdersController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Orders;
using Webshop.Application.Services.Customers;
using Webshop.Application.Services.Customers.Interfaces; // Für IOrderService
namespace Webshop.Api.Controllers.Customers
namespace Webshop.Api.Controllers.Customer
{
[ApiController]
[Route("api/v1/customer/[controller]")]
[Route("api/v1/customer/orders")]
[Authorize(Roles = "Customer")]
public class OrdersController : ControllerBase
{
[HttpGet("my-orders")]
public async Task<IActionResult> GetMyOrders()
private readonly IOrderService _orderService;
public OrdersController(IOrderService orderService)
{
return Ok(new { Message = "Dies ist Ihr persönlicher Bestellverlauf (Platzhalter)." });
_orderService = orderService;
}
[HttpPost]
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderDto orderDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrEmpty(userId))
{
// In einer [Authorize]-Methode sollte das nie passieren, aber zur Sicherheit
return Unauthorized();
}
var (success, createdOrder, errorMessage) = await _orderService.CreateOrderAsync(orderDto, userId);
if (!success)
{
return BadRequest(new { Message = errorMessage });
}
// Hier wird GetMyOrderById referenziert, also erstellen wir eine leere Methode dafür
return CreatedAtAction(nameof(GetMyOrderById), new { id = createdOrder.Id }, createdOrder);
}
[HttpGet]
public async Task<ActionResult<IEnumerable<OrderSummaryDto>>> GetMyOrders()
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrEmpty(userId)) return Unauthorized();
var orders = await _orderService.GetMyOrdersAsync(userId);
return Ok(orders);
}
[HttpGet("{id}")]
public async Task<ActionResult<OrderDetailDto>> GetMyOrderById(Guid id)
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrEmpty(userId)) return Unauthorized();
var order = await _orderService.GetMyOrderByIdAsync(id, userId);
if (order == null) return NotFound();
return Ok(order);
}
}
}

View File

@@ -83,6 +83,7 @@ builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
builder.Services.AddScoped<IPaymentMethodRepository, PaymentMethodRepository>();
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddScoped<IShippingMethodRepository, ShippingMethodRepository>();
// AUTH Services
builder.Services.AddScoped<IAuthService, AuthService>();
@@ -101,12 +102,12 @@ builder.Services.AddScoped<IAdminPaymentMethodService, AdminPaymentMethodService
builder.Services.AddScoped<IAdminCategoryService, AdminCategoryService>(); // Hinzugef<65>gt f<>r Konsistenz
builder.Services.AddScoped<IAdminOrderService, AdminOrderService>();
//builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>(); // Hinzugef<65>gt f<>r Konsistenz
//builder.Services.AddScoped<IAdminOrderService, AdminOrderService>(); // Hinzugef<65>gt f<>r Konsistenz
builder.Services.AddScoped<IAdminOrderService, AdminOrderService>(); // Hinzugef<65>gt f<>r Konsistenz
//builder.Services.AddScoped<IAdminSettingService, AdminSettingService>(); // Hinzugef<65>gt f<>r Konsistenz
// CUSTOMER Services (sp<73>ter Implementierungen hinzuf<75>gen)
builder.Services.AddScoped<ICustomerService, CustomerService>();
//builder.Services.AddScoped<IOrderService, OrderService>(); // Hinzugef<65>gt f<>r Konsistenz
builder.Services.AddScoped<IOrderService, OrderService>(); // Hinzugef<65>gt f<>r Konsistenz
//builder.Services.AddScoped<ICheckoutService, CheckoutService>(); // Hinzugef<65>gt f<>r Konsistenz
//builder.Services.AddScoped<IReviewService, ReviewService>(); // Hinzugef<65>gt f<>r Konsistenz

View File

@@ -1,16 +1,15 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Application/Services/Customers/IOrderService.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs;
using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
using Webshop.Application.DTOs.Orders;
namespace Webshop.Application.Services.Customers.Interfaces
namespace Webshop.Application.Services.Customers
{
public interface IOrderService
{
// Fügen Sie hier Methodensignaturen hinzu
Task<(bool Success, OrderDetailDto? CreatedOrder, string? ErrorMessage)> CreateOrderAsync(CreateOrderDto orderDto, string userId);
Task<IEnumerable<OrderSummaryDto>> GetMyOrdersAsync(string userId);
Task<OrderDetailDto?> GetMyOrderByIdAsync(Guid orderId, string userId);
}
}

View File

@@ -1,18 +1,211 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Application/Services/Customers/OrderService.cs
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.Services.Customers.Interfaces;
using Webshop.Application.DTOs.Orders;
using Webshop.Domain.Entities;
using Webshop.Domain.Enums;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
namespace Webshop.Application.Services.Customers
{
public class OrderService : IOrderService
{
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
private readonly ApplicationDbContext _context;
private readonly IOrderRepository _orderRepository;
private readonly IProductRepository _productRepository;
private readonly IShippingMethodRepository _shippingMethodRepository;
private readonly ICustomerRepository _customerRepository;
// public OrderService(IYourRepository repository) { }
public OrderService(
ApplicationDbContext context,
IOrderRepository orderRepository,
IProductRepository productRepository,
IShippingMethodRepository shippingMethodRepository,
ICustomerRepository customerRepository)
{
_context = context;
_orderRepository = orderRepository;
_productRepository = productRepository;
_shippingMethodRepository = shippingMethodRepository;
_customerRepository = customerRepository;
}
// Fügen Sie hier Service-Methoden hinzu
public async Task<(bool Success, OrderDetailDto? CreatedOrder, string? ErrorMessage)> CreateOrderAsync(CreateOrderDto orderDto, string userId)
{
await using var transaction = await _context.Database.BeginTransactionAsync();
try
{
var customer = await _customerRepository.GetByUserIdAsync(userId);
if (customer == null)
{
return (false, null, "Kundenprofil nicht gefunden.");
}
var shippingMethod = await _shippingMethodRepository.GetByIdAsync(orderDto.ShippingMethodId);
if (shippingMethod == null || !shippingMethod.IsActive) return (false, null, "Ungültige Versandmethode.");
var paymentMethod = await _context.PaymentMethods.FindAsync(orderDto.PaymentMethodId);
if (paymentMethod == null || !paymentMethod.IsActive) return (false, null, "Ungültige Zahlungsmethode.");
if (!await _context.Addresses.AnyAsync(a => a.Id == orderDto.ShippingAddressId && a.Customer.AspNetUserId == userId) ||
!await _context.Addresses.AnyAsync(a => a.Id == orderDto.BillingAddressId && a.Customer.AspNetUserId == userId))
{
return (false, null, "Ungültige oder nicht zugehörige Liefer- oder Rechnungsadresse.");
}
var orderItems = new List<OrderItem>();
decimal itemsTotal = 0;
foreach (var itemDto in orderDto.Items)
{
var product = await _productRepository.GetProductByIdAsync(itemDto.ProductId);
if (product == null || !product.IsActive)
{
await transaction.RollbackAsync();
return (false, null, $"Produkt mit ID {itemDto.ProductId} ist nicht verfügbar.");
}
if (product.StockQuantity < itemDto.Quantity)
{
await transaction.RollbackAsync();
return (false, null, $"Nicht genügend Lagerbestand für {product.Name}. Verfügbar: {product.StockQuantity}.");
}
var orderItem = new OrderItem
{
Id = Guid.NewGuid(),
ProductId = product.Id,
ProductVariantId = itemDto.ProductVariantId,
ProductName = product.Name,
ProductSKU = product.SKU,
Quantity = itemDto.Quantity,
UnitPrice = product.Price,
TotalPrice = product.Price * itemDto.Quantity
};
orderItems.Add(orderItem);
itemsTotal += orderItem.TotalPrice;
product.StockQuantity -= itemDto.Quantity;
_context.Products.Update(product);
}
decimal shippingCost = shippingMethod.BaseCost;
decimal taxAmount = (itemsTotal + shippingCost) * 0.19m; // Annahme: 19% MwSt.
decimal orderTotal = itemsTotal + shippingCost + taxAmount;
var newOrder = new Order
{
Id = Guid.NewGuid(),
OrderNumber = $"WS-{DateTime.UtcNow:yyyyMMdd}-{new Random().Next(1000, 9999)}",
CustomerId = customer.Id, // Verwende die interne Customer-ID
OrderDate = DateTimeOffset.UtcNow,
OrderStatus = OrderStatus.Pending.ToString(),
PaymentStatus = PaymentStatus.Pending.ToString(),
OrderTotal = orderTotal,
ShippingCost = shippingCost,
TaxAmount = taxAmount,
DiscountAmount = 0,
PaymentMethod = paymentMethod.Name,
PaymentMethodId = paymentMethod.Id,
ShippingMethodId = shippingMethod.Id,
BillingAddressId = orderDto.BillingAddressId,
ShippingAddressId = orderDto.ShippingAddressId,
OrderItems = orderItems
};
await _orderRepository.AddAsync(newOrder);
await transaction.CommitAsync();
var createdOrderDto = new OrderDetailDto { Id = newOrder.Id, OrderNumber = newOrder.OrderNumber /* ... weitere Felder mappen ... */ };
return (true, createdOrderDto, null);
}
catch (Exception ex)
{
await transaction.RollbackAsync();
return (false, null, $"Ein unerwarteter Fehler ist aufgetreten: {ex.Message}");
}
}
public async Task<IEnumerable<OrderSummaryDto>> GetMyOrdersAsync(string userId)
{
var customer = await _customerRepository.GetByUserIdAsync(userId);
if (customer == null)
{
return new List<OrderSummaryDto>();
}
var orders = await _context.Orders
.Where(o => o.CustomerId == customer.Id)
.OrderByDescending(o => o.OrderDate)
.ToListAsync();
return orders.Select(o => new OrderSummaryDto
{
Id = o.Id,
OrderNumber = o.OrderNumber,
OrderDate = o.OrderDate,
CustomerName = $"{customer.FirstName} {customer.LastName}",
TotalAmount = o.OrderTotal,
Status = Enum.TryParse<OrderStatus>(o.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending,
PaymentStatus = Enum.TryParse<PaymentStatus>(o.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending
}).ToList();
}
public async Task<OrderDetailDto?> GetMyOrderByIdAsync(Guid orderId, string userId)
{
var customer = await _customerRepository.GetByUserIdAsync(userId);
if (customer == null)
{
return null;
}
var order = await _context.Orders
.Include(o => o.BillingAddress)
.Include(o => o.ShippingAddress)
.Include(o => o.PaymentMethodInfo)
.Include(o => o.OrderItems)
.ThenInclude(oi => oi.Product)
.FirstOrDefaultAsync(o => o.Id == orderId && o.CustomerId == customer.Id);
if (order == null)
{
return null;
}
return new OrderDetailDto
{
Id = order.Id,
OrderNumber = order.OrderNumber,
OrderDate = order.OrderDate,
CustomerId = order.CustomerId,
Status = Enum.TryParse<OrderStatus>(order.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending,
TotalAmount = order.OrderTotal,
ShippingAddress = order.ShippingAddress,
BillingAddress = order.BillingAddress,
PaymentMethod = order.PaymentMethod,
PaymentStatus = Enum.TryParse<PaymentStatus>(order.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending,
ShippingTrackingNumber = order.ShippingTrackingNumber,
ShippedDate = order.ShippedDate,
DeliveredDate = order.DeliveredDate,
OrderItems = order.OrderItems.Select(oi => new OrderItemDto
{
Id = oi.Id,
ProductId = oi.ProductId,
ProductVariantId = oi.ProductVariantId,
ProductName = oi.ProductName,
ProductSKU = oi.ProductSKU,
Quantity = oi.Quantity,
UnitPrice = oi.UnitPrice,
TotalPrice = oi.TotalPrice
}).ToList()
};
}
}
}

View File

@@ -1,14 +1,17 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Domain/Interfaces/IShippingMethodRepository.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Domain.Entities;
namespace Webshop.Domain.Interfaces
{
public interface IShippingMethodRepository
{
// Fügen Sie hier Methodensignaturen hinzu
Task<IEnumerable<ShippingMethod>> GetAllAsync();
Task<ShippingMethod?> GetByIdAsync(Guid id); // << HINZUFÜGEN >>
Task AddAsync(ShippingMethod shippingMethod);
Task UpdateAsync(ShippingMethod shippingMethod);
Task DeleteAsync(Guid id);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,832 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Webshop.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class addCategory : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Categories",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
Slug = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
ParentCategoryId = table.Column<Guid>(type: "uuid", nullable: true),
ImageUrl = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
CreatedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LastModifiedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
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: "Discounts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
DiscountType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
DiscountValue = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
StartDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
EndDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
RequiresCouponCode = table.Column<bool>(type: "boolean", nullable: false),
CouponCode = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
MinimumOrderAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true),
MaximumUsageCount = table.Column<int>(type: "integer", nullable: true),
CurrentUsageCount = table.Column<int>(type: "integer", nullable: false),
Description = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
PaymentGatewayType = table.Column<int>(type: "integer", nullable: false),
Configuration = table.Column<string>(type: "jsonb", nullable: true),
ProcessingFee = table.Column<decimal>(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<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Settings",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Key = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Value = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
Group = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
BaseCost = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
MinimumOrderAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
EstimatedDeliveryTime = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
RequiresTracking = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShippingMethods", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
CreatedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LastActive = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CategoryDiscounts",
columns: table => new
{
CategoryId = table.Column<Guid>(type: "uuid", nullable: false),
DiscountId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CategoryDiscounts", x => new { x.CategoryId, x.DiscountId });
table.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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(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: "Customers",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
AspNetUserId = table.Column<string>(type: "text", nullable: false),
FirstName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
LastName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
DefaultShippingAddressId = table.Column<Guid>(type: "uuid", nullable: true),
DefaultBillingAddressId = table.Column<Guid>(type: "uuid", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Customers", x => x.Id);
table.ForeignKey(
name: "FK_Customers_Users_AspNetUserId",
column: x => x.AspNetUserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "UserClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(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<string>(type: "text", nullable: false),
ProviderKey = table.Column<string>(type: "text", nullable: false),
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
UserId = table.Column<string>(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<string>(type: "text", nullable: false),
RoleId = table.Column<string>(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<string>(type: "text", nullable: false),
LoginProvider = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(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: "Addresses",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CustomerId = table.Column<Guid>(type: "uuid", nullable: true),
AddressType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
Street = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Street2 = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
City = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
State = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
PostalCode = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
Country = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
CompanyName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
FirstName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
LastName = table.Column<string>(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: "Orders",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
OrderNumber = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
CustomerId = table.Column<Guid>(type: "uuid", nullable: true),
GuestEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
GuestPhoneNumber = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
OrderDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
OrderStatus = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
OrderTotal = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
ShippingCost = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
TaxAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
DiscountAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
PaymentStatus = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
PaymentMethod = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
PaymentMethodId = table.Column<Guid>(type: "uuid", nullable: true),
ShippingMethodId = table.Column<Guid>(type: "uuid", nullable: true),
TransactionId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
BillingAddressId = table.Column<Guid>(type: "uuid", nullable: false),
ShippingAddressId = table.Column<Guid>(type: "uuid", nullable: false),
CustomerNotes = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
AdminNotes = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
ContactPerson = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
PhoneNumber = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
AddressId = table.Column<Guid>(type: "uuid", nullable: true),
Notes = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Description = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: true),
ShortDescription = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
SKU = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Price = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
OldPrice = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
IsInStock = table.Column<bool>(type: "boolean", nullable: false),
StockQuantity = table.Column<int>(type: "integer", nullable: false),
Weight = table.Column<decimal>(type: "numeric(18,3)", precision: 18, scale: 3, nullable: true),
Width = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true),
Height = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true),
Length = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: true),
ImageUrl = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
Slug = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
CreatedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LastModifiedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
SupplierId = table.Column<Guid>(type: "uuid", nullable: true),
PurchasePrice = table.Column<decimal>(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<Guid>(type: "uuid", nullable: false),
CategoryId = table.Column<Guid>(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<Guid>(type: "uuid", nullable: false),
DiscountId = table.Column<Guid>(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<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Value = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
SKU = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
PriceAdjustment = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
StockQuantity = table.Column<int>(type: "integer", nullable: false),
ImageUrl = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
IsActive = table.Column<bool>(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<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
CustomerId = table.Column<Guid>(type: "uuid", nullable: true),
Rating = table.Column<int>(type: "integer", nullable: false),
Title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Comment = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
ReviewDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
IsApproved = table.Column<bool>(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<Guid>(type: "uuid", nullable: false),
OrderId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: true),
ProductVariantId = table.Column<Guid>(type: "uuid", nullable: true),
ProductName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
ProductSKU = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Quantity = table.Column<int>(type: "integer", nullable: false),
UnitPrice = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
TotalPrice = table.Column<decimal>(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_Customers_AspNetUserId",
table: "Customers",
column: "AspNetUserId",
unique: true);
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);
}
/// <inheritdoc />
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: "PaymentMethods");
migrationBuilder.DropTable(
name: "ShippingMethods");
migrationBuilder.DropTable(
name: "Products");
migrationBuilder.DropTable(
name: "Suppliers");
migrationBuilder.DropTable(
name: "Addresses");
migrationBuilder.DropTable(
name: "Customers");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@@ -1,11 +1,11 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Infrastructure/Repositories/ShippingMethodRepository.cs
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;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Repositories
{
@@ -18,12 +18,15 @@ namespace Webshop.Infrastructure.Repositories
_context = context;
}
// Fügen Sie hier Repository-Methoden hinzu
// Beispiel:
// public async Task<IEnumerable<T>> GetAllAsync() { return await _context.Set<T>().ToListAsync(); }
// public async Task<T?> GetByIdAsync(Guid id) { return await _context.Set<T>().FindAsync(id); }
// public async Task AddAsync(T entity) { _context.Set<T>().Add(entity); await _context.SaveChangesAsync(); }
// public async Task UpdateAsync(T entity) { _context.Set<T>().Update(entity); await _context.SaveChangesAsync(); }
// public async Task DeleteAsync(Guid id) { var entity = await _context.Set<T>().FindAsync(id); if (entity != null) { _context.Set<T>().Remove(entity); await _context.SaveChangesAsync(); } }
public async Task<IEnumerable<ShippingMethod>> GetAllAsync() => await _context.ShippingMethods.ToListAsync();
public async Task<ShippingMethod?> GetByIdAsync(Guid id) // << HINZUFÜGEN >>
{
return await _context.ShippingMethods.FindAsync(id);
}
public async Task AddAsync(ShippingMethod shippingMethod) { _context.ShippingMethods.Add(shippingMethod); await _context.SaveChangesAsync(); }
public async Task UpdateAsync(ShippingMethod shippingMethod) { _context.ShippingMethods.Update(shippingMethod); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(Guid id) { var entity = await _context.ShippingMethods.FindAsync(id); if (entity != null) { _context.ShippingMethods.Remove(entity); await _context.SaveChangesAsync(); } }
}
}