// src/Webshop.Api/Controllers/Admin/AdminShippingMethodsController.cs using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Threading.Tasks; using Webshop.Application.DTOs.Shipping; using Webshop.Application.Services.Admin; namespace Webshop.Api.Controllers.Admin { [ApiController] [Route("api/v1/admin/[controller]")] [Authorize(Roles = "Admin")] public class AdminShippingMethodsController : ControllerBase { private readonly IAdminShippingMethodService _shippingMethodService; public AdminShippingMethodsController(IAdminShippingMethodService shippingMethodService) { _shippingMethodService = shippingMethodService; } [HttpPost] public async Task> CreateShippingMethod([FromBody] ShippingMethodDto shippingMethodDto) { var createdMethod = await _shippingMethodService.CreateAsync(shippingMethodDto); return CreatedAtAction(nameof(GetShippingMethodById), new { id = createdMethod.Id }, createdMethod); } [HttpGet("{id}")] public async Task> GetShippingMethodById(Guid id) { var method = await _shippingMethodService.GetByIdAsync(id); if (method == null) return NotFound(); return Ok(method); } [HttpGet] public async Task>> GetAllShippingMethods() { var methods = await _shippingMethodService.GetAllAsync(); return Ok(methods); } [HttpPut("{id}")] public async Task 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 DeleteShippingMethod(Guid id) { var success = await _shippingMethodService.DeleteAsync(id); if (!success) return NotFound(); return NoContent(); } } }