-
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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<ActionResult<List<BillOfMaterialsDto>>> GetAll()
|
||||
{
|
||||
return Ok(await _productionService.GetBillOfMaterialsAsync());
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<BillOfMaterialsDto>> GetById(int id)
|
||||
{
|
||||
var bom = await _productionService.GetBillOfMaterialsByIdAsync(id);
|
||||
if (bom == null) return NotFound();
|
||||
return Ok(bom);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<BillOfMaterialsDto>> Create(CreateBillOfMaterialsDto dto)
|
||||
{
|
||||
var bom = await _productionService.CreateBillOfMaterialsAsync(dto);
|
||||
return CreatedAtAction(nameof(GetById), new { id = bom.Id }, bom);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ActionResult<BillOfMaterialsDto>> 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<ActionResult> Delete(int id)
|
||||
{
|
||||
await _productionService.DeleteBillOfMaterialsAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user