// src/Webshop.Api/Controllers/Admin/FileUploadController.cs using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; using Webshop.Application; using Webshop.Application.DTOs; using Webshop.Application.Services; // Namespace für den neuen Service namespace Webshop.Api.Controllers.Admin { [ApiController] [Route("api/v1/admin/[controller]")] [Authorize(Roles = "Admin")] public class FileUploadController : ControllerBase { private readonly IFileUploadService _fileUploadService; public FileUploadController(IFileUploadService fileUploadService) { _fileUploadService = fileUploadService; } [HttpPost("upload")] [ProducesResponseType(typeof(FileUploadResultDto), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task UploadImage(IFormFile file) { var result = await _fileUploadService.UploadFileAsync(file); return result.Type switch { ServiceResultType.Success => Ok(result.Value), ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }), _ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." }) }; } } }