52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using OrdersManagementDataModel.Dtos;
|
|
using OrdersManagementDataModel.Services;
|
|
|
|
namespace FaKrosnoApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class FunctionsController(IFunctionService service) : Controller
|
|
{
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<FunctionDto>>> GetAll()
|
|
{
|
|
IEnumerable<FunctionDto?> functions = await service.GetAll();
|
|
return Ok(functions);
|
|
}
|
|
|
|
[HttpGet("by-id")]
|
|
public async Task<ActionResult<FunctionDto?>> GetById([FromQuery] Guid id)
|
|
{
|
|
FunctionDto? function = await service.GetById(id);
|
|
return function != null ? Ok(function) : NotFound();
|
|
}
|
|
|
|
[HttpGet("by-name")]
|
|
public async Task<ActionResult<FunctionDto?>> GetByName([FromQuery] string name)
|
|
{
|
|
FunctionDto? function = await service.GetByName(name);
|
|
return function != null ? Ok(function) : NotFound();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult<FunctionDto>> Add([FromBody] FunctionDto function)
|
|
{
|
|
await service.Add(function);
|
|
return Ok(function);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<ActionResult<FunctionDto>> Update([FromBody] FunctionDto function)
|
|
{
|
|
await service.Update(function);
|
|
return Ok(function);
|
|
}
|
|
|
|
[HttpDelete]
|
|
public async Task<ActionResult<FunctionDto>> Delete([FromQuery] Guid id)
|
|
{
|
|
await service.Delete(id);
|
|
return Ok();
|
|
}
|
|
} |