| Name | Message | Date |
|---|---|---|
| 📄 OrdersController.cs | 4 days ago |
📄
OrdersController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Microsoft.AspNetCore.Mvc; using Walley.Checkout.Api.Models; using Walley.Checkout.Api.Services; namespace Walley.Checkout.Api.Controllers; [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase { private readonly IOrderService _orderService; private readonly IRefundService _refundService; public OrdersController(IOrderService orderService, IRefundService refundService) { _orderService = orderService; _refundService = refundService; } /// <summary> /// Get all orders. /// </summary> [HttpGet] public async Task<ActionResult<IEnumerable<Order>>> GetAll() { var orders = await _orderService.GetAllOrdersAsync(); return Ok(orders); } /// <summary> /// Get a specific order by ID. /// </summary> [HttpGet("{id}")] public async Task<ActionResult<Order>> GetById(string id) { // Task 4: This error handling needs improvement. // Right now any issue results in a generic 500 from the exception middleware. var order = await _orderService.GetOrderByIdAsync(id); return Ok(order); } // Task 1: Implement POST /api/orders // See README for requirements. /// <summary> /// Request a refund for an order. /// </summary> [HttpPost("{orderId}/refunds")] public async Task<ActionResult<Refund>> RequestRefund( string orderId, [FromBody] RefundRequest request) { var refund = await _refundService.ProcessRefundAsync( orderId, request.Amount, request.Reason); if (refund.Status == RefundStatus.Rejected) { return UnprocessableEntity(refund); } return Ok(refund); } } public class RefundRequest { public decimal Amount { get; set; } public string Reason { get; set; } = string.Empty; }