65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
|
|
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);
|