Files
CartriX/CartriX.Api/Controllers/PrinterController.cs
T
2026-05-18 01:58:29 +09:00

43 lines
1.4 KiB
C#

using CartriX.Api.Interfaces;
using CartriX.Api.Mappers;
using Microsoft.AspNetCore.Mvc;
namespace CartriX.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PrinterController : ControllerBase
{
private readonly IPrinterService _printerService;
public PrinterController(IPrinterService printerService)
{
_printerService = printerService;
}
#region Get methods
[HttpGet(nameof(Item))] public async Task<IActionResult> Item([FromQuery] int id)
{
var Item = await _printerService.GetAsync(id);
return (Item is not null) ? Ok(Item.ToItem()) : NotFound();
}
[HttpGet(nameof(Models))] public async Task<IActionResult> Models() => Ok(await _printerService.GetModelsAsync());
[HttpGet(nameof(PrintTypes))] public async Task<IActionResult> PrintTypes() => Ok((await _printerService.GetPrintTypesAsync()).Select(t => t.ToPrintType()));
#endregion
#region Post methods
[HttpPost(nameof(Add))]
public async Task<IActionResult> Add([FromBody] DTOs.Printer.AddPrinter printer)
{
if (printer is null)
return BadRequest("Данные не были переданы.");
var result = await _printerService.AddAsync(printer);
return Ok();
}
#endregion
}
}