47 lines
1.2 KiB
C#
47 lines
1.2 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 ClientsController(IClientAdapter adapter) : ControllerBase
|
|
{
|
|
private readonly IClientAdapter _adapter = adapter;
|
|
|
|
[HttpGet]
|
|
public IActionResult GetAllRecords()
|
|
{
|
|
return _adapter.GetList().GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpGet("{data}")]
|
|
public IActionResult GetRecord(string data)
|
|
{
|
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Register([FromBody] ClientBindingModel model)
|
|
{
|
|
return _adapter.RegisterClient(model).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPut]
|
|
public IActionResult ChangeInfo([FromBody] ClientBindingModel model)
|
|
{
|
|
return _adapter.ChangeClientInfo(model).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public IActionResult Delete(string id)
|
|
{
|
|
return _adapter.RemoveClient(id).GetResponse(Request, Response);
|
|
}
|
|
}
|