// Controllers/CheckoutController.cs
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace CheckoutExample.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class CheckoutController : ControllerBase
{
[HttpGet]
public IActionResult Get(string products, string coupon)
{
// Parse products
var productQuantities = new Dictionary<string, int>();
if (!string.IsNullOrEmpty(products))
{
foreach (var entry in products.Split(','))
{
var parts = entry.Split(':');
if (parts.Length == 2)
{
if (int.TryParse(parts[1], out int quantity))
{
productQuantities.Add(parts[0], quantity);
}
}
}
}
// Build response
var response = new
{
Products = productQuantities,
Coupon = coupon ?? "No coupon applied"
};
return Ok(response);
}
}
}