Class CustomerQueryRestController
java.lang.Object
com.brodygaudel.bank.query.controller.CustomerQueryRestController
@RestController
@RequestMapping("/queries/customers")
public class CustomerQueryRestController
extends Object
REST controller for handling customer-related queries.
This controller provides endpoints for querying customer information, including getting a customer by ID, searching for customers based on a keyword, and retrieving a list of all customers. It uses the Query Gateway to dispatch queries to the appropriate handlers and retrieve the query results.
-
Constructor Summary
ConstructorDescriptionCustomerQueryRestController
(org.axonframework.queryhandling.QueryGateway queryGateway) Constructs a new instance of CustomerQueryRestController. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
exceptionHandler
(@NotNull Exception exception) Exception handler for handling exceptions that may occur during query processing.getAll()
Endpoint for retrieving a list of all customers.Endpoint for retrieving customer information by ID.Endpoint for searching customers based on a keyword.
-
Constructor Details
-
CustomerQueryRestController
public CustomerQueryRestController(org.axonframework.queryhandling.QueryGateway queryGateway) Constructs a new instance of CustomerQueryRestController.- Parameters:
queryGateway
- The Query Gateway used for dispatching queries.
-
-
Method Details
-
getById
Endpoint for retrieving customer information by ID.- Parameters:
id
- The unique identifier of the customer to retrieve.- Returns:
- A CustomerResponseDTO containing the information of the specified customer.
-
search
@GetMapping("/search") public List<CustomerResponseDTO> search(@RequestParam(name="keyword",defaultValue="") String keyword, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="100") int size) Endpoint for searching customers based on a keyword.- Parameters:
keyword
- The keyword to search for in customer information.page
- The page number for paginated results (default is 0).size
- The size of each page in paginated results (default is 100).- Returns:
- A list of CustomerResponseDTO objects matching the search criteria.
-
getAll
Endpoint for retrieving a list of all customers.- Returns:
- A list of CustomerResponseDTO objects representing all customers.
-
exceptionHandler
@ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<String> exceptionHandler(@NotNull @NotNull Exception exception) Exception handler for handling exceptions that may occur during query processing.- Parameters:
exception
- The exception that occurred.- Returns:
- A ResponseEntity with an error message and HTTP status code 500 (Internal Server Error).
-