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.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>();
|
||||||
|
|||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Webshop.Domain.Entities;
|
namespace Webshop.Domain.Entities
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Konfigurierbare Versandoptionen für den Checkout.
|
/// Konfigurierbare Versandoptionen für den Checkout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -13,15 +13,16 @@ public class ShippingMethod
|
|||||||
|
|
||||||
[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; }
|
||||||
|
|
||||||
|
// Optional: Mindestbestellwert (für kostenlosen Versand etc.)
|
||||||
public decimal? MinimumOrderAmount { get; set; }
|
public decimal? MinimumOrderAmount { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
@@ -35,4 +36,11 @@ public class ShippingMethod
|
|||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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")
|
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)");
|
||||||
|
|||||||
Reference in New Issue
Block a user