Merge pull request 'shipping method weight' (#1) from Feature_Shipping_Method_Add_Weight into develop
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 1m3s
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 1m3s
Reviewed-on: #1
This commit is contained in:
@@ -211,7 +211,7 @@ builder.Services.AddSwaggerGen(c =>
|
||||
c.SchemaFilter<AddExampleSchemaFilter>();
|
||||
c.OperationFilter<AuthorizeOperationFilter>();
|
||||
c.OperationFilter<LoginExampleOperationFilter>();
|
||||
c.OperationFilter<PaymentMethodExampleOperationFilter>();
|
||||
//c.OperationFilter<PaymentMethodExampleOperationFilter>();
|
||||
c.OperationFilter<SupplierExampleOperationFilter>();
|
||||
c.OperationFilter<ShippingMethodExampleOperationFilter>();
|
||||
c.OperationFilter<AdminProductExampleOperationFilter>();
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Webshop.Application.DTOs.Shipping
|
||||
{
|
||||
@@ -15,5 +11,9 @@ namespace Webshop.Application.DTOs.Shipping
|
||||
public bool IsActive { get; set; }
|
||||
public int MinDeliveryDays { get; set; }
|
||||
public int MaxDeliveryDays { get; set; }
|
||||
|
||||
// NEU: Gewichtsgrenzen f<>r diese Methode
|
||||
public decimal MinWeight { get; set; }
|
||||
public decimal MaxWeight { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
// src/Webshop.Application/Services/Admin/AdminShippingMethodService.cs
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore; // Hinzufügen für .AnyAsync
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Shipping;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
using Webshop.Infrastructure.Data; // Hinzufügen für DbContext
|
||||
using Webshop.Infrastructure.Data;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
@@ -55,14 +54,15 @@ namespace Webshop.Application.Services.Admin
|
||||
Description = shippingMethodDto.Description,
|
||||
BaseCost = shippingMethodDto.Cost,
|
||||
IsActive = shippingMethodDto.IsActive,
|
||||
// +++ KORREKTUR +++
|
||||
MinDeliveryDays = shippingMethodDto.MinDeliveryDays,
|
||||
MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays
|
||||
MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays,
|
||||
// NEU: Gewichte mappen
|
||||
MinWeight = shippingMethodDto.MinWeight,
|
||||
MaxWeight = shippingMethodDto.MaxWeight
|
||||
};
|
||||
|
||||
await _shippingMethodRepository.AddAsync(newMethod);
|
||||
|
||||
// Verwende MapToDto, um eine konsistente Antwort zu gewährleisten
|
||||
return ServiceResult.Ok(MapToDto(newMethod));
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace Webshop.Application.Services.Admin
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
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.BaseCost = shippingMethodDto.Cost;
|
||||
existingMethod.IsActive = shippingMethodDto.IsActive;
|
||||
// +++ KORREKTUR +++
|
||||
existingMethod.MinDeliveryDays = shippingMethodDto.MinDeliveryDays;
|
||||
existingMethod.MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays;
|
||||
// NEU: Gewichte aktualisieren
|
||||
existingMethod.MinWeight = shippingMethodDto.MinWeight;
|
||||
existingMethod.MaxWeight = shippingMethodDto.MaxWeight;
|
||||
|
||||
await _shippingMethodRepository.UpdateAsync(existingMethod);
|
||||
return ServiceResult.Ok();
|
||||
@@ -119,9 +122,11 @@ namespace Webshop.Application.Services.Admin
|
||||
Description = sm.Description,
|
||||
Cost = sm.BaseCost,
|
||||
IsActive = sm.IsActive,
|
||||
// +++ KORREKTUR +++
|
||||
MinDeliveryDays = sm.MinDeliveryDays,
|
||||
MaxDeliveryDays = sm.MaxDeliveryDays
|
||||
MaxDeliveryDays = sm.MaxDeliveryDays,
|
||||
// NEU: Gewichte ins DTO übertragen
|
||||
MinWeight = sm.MinWeight,
|
||||
MaxWeight = sm.MaxWeight
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,46 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Webshop.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Konfigurierbare Versandoptionen für den Checkout.
|
||||
/// </summary>
|
||||
public class ShippingMethod
|
||||
namespace Webshop.Domain.Entities
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
/// <summary>
|
||||
/// Konfigurierbare Versandoptionen für den Checkout.
|
||||
/// </summary>
|
||||
public class ShippingMethod
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
// Precision wird via Fluent API konfiguriert
|
||||
[Required]
|
||||
public decimal BaseCost { get; set; }
|
||||
// Grundkosten der Versandmethode
|
||||
[Required]
|
||||
public decimal BaseCost { get; set; }
|
||||
|
||||
public decimal? MinimumOrderAmount { get; set; }
|
||||
// Optional: Mindestbestellwert (für kostenlosen Versand etc.)
|
||||
public decimal? MinimumOrderAmount { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool IsActive { get; set; }
|
||||
[Required]
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? EstimatedDeliveryTime { get; set; }
|
||||
[MaxLength(100)]
|
||||
public string? EstimatedDeliveryTime { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool RequiresTracking { get; set; }
|
||||
[Required]
|
||||
public bool RequiresTracking { get; set; }
|
||||
|
||||
public int MinDeliveryDays { get; set; }
|
||||
public int MaxDeliveryDays { get; set; }
|
||||
public int MinDeliveryDays { 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;
|
||||
}
|
||||
}
|
||||
1372
Webshop.Infrastructure/Migrations/20251126085553_shippingmethodWeight.Designer.cs
generated
Normal file
1372
Webshop.Infrastructure/Migrations/20251126085553_shippingmethodWeight.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -855,9 +855,15 @@ namespace Webshop.Infrastructure.Migrations
|
||||
b.Property<int>("MaxDeliveryDays")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<decimal>("MaxWeight")
|
||||
.HasColumnType("numeric");
|
||||
|
||||
b.Property<int>("MinDeliveryDays")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<decimal>("MinWeight")
|
||||
.HasColumnType("numeric");
|
||||
|
||||
b.Property<decimal?>("MinimumOrderAmount")
|
||||
.HasPrecision(18, 2)
|
||||
.HasColumnType("numeric(18,2)");
|
||||
|
||||
Reference in New Issue
Block a user