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 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 Models() => Ok(await _printerService.GetModelsAsync()); [HttpGet(nameof(PrintTypes))] public async Task PrintTypes() => Ok((await _printerService.GetPrintTypesAsync()).Select(t => t.ToPrintType())); #endregion #region Post methods [HttpPost(nameof(Add))] public async Task Add([FromBody] DTOs.Printer.AddPrinter printer) { if (printer is null) return BadRequest("Данные не были переданы."); var result = await _printerService.AddAsync(printer); return Ok(); } #endregion } }