adress und migration

This commit is contained in:
Tizian.Breuch
2025-08-01 13:42:11 +02:00
parent 66709d3dbe
commit 2329cd1ac8
6 changed files with 51 additions and 28 deletions

View File

@@ -24,7 +24,6 @@ namespace Webshop.Api.Controllers.Admin
[HttpPost] [HttpPost]
public async Task<ActionResult<ShippingMethodDto>> CreateShippingMethod([FromBody] ShippingMethodDto shippingMethodDto) public async Task<ActionResult<ShippingMethodDto>> CreateShippingMethod([FromBody] ShippingMethodDto shippingMethodDto)
{ {
// Implementierung im AdminShippingMethodService
var createdMethod = await _shippingMethodService.CreateAsync(shippingMethodDto); var createdMethod = await _shippingMethodService.CreateAsync(shippingMethodDto);
return CreatedAtAction(nameof(GetShippingMethodById), new { id = createdMethod.Id }, createdMethod); return CreatedAtAction(nameof(GetShippingMethodById), new { id = createdMethod.Id }, createdMethod);
} }
@@ -32,8 +31,33 @@ namespace Webshop.Api.Controllers.Admin
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<ActionResult<ShippingMethodDto>> GetShippingMethodById(Guid id) public async Task<ActionResult<ShippingMethodDto>> GetShippingMethodById(Guid id)
{ {
// ... var method = await _shippingMethodService.GetByIdAsync(id);
return Ok(); if (method == null) return NotFound();
return Ok(method);
}
[HttpGet]
public async Task<ActionResult<IEnumerable<ShippingMethodDto>>> GetAllShippingMethods()
{
var methods = await _shippingMethodService.GetAllAsync();
return Ok(methods);
}
[HttpPut("{id}")]
public async Task<IActionResult> UpdateShippingMethod(Guid id, [FromBody] ShippingMethodDto shippingMethodDto)
{
if (id != shippingMethodDto.Id) return BadRequest();
var success = await _shippingMethodService.UpdateAsync(shippingMethodDto);
if (!success) return NotFound();
return NoContent();
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteShippingMethod(Guid id)
{
var success = await _shippingMethodService.DeleteAsync(id);
if (!success) return NotFound();
return NoContent();
} }
} }
} }

View File

@@ -38,7 +38,6 @@ namespace Webshop.Api.Controllers.Customer
if (createdAddress == null) return BadRequest(new { Message = errorMessage }); if (createdAddress == null) return BadRequest(new { Message = errorMessage });
// Annahme: Es gibt eine GetMyAddressById-Methode
return CreatedAtAction(nameof(GetMyAddresses), new { id = createdAddress.Id }, createdAddress); return CreatedAtAction(nameof(GetMyAddresses), new { id = createdAddress.Id }, createdAddress);
} }
} }

View File

@@ -12,8 +12,8 @@ using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Migrations namespace Webshop.Infrastructure.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20250801073120_AddHouseNumberAndTypeToAddress")] [Migration("20250801114205_FinalSchema")]
partial class AddHouseNumberAndTypeToAddress partial class FinalSchema
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -1224,10 +1224,10 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Product", b => modelBuilder.Entity("Webshop.Domain.Entities.Product", b =>
{ {
b.Navigation("Productcategorys");
b.Navigation("ProductDiscounts"); b.Navigation("ProductDiscounts");
b.Navigation("Productcategorys");
b.Navigation("Reviews"); b.Navigation("Reviews");
b.Navigation("Variants"); b.Navigation("Variants");

View File

@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Webshop.Infrastructure.Migrations namespace Webshop.Infrastructure.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class AddHouseNumberAndTypeToAddress : Migration public partial class FinalSchema : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@@ -163,18 +163,18 @@ namespace Webshop.Infrastructure.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_CategoryDiscounts", x => new { x.CategoryId, x.DiscountId }); table.PrimaryKey("PK_CategoryDiscounts", x => new { x.CategoryId, x.DiscountId });
table.ForeignKey(
name: "FK_CategoryDiscounts_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_CategoryDiscounts_Discounts_DiscountId", name: "FK_CategoryDiscounts_Discounts_DiscountId",
column: x => x.DiscountId, column: x => x.DiscountId,
principalTable: "Discounts", principalTable: "Discounts",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CategoryDiscounts_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@@ -459,18 +459,18 @@ namespace Webshop.Infrastructure.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Productcategorys", x => new { x.ProductId, x.CategoryId }); table.PrimaryKey("PK_Productcategorys", x => new { x.ProductId, x.CategoryId });
table.ForeignKey(
name: "FK_Productcategorys_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Productcategorys_Products_ProductId", name: "FK_Productcategorys_Products_ProductId",
column: x => x.ProductId, column: x => x.ProductId,
principalTable: "Products", principalTable: "Products",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Productcategorys_categorys_CategoryId",
column: x => x.CategoryId,
principalTable: "categorys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@@ -593,6 +593,11 @@ namespace Webshop.Infrastructure.Migrations
table: "Addresses", table: "Addresses",
column: "CustomerId"); column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_CategoryDiscounts_DiscountId",
table: "CategoryDiscounts",
column: "DiscountId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_categorys_ParentCategoryId", name: "IX_categorys_ParentCategoryId",
table: "categorys", table: "categorys",
@@ -604,11 +609,6 @@ namespace Webshop.Infrastructure.Migrations
column: "Slug", column: "Slug",
unique: true); unique: true);
migrationBuilder.CreateIndex(
name: "IX_CategoryDiscounts_DiscountId",
table: "CategoryDiscounts",
column: "DiscountId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Customers_AspNetUserId", name: "IX_Customers_AspNetUserId",
table: "Customers", table: "Customers",

View File

@@ -1221,10 +1221,10 @@ namespace Webshop.Infrastructure.Migrations
modelBuilder.Entity("Webshop.Domain.Entities.Product", b => modelBuilder.Entity("Webshop.Domain.Entities.Product", b =>
{ {
b.Navigation("Productcategorys");
b.Navigation("ProductDiscounts"); b.Navigation("ProductDiscounts");
b.Navigation("Productcategorys");
b.Navigation("Reviews"); b.Navigation("Reviews");
b.Navigation("Variants"); b.Navigation("Variants");