2026-02-25 15:41:00 +08:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using PetWash.Api.Models;
|
|
|
|
|
using PetWash.Api.Services;
|
|
|
|
|
|
|
|
|
|
namespace PetWash.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class OrdersController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly OrderService _orderService;
|
|
|
|
|
|
|
|
|
|
public OrdersController(OrderService orderService)
|
|
|
|
|
{
|
|
|
|
|
_orderService = orderService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderRequest request)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var order = await _orderService.CreateOrderAsync(request.PackageId);
|
|
|
|
|
return Ok(order);
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id}/payment")]
|
|
|
|
|
public async Task<IActionResult> ConfirmPayment(int id)
|
|
|
|
|
{
|
|
|
|
|
var order = await _orderService.ConfirmPaymentAsync(id);
|
|
|
|
|
if (order == null)
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
2026-03-04 17:51:35 +08:00
|
|
|
return Ok(order);
|
2026-02-25 15:41:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public async Task<IActionResult> GetOrder(int id)
|
|
|
|
|
{
|
|
|
|
|
var order = await _orderService.GetOrderAsync(id);
|
|
|
|
|
if (order == null)
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
return Ok(order);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}/status")]
|
|
|
|
|
public async Task<IActionResult> UpdateStatus(int id, [FromBody] UpdateStatusRequest request)
|
|
|
|
|
{
|
|
|
|
|
var order = await _orderService.UpdateOrderStatusAsync(id, request.Status);
|
|
|
|
|
if (order == null)
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
return Ok(order);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public record CreateOrderRequest(int PackageId);
|
|
|
|
|
public record UpdateStatusRequest(OrderStatus Status);
|