feat: add 服务端
This commit is contained in:
64
PetWash.Api/Controllers/OrdersController.cs
Normal file
64
PetWash.Api/Controllers/OrdersController.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
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();
|
||||
|
||||
return Ok(order);
|
||||
}
|
||||
|
||||
[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);
|
||||
Reference in New Issue
Block a user