Initial version

This commit is contained in:
2026-06-20 10:24:36 +02:00
parent f85b83d90f
commit 7e1173bf2c
40 changed files with 5438 additions and 63 deletions
@@ -0,0 +1,54 @@
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<Order> _orders = new();
[HttpGet]
public ActionResult<List<Order>> GetOrders()
=> Ok(_orders.OrderByDescending(o => o.PlacedAt).ToList());
[HttpGet("{id}")]
public ActionResult<Order> GetById(Guid id)
{
var order = _orders.FirstOrDefault(o => o.Id == id);
return order is null ? NotFound() : Ok(order);
}
[HttpPost]
public ActionResult<Order> 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<Order> Cancel(Guid id)
{
var order = _orders.FirstOrDefault(o => o.Id == id);
if (order is null)
{
return NotFound();
}
order.Status = OrderStatus.Cancelled;
return Ok(order);
}
}
}