shipping method weight

This commit is contained in:
Tizian.Breuch
2025-11-26 09:56:05 +01:00
parent e42c4d6741
commit efc70084c3
7 changed files with 1472 additions and 41 deletions

View File

@@ -211,7 +211,7 @@ builder.Services.AddSwaggerGen(c =>
c.SchemaFilter<AddExampleSchemaFilter>(); c.SchemaFilter<AddExampleSchemaFilter>();
c.OperationFilter<AuthorizeOperationFilter>(); c.OperationFilter<AuthorizeOperationFilter>();
c.OperationFilter<LoginExampleOperationFilter>(); c.OperationFilter<LoginExampleOperationFilter>();
c.OperationFilter<PaymentMethodExampleOperationFilter>(); //c.OperationFilter<PaymentMethodExampleOperationFilter>();
c.OperationFilter<SupplierExampleOperationFilter>(); c.OperationFilter<SupplierExampleOperationFilter>();
c.OperationFilter<ShippingMethodExampleOperationFilter>(); c.OperationFilter<ShippingMethodExampleOperationFilter>();
c.OperationFilter<AdminProductExampleOperationFilter>(); c.OperationFilter<AdminProductExampleOperationFilter>();

View File

@@ -1,8 +1,4 @@
// Auto-generiert von CreateWebshopFiles.ps1
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs.Shipping namespace Webshop.Application.DTOs.Shipping
{ {
@@ -15,5 +11,9 @@ namespace Webshop.Application.DTOs.Shipping
public bool IsActive { get; set; } public bool IsActive { get; set; }
public int MinDeliveryDays { get; set; } public int MinDeliveryDays { get; set; }
public int MaxDeliveryDays { get; set; } public int MaxDeliveryDays { get; set; }
// NEU: Gewichtsgrenzen f<>r diese Methode
public decimal MinWeight { get; set; }
public decimal MaxWeight { get; set; }
} }
} }

View File

@@ -1,14 +1,13 @@
// src/Webshop.Application/Services/Admin/AdminShippingMethodService.cs using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; // Hinzufügen für .AnyAsync using Microsoft.EntityFrameworkCore;
using Webshop.Application; using Webshop.Application;
using Webshop.Application.DTOs.Shipping; using Webshop.Application.DTOs.Shipping;
using Webshop.Domain.Entities; using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces; using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data; // Hinzufügen für DbContext using Webshop.Infrastructure.Data;
namespace Webshop.Application.Services.Admin namespace Webshop.Application.Services.Admin
{ {
@@ -55,14 +54,15 @@ namespace Webshop.Application.Services.Admin
Description = shippingMethodDto.Description, Description = shippingMethodDto.Description,
BaseCost = shippingMethodDto.Cost, BaseCost = shippingMethodDto.Cost,
IsActive = shippingMethodDto.IsActive, IsActive = shippingMethodDto.IsActive,
// +++ KORREKTUR +++
MinDeliveryDays = shippingMethodDto.MinDeliveryDays, MinDeliveryDays = shippingMethodDto.MinDeliveryDays,
MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays,
// NEU: Gewichte mappen
MinWeight = shippingMethodDto.MinWeight,
MaxWeight = shippingMethodDto.MaxWeight
}; };
await _shippingMethodRepository.AddAsync(newMethod); await _shippingMethodRepository.AddAsync(newMethod);
// Verwende MapToDto, um eine konsistente Antwort zu gewährleisten
return ServiceResult.Ok(MapToDto(newMethod)); return ServiceResult.Ok(MapToDto(newMethod));
} }
@@ -75,6 +75,7 @@ namespace Webshop.Application.Services.Admin
} }
var allMethods = await _shippingMethodRepository.GetAllAsync(); var allMethods = await _shippingMethodRepository.GetAllAsync();
// Prüfen, ob der Name von einer ANDEREN Methode bereits verwendet wird
if (allMethods.Any(sm => sm.Name.Equals(shippingMethodDto.Name, StringComparison.OrdinalIgnoreCase) && sm.Id != shippingMethodDto.Id)) if (allMethods.Any(sm => sm.Name.Equals(shippingMethodDto.Name, StringComparison.OrdinalIgnoreCase) && sm.Id != shippingMethodDto.Id))
{ {
return ServiceResult.Fail(ServiceResultType.Conflict, $"Eine andere Versandmethode mit dem Namen '{shippingMethodDto.Name}' existiert bereits."); return ServiceResult.Fail(ServiceResultType.Conflict, $"Eine andere Versandmethode mit dem Namen '{shippingMethodDto.Name}' existiert bereits.");
@@ -84,9 +85,11 @@ namespace Webshop.Application.Services.Admin
existingMethod.Description = shippingMethodDto.Description; existingMethod.Description = shippingMethodDto.Description;
existingMethod.BaseCost = shippingMethodDto.Cost; existingMethod.BaseCost = shippingMethodDto.Cost;
existingMethod.IsActive = shippingMethodDto.IsActive; existingMethod.IsActive = shippingMethodDto.IsActive;
// +++ KORREKTUR +++
existingMethod.MinDeliveryDays = shippingMethodDto.MinDeliveryDays; existingMethod.MinDeliveryDays = shippingMethodDto.MinDeliveryDays;
existingMethod.MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays; existingMethod.MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays;
// NEU: Gewichte aktualisieren
existingMethod.MinWeight = shippingMethodDto.MinWeight;
existingMethod.MaxWeight = shippingMethodDto.MaxWeight;
await _shippingMethodRepository.UpdateAsync(existingMethod); await _shippingMethodRepository.UpdateAsync(existingMethod);
return ServiceResult.Ok(); return ServiceResult.Ok();
@@ -119,9 +122,11 @@ namespace Webshop.Application.Services.Admin
Description = sm.Description, Description = sm.Description,
Cost = sm.BaseCost, Cost = sm.BaseCost,
IsActive = sm.IsActive, IsActive = sm.IsActive,
// +++ KORREKTUR +++
MinDeliveryDays = sm.MinDeliveryDays, MinDeliveryDays = sm.MinDeliveryDays,
MaxDeliveryDays = sm.MaxDeliveryDays MaxDeliveryDays = sm.MaxDeliveryDays,
// NEU: Gewichte ins DTO übertragen
MinWeight = sm.MinWeight,
MaxWeight = sm.MaxWeight
}; };
} }
} }

View File

@@ -1,38 +1,46 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Webshop.Domain.Entities; namespace Webshop.Domain.Entities
/// <summary>
/// Konfigurierbare Versandoptionen für den Checkout.
/// </summary>
public class ShippingMethod
{ {
[Key] /// <summary>
public Guid Id { get; set; } /// Konfigurierbare Versandoptionen für den Checkout.
/// </summary>
public class ShippingMethod
{
[Key]
public Guid Id { get; set; }
[Required] [Required]
[MaxLength(100)] [MaxLength(100)]
public string Name { get; set; } public string Name { get; set; } = string.Empty;
[MaxLength(500)] [MaxLength(500)]
public string? Description { get; set; } public string? Description { get; set; }
// Precision wird via Fluent API konfiguriert // Grundkosten der Versandmethode
[Required] [Required]
public decimal BaseCost { get; set; } public decimal BaseCost { get; set; }
public decimal? MinimumOrderAmount { get; set; } // Optional: Mindestbestellwert (für kostenlosen Versand etc.)
public decimal? MinimumOrderAmount { get; set; }
[Required] [Required]
public bool IsActive { get; set; } public bool IsActive { get; set; }
[MaxLength(100)] [MaxLength(100)]
public string? EstimatedDeliveryTime { get; set; } public string? EstimatedDeliveryTime { get; set; }
[Required] [Required]
public bool RequiresTracking { get; set; } public bool RequiresTracking { get; set; }
public int MinDeliveryDays { get; set; } public int MinDeliveryDays { get; set; }
public int MaxDeliveryDays { get; set; } public int MaxDeliveryDays { get; set; }
// NEU: Gewichtsbasierte Berechnung
// Einheit: kg (oder die Standardeinheit deines Shops)
public decimal MinWeight { get; set; } = 0;
public decimal MaxWeight { get; set; } = 0;
}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Webshop.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class shippingmethodWeight : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "MaxWeight",
table: "ShippingMethods",
type: "numeric",
nullable: false,
defaultValue: 0m);
migrationBuilder.AddColumn<decimal>(
name: "MinWeight",
table: "ShippingMethods",
type: "numeric",
nullable: false,
defaultValue: 0m);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "MaxWeight",
table: "ShippingMethods");
migrationBuilder.DropColumn(
name: "MinWeight",
table: "ShippingMethods");
}
}
}

View File

@@ -855,9 +855,15 @@ namespace Webshop.Infrastructure.Migrations
b.Property<int>("MaxDeliveryDays") b.Property<int>("MaxDeliveryDays")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<decimal>("MaxWeight")
.HasColumnType("numeric");
b.Property<int>("MinDeliveryDays") b.Property<int>("MinDeliveryDays")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<decimal>("MinWeight")
.HasColumnType("numeric");
b.Property<decimal?>("MinimumOrderAmount") b.Property<decimal?>("MinimumOrderAmount")
.HasPrecision(18, 2) .HasPrecision(18, 2)
.HasColumnType("numeric(18,2)"); .HasColumnType("numeric(18,2)");