bild update
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminProductsController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http; // F<>r IFormFile
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Products;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
[ApiController]
|
||||
@@ -38,20 +37,29 @@ namespace Webshop.Api.Controllers.Admin
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<AdminProductDto>> CreateAdminProduct([FromBody] CreateAdminProductDto productDto) // << ZUR<55>CK ZU [FromBody] >>
|
||||
[Consumes("multipart/form-data")]
|
||||
public async Task<ActionResult<AdminProductDto>> CreateAdminProduct([FromForm] CreateAdminProductDto productDto)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var createdProduct = await _adminProductService.CreateAdminProductAsync(productDto);
|
||||
if (createdProduct == null) return BadRequest("Produkt konnte nicht erstellt werden.");
|
||||
|
||||
return CreatedAtAction(nameof(GetAdminProduct), new { id = createdProduct.Id }, createdProduct);
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateAdminProduct(Guid id, [FromBody] UpdateAdminProductDto productDto) // << ZUR<55>CK ZU [FromBody] >>
|
||||
[Consumes("multipart/form-data")]
|
||||
public async Task<IActionResult> UpdateAdminProduct(Guid id, [FromForm] UpdateAdminProductDto productDto)
|
||||
{
|
||||
if (id != productDto.Id) return BadRequest();
|
||||
if (id != productDto.Id) return BadRequest("ID in URL und Body stimmen nicht <20>berein.");
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var success = await _adminProductService.UpdateAdminProductAsync(productDto);
|
||||
|
||||
if (!success) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user