/
HiddenLogic
/
Motion-ERP
Обзор
Документация
Войти
/
HiddenLogic
/
Motion-ERP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
Motion-ERP.API/Controllers/PaymentsController.cs
51 строка
2 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(Roles = "Admin,Accountant")] public class PaymentsController : ControllerBase { private readonly IPaymentService _paymentService; public PaymentsController(IPaymentService paymentService) { _paymentService = paymentService; } [HttpGet] [ProducesResponseType(typeof(IEnumerable<PaymentDto>), StatusCodes.Status200OK)] public async Task<ActionResult<IEnumerable<PaymentDto>>> GetAll([FromQuery] Guid? chargeId, CancellationToken ct) { var payments = await _paymentService.GetAllAsync(chargeId, ct); return Ok(payments); } [HttpGet("{id}")] [ProducesResponseType(typeof(PaymentDto), StatusCodes.Status200OK)] public async Task<ActionResult<PaymentDto>> GetById(Guid id, CancellationToken ct) { var payment = await _paymentService.GetByIdAsync(id, ct); return payment != null ? Ok(payment) : NotFound(); } [HttpPost] [ProducesResponseType(typeof(PaymentDto), StatusCodes.Status201Created)] public async Task<ActionResult<PaymentDto>> Create(CreatePaymentDto dto, CancellationToken ct) { try { var payment = await _paymentService.CreatePaymentAsync(dto, ct); return CreatedAtAction(nameof(GetById), new { id = payment.PaymentId }, payment); } catch (DomainException ex) { return BadRequest(ex.Message); } } }