CustomerController.java
package io.slayyyyer.orders.web.rest;
import io.slayyyyer.orders.service.CustomerService;
import io.slayyyyer.orders.web.dto.CustomerResponse;
import java.util.List;
import java.util.UUID;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/customers")
public class CustomerController {
private final CustomerService customers;
public CustomerController(CustomerService customers) {
this.customers = customers;
}
@GetMapping("/{id}")
public CustomerResponse get(@PathVariable UUID id) {
return CustomerResponse.from(customers.require(id));
}
@GetMapping
public List<CustomerResponse> list(
@RequestParam(defaultValue = "20") int limit,
@RequestParam(defaultValue = "0") int offset) {
if (limit < 1 || limit > 100) {
throw new IllegalArgumentException("limit must be between 1 and 100");
}
return customers.list(limit, offset).stream().map(CustomerResponse::from).toList();
}
}