using EonaCat.DoxaApi.Attributes; using Microsoft.AspNetCore.Mvc; using SampleApi.Models; namespace SampleApi.Controllers { [ApiController] [Route("api/orders")] [DoxaApiGroup("Orders")] public class OrdersController : ControllerBase { private static readonly List _orders = new(); [HttpGet] public ActionResult> GetOrders() => Ok(_orders.OrderByDescending(o => o.PlacedAt).ToList()); [HttpGet("{id}")] public ActionResult GetById(Guid id) { var order = _orders.FirstOrDefault(o => o.Id == id); return order is null ? NotFound() : Ok(order); } [HttpPost] public ActionResult Create([FromBody] CreateOrderRequest request) { var order = new Order { Id = Guid.NewGuid(), UserId = request.UserId, Lines = request.Lines, Total = request.Lines.Sum(l => l.UnitPrice * l.Quantity), Status = OrderStatus.Pending, PlacedAt = DateTime.UtcNow }; _orders.Add(order); return CreatedAtAction(nameof(GetById), new { id = order.Id }, order); } [HttpPost("{id}/cancel")] public ActionResult Cancel(Guid id) { var order = _orders.FirstOrDefault(o => o.Id == id); if (order is null) { return NotFound(); } order.Status = OrderStatus.Cancelled; return Ok(order); } } }