import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@RestController
public class CheckoutController {
@GetMapping("/checkout")
public Map checkout(
@RequestParam String products,
@RequestParam(required = false) String coupon) {
// Parse products
Map productQuantities = new HashMap<>();
for (String productEntry : products.split(",")) {
String[] parts = productEntry.split(":");
productQuantities.put(
parts[0], // Product ID
Integer.parseInt(parts[1]) // Quantity
);
}
// Build result
Map result = new HashMap<>();
result.put("products", productQuantities);
result.put("coupon", coupon != null ? coupon : "No coupon applied");
return result;
}
}
top of page
bottom of page