using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using LittleShop.DTOs; using LittleShop.Services; namespace LittleShop.Controllers; [ApiController] [Route("api/[controller]")] [Authorize(AuthenticationSchemes = "Bearer")] public class ProductMultiBuysController : ControllerBase { private readonly IProductService _productService; public ProductMultiBuysController(IProductService productService) { _productService = productService; } [HttpGet("product/{productId}")] public async Task>> GetProductMultiBuys(Guid productId) { var multiBuys = await _productService.GetProductMultiBuysAsync(productId); return Ok(multiBuys); } [HttpGet("{id}")] public async Task> GetProductMultiBuy(Guid id) { var multiBuy = await _productService.GetProductMultiBuyByIdAsync(id); if (multiBuy == null) return NotFound(); return Ok(multiBuy); } [HttpPost] [Authorize(Roles = "Admin")] public async Task> CreateProductMultiBuy(CreateProductMultiBuyDto createMultiBuyDto) { try { var multiBuy = await _productService.CreateProductMultiBuyAsync(createMultiBuyDto); return CreatedAtAction(nameof(GetProductMultiBuy), new { id = multiBuy.Id }, multiBuy); } catch (ArgumentException ex) { return BadRequest(ex.Message); } } [HttpPut("{id}")] [Authorize(Roles = "Admin")] public async Task UpdateProductMultiBuy(Guid id, UpdateProductMultiBuyDto updateMultiBuyDto) { try { await _productService.UpdateProductMultiBuyAsync(id, updateMultiBuyDto); return NoContent(); } catch (ArgumentException ex) { return BadRequest(ex.Message); } } [HttpDelete("{id}")] [Authorize(Roles = "Admin")] public async Task DeleteProductMultiBuy(Guid id) { try { await _productService.DeleteProductMultiBuyAsync(id); return NoContent(); } catch (ArgumentException ex) { return BadRequest(ex.Message); } } }