Spaces:
Runtime error
Runtime error
Download src/SCM.Api/Controllers/ConversoesUnidadeMedidaController.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 4.12 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Api/Controllers/ConversoesUnidadeMedidaController.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Api/Controllers/ConversoesUnidadeMedidaController.cs
-
curl -L -o ConversoesUnidadeMedidaController.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Api/Controllers/ConversoesUnidadeMedidaController.cs
4.12 kB
| using Asp.Versioning; | |
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| using SCM.Application.Cadastros; | |
| using SCM.Application.Cadastros.Dtos; | |
| using SCM.Shared.Api; | |
| using SCM.Shared.Constants; | |
| namespace SCM.Api.Controllers; | |
| /// <summary>Conversões entre unidades de medida (par direcional com fator).</summary> | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| public sealed class ConversoesUnidadeMedidaController : ControllerBase | |
| { | |
| private readonly IConversaoUnidadeMedidaService _service; | |
| public ConversoesUnidadeMedidaController(IConversaoUnidadeMedidaService service) => _service = service; | |
| /// <summary>Lista todas as conversões (com os códigos das unidades).</summary> | |
| [] | |
| [] | |
| public async Task<ActionResult<IReadOnlyList<ConversaoUnidadeMedidaResponse>>> GetAll(CancellationToken ct = default) | |
| => Ok(await _service.GetAllAsync(ct)); | |
| /// <summary>Obtém uma conversão pelo identificador.</summary> | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<ConversaoUnidadeMedidaResponse>> GetById(Guid id, CancellationToken ct = default) | |
| => Ok(await _service.GetByIdAsync(id, ct)); | |
| /// <summary>Converte um valor entre duas unidades (404 se a conversão não estiver cadastrada).</summary> | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<ConversaoValorResponse>> Converter( | |
| [] Guid unidadeDeId, [FromQuery] Guid unidadeParaId, [FromQuery] decimal valor, | |
| CancellationToken ct = default) | |
| => Ok(await _service.ConverterAsync(unidadeDeId, unidadeParaId, valor, ct)); | |
| /// <summary>Cria uma conversão (opcionalmente também a direção inversa, 1/fator).</summary> | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<ConversaoUnidadeMedidaResponse>> Create( | |
| [] CreateConversaoUnidadeMedidaRequest request, CancellationToken ct = default) | |
| { | |
| var created = await _service.CreateAsync(request, ct); | |
| return CreatedAtAction(nameof(GetById), new { id = created.Id, version = "1.0" }, created); | |
| } | |
| /// <summary>Altera o fator de uma conversão (o par de unidades é imutável).</summary> | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<ConversaoUnidadeMedidaResponse>> Update( | |
| Guid id, [FromBody] UpdateConversaoUnidadeMedidaRequest request, CancellationToken ct = default) | |
| => Ok(await _service.UpdateAsync(id, request, ct)); | |
| /// <summary>Exclui uma conversão.</summary> | |
| [] | |
| [] | |
| [] | |
| [] | |
| public async Task<IActionResult> Delete(Guid id, CancellationToken ct = default) | |
| { | |
| await _service.DeleteAsync(id, ct); | |
| return NoContent(); | |
| } | |
| } | |