49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using FurnitureAssemblyContracts.AdapterContracts;
|
|
using FurnitureAssemblyContracts.BindingModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace FurnitureAssemblyWebApi.Controllers;
|
|
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
public class ComponentsController(IComponentAdapter adapter) : ControllerBase
|
|
{
|
|
private readonly IComponentAdapter _adapter = adapter;
|
|
|
|
[HttpGet]
|
|
public IActionResult GetAllComponents()
|
|
{
|
|
return _adapter.GetAllComponents().GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpGet("{data}")]
|
|
public IActionResult GetComponentByData(string data)
|
|
{
|
|
return _adapter.GetComponentByData(data).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Register([FromBody] ComponentBindingModel componentBindingModel)
|
|
{
|
|
return _adapter.InsertComponent(componentBindingModel).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPut]
|
|
public IActionResult ChangeInfo([FromBody] ComponentBindingModel componentBindingModel)
|
|
{
|
|
return _adapter.UpdateComponent(componentBindingModel).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public IActionResult DeleteComponent(string id)
|
|
{
|
|
if (string.IsNullOrEmpty(id))
|
|
return BadRequest("Id is null or empty");
|
|
|
|
return _adapter.DeleteComponent(id).GetResponse(Request, Response);
|
|
}
|
|
}
|