forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using MagicCarpetContracts.AdapterContracts;
|
|
using MagicCarpetContracts.BindingModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace MagicCarpetWebApi.Controllers;
|
|
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
public class AgencyController(IAgencyAdapter adapter) : ControllerBase
|
|
{
|
|
private readonly IAgencyAdapter _adapter = adapter;
|
|
|
|
[HttpGet]
|
|
public IActionResult GetAll()
|
|
{
|
|
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] AgencyBindingModel agencyBindingModel)
|
|
{
|
|
return _adapter.InsertComponent(agencyBindingModel).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPut]
|
|
public IActionResult ChangeInfo([FromBody] AgencyBindingModel agencyBindingModel)
|
|
{
|
|
return _adapter.UpdateComponent(agencyBindingModel).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);
|
|
}
|
|
}
|