test
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 26s

This commit is contained in:
Tizian.Breuch
2025-11-07 14:15:35 +01:00
parent 4ef8047460
commit dae7d1d979
4 changed files with 10 additions and 9 deletions

View File

@@ -78,16 +78,11 @@ namespace Webshop.Api.Controllers.Admin
public async Task<IActionResult> 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.
// DEINE PERFEKTE L<>SUNG: URL-ID erzwingen
// ==============================================================================
if (id != productDto.Id)
{
// 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 <20>berein." });
}
productDto.Id = id;
// Ab hier l<>uft alles wie gehabt. Der Service erh<72>lt ein DTO mit der verifizierten ID.
// Jetzt den Service mit dem garantiert korrekten DTO aufrufen.
var result = await _adminProductService.UpdateAdminProductAsync(productDto);
return result.Type switch

View File

@@ -122,7 +122,8 @@ namespace Webshop.Application.Services.Admin
if (productDto.AdditionalImageFiles != null && productDto.AdditionalImageFiles.Any()) { int displayOrder = (existingProduct.Images.Any() ? existingProduct.Images.Max(i => i.DisplayOrder) : 0) + 1; foreach (var file in productDto.AdditionalImageFiles) { await using var stream = file.OpenReadStream(); var url = await _fileStorageService.SaveFileAsync(stream, file.FileName, file.ContentType); existingProduct.Images.Add(new ProductImage { Url = url, IsMainImage = false, DisplayOrder = displayOrder++ }); } }
existingProduct.Name = productDto.Name; existingProduct.Description = productDto.Description; existingProduct.SKU = productDto.SKU; existingProduct.Price = productDto.Price; existingProduct.IsActive = productDto.IsActive; existingProduct.StockQuantity = productDto.StockQuantity; existingProduct.Slug = productDto.Slug; existingProduct.Weight = productDto.Weight; existingProduct.OldPrice = productDto.OldPrice; existingProduct.SupplierId = productDto.SupplierId; existingProduct.PurchasePrice = productDto.PurchasePrice; existingProduct.LastModifiedDate = DateTimeOffset.UtcNow; existingProduct.IsFeatured = productDto.IsFeatured; existingProduct.FeaturedDisplayOrder = productDto.FeaturedDisplayOrder;
existingProduct.Productcategories.Clear(); if (productDto.CategorieIds != null) { foreach (var categorieId in productDto.CategorieIds) { existingProduct.Productcategories.Add(new Productcategorie { categorieId = categorieId }); } }
await _productRepository.UpdateProductAsync(existingProduct); return ServiceResult.Ok();
await _productRepository.SaveChangesAsync();
return ServiceResult.Ok();
}
public async Task<ServiceResult> DeleteAdminProductAsync(Guid id)

View File

@@ -13,6 +13,7 @@ namespace Webshop.Domain.Interfaces
Task<Product?> GetBySlugAsync(string slug);
Task AddProductAsync(Product product);
Task UpdateProductAsync(Product product);
Task SaveChangesAsync();
Task DeleteProductAsync(Guid id);
}
}

View File

@@ -55,5 +55,9 @@ namespace Webshop.Infrastructure.Repositories
await _context.SaveChangesAsync();
}
}
public async Task SaveChangesAsync()
{
await _context.SaveChangesAsync();
}
}
}