/
HiddenLogic
/
Motion-ERP
Обзор
Документация
Войти
/
HiddenLogic
/
Motion-ERP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
Motion-ERP.API/Controllers/TariffsController.cs
89 строк
3 KB
adnet
Initial commit: Motion-ERP solution structure
30 июл 2026, 17:01
30 июл 2026, 17:01
bf32c92
Код
Авторство
О чём код?
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Motion_ERP_Application.DTOs; using Motion_ERP_Application.Interfaces; using Motion_ERP_Domain.Exceptions; namespace Motion_ERP_API.Controllers; [ApiController] [Route("api/[controller]")] [Authorize] public class TariffsController : ControllerBase { private readonly ITariffService _tariffService; public TariffsController(ITariffService tariffService) { _tariffService = tariffService; } [HttpGet] [ProducesResponseType(typeof(IEnumerable<TariffDto>), StatusCodes.Status200OK)] public async Task<ActionResult<IEnumerable<TariffDto>>> GetAll([FromQuery] Guid? assetGroupId, CancellationToken ct) { var tariffs = await _tariffService.GetAllAsync(assetGroupId, ct); return Ok(tariffs); } [HttpGet("{id}")] [ProducesResponseType(typeof(TariffDto), StatusCodes.Status200OK)] public async Task<ActionResult<TariffDto>> GetById(Guid id, CancellationToken ct) { try { var tariff = await _tariffService.GetByIdAsync(id, ct); return Ok(tariff); } catch (DomainException ex) { return NotFound(ex.Message); } } [HttpPost] [ProducesResponseType(typeof(TariffDto), StatusCodes.Status201Created)] public async Task<ActionResult<TariffDto>> Create(CreateTariffDto dto, CancellationToken ct) { var tariff = await _tariffService.CreateAsync(dto, ct); return CreatedAtAction(nameof(GetById), new { id = tariff.TariffId }, tariff); } [HttpPut("{id}")] [ProducesResponseType(typeof(TariffDto), StatusCodes.Status200OK)] public async Task<ActionResult<TariffDto>> Update(Guid id, UpdateTariffDto dto, CancellationToken ct) { try { var tariff = await _tariffService.UpdateAsync(id, dto, ct); return Ok(tariff); } catch (DomainException ex) { return NotFound(ex.Message); } } [HttpDelete("{id}")] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task<IActionResult> Delete(Guid id, CancellationToken ct) { var result = await _tariffService.DeleteAsync(id, ct); return result ? NoContent() : NotFound(); } [HttpPost("calculate")] [ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)] public async Task<ActionResult<decimal>> CalculateCost(Guid assetGroupId, [FromQuery] DateTime startTime, [FromQuery] DateTime endTime, CancellationToken ct) { try { var cost = await _tariffService.CalculateRentalCostAsync(assetGroupId, startTime, endTime, ct); return Ok(cost); } catch (DomainException ex) { return NotFound(ex.Message); } } }