using Apollinare.API.Modules.Production.Dtos; using Apollinare.API.Modules.Production.Services; using Microsoft.AspNetCore.Mvc; namespace Apollinare.API.Modules.Production.Controllers; [ApiController] [Route("api/production/bom")] public class BillOfMaterialsController : ControllerBase { private readonly IProductionService _productionService; public BillOfMaterialsController(IProductionService productionService) { _productionService = productionService; } [HttpGet] public async Task>> GetAll() { return Ok(await _productionService.GetBillOfMaterialsAsync()); } [HttpGet("{id}")] public async Task> GetById(int id) { var bom = await _productionService.GetBillOfMaterialsByIdAsync(id); if (bom == null) return NotFound(); return Ok(bom); } [HttpPost] public async Task> Create(CreateBillOfMaterialsDto dto) { var bom = await _productionService.CreateBillOfMaterialsAsync(dto); return CreatedAtAction(nameof(GetById), new { id = bom.Id }, bom); } [HttpPut("{id}")] public async Task> Update(int id, UpdateBillOfMaterialsDto dto) { try { var bom = await _productionService.UpdateBillOfMaterialsAsync(id, dto); return Ok(bom); } catch (KeyNotFoundException) { return NotFound(); } } [HttpDelete("{id}")] public async Task Delete(int id) { await _productionService.DeleteBillOfMaterialsAsync(id); return NoContent(); } }