53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using CandyHouseContracts.AdapterContracts;
|
|
using CandyHouseContracts.BindingModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CandyHouseWebApi.Controllers;
|
|
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
public class PostsController(IPostAdapter adapter) : ControllerBase
|
|
{
|
|
private readonly IPostAdapter _adapter = adapter;
|
|
|
|
[HttpGet]
|
|
public IActionResult GetRecords()
|
|
{
|
|
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] PostBindingModel model)
|
|
{
|
|
return _adapter.RegisterPost(model).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPut]
|
|
public IActionResult ChangeInfo([FromBody] PostBindingModel model)
|
|
{
|
|
return _adapter.ChangePostInfo(model).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public IActionResult Delete(string id)
|
|
{
|
|
return _adapter.RemovePost(id).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPatch("{id}")]
|
|
public IActionResult Restore(string id)
|
|
{
|
|
return _adapter.RestorePost(id).GetResponse(Request, Response);
|
|
}
|
|
}
|