From 4ef804746031b6d46316e91699972d27d9ef78b5 Mon Sep 17 00:00:00 2001 From: "Tizian.Breuch" Date: Fri, 7 Nov 2025 14:10:00 +0100 Subject: [PATCH] trst --- .../Controllers/Admin/AdminProductsController.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Webshop.Api/Controllers/Admin/AdminProductsController.cs b/Webshop.Api/Controllers/Admin/AdminProductsController.cs index 1cd8b5e..c2375ee 100644 --- a/Webshop.Api/Controllers/Admin/AdminProductsController.cs +++ b/Webshop.Api/Controllers/Admin/AdminProductsController.cs @@ -77,15 +77,17 @@ namespace Webshop.Api.Controllers.Admin [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)] public async Task UpdateAdminProduct(Guid id, [FromForm] UpdateAdminProductDto productDto) { + // ============================================================================== + // DIES IST DIE ENTSCHEIDENDE KORREKTUR + // Wir stellen sicher, dass die ID aus der URL die ID ist, mit der wir arbeiten. + // ============================================================================== if (id != productDto.Id) { - return BadRequest(new { Message = "ID in der URL und im Body stimmen nicht überein." }); - } - if (!ModelState.IsValid) - { - return BadRequest(ModelState); + // Wenn Frontend und URL sich nicht einig sind, ist die Anfrage fehlerhaft. + return BadRequest(new { Message = "Die ID in der URL stimmt nicht mit der ID im Formular überein." }); } + // Ab hier läuft alles wie gehabt. Der Service erhält ein DTO mit der verifizierten ID. var result = await _adminProductService.UpdateAdminProductAsync(productDto); return result.Type switch @@ -93,8 +95,7 @@ namespace Webshop.Api.Controllers.Admin ServiceResultType.Success => NoContent(), ServiceResultType.NotFound => NotFound(new { Message = result.ErrorMessage }), ServiceResultType.Conflict => Conflict(new { Message = result.ErrorMessage }), - ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }), - _ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." }) + _ => BadRequest(new { Message = result.ErrorMessage ?? "Ein Fehler ist aufgetreten." }) }; }