Class AccountQueryRestController
java.lang.Object
com.brodygaudel.bank.query.controller.AccountQueryRestController
@RestController
@RequestMapping("/queries/accounts")
public class AccountQueryRestController
extends Object
REST controller for handling account-related queries.
This controller provides endpoints for querying account information, including getting an account by ID or customer ID, retrieving a list of all accounts, and getting operations by account ID. It uses the Query Gateway to dispatch queries to the appropriate handlers and retrieve the query results.
-
Constructor Summary
ConstructorDescriptionAccountQueryRestController
(org.axonframework.queryhandling.QueryGateway queryGateway) Constructs a new instance of AccountQueryRestController. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
exceptionHandler
(@NotNull Exception exception) Exception handler for handling exceptions that may occur during query processing.getAccountByCustomerId
(String customerId) Endpoint for retrieving account information by customer ID.getAccountById
(String accountId) Endpoint for retrieving account information by ID.Endpoint for retrieving a list of all accounts.getOperationByAccountId
(String accountId, int page, int size) Endpoint for retrieving a list of operations by account ID with pagination support.getOperationById
(String operationId) Endpoint for retrieving operation information by operation ID.
-
Constructor Details
-
AccountQueryRestController
public AccountQueryRestController(org.axonframework.queryhandling.QueryGateway queryGateway) Constructs a new instance of AccountQueryRestController.- Parameters:
queryGateway
- The Query Gateway used for dispatching queries.
-
-
Method Details
-
getAccountById
@GetMapping("/get-account-by-id/{accountId}") public AccountResponseDTO getAccountById(@PathVariable String accountId) Endpoint for retrieving account information by ID.- Parameters:
accountId
- The unique identifier of the account to retrieve.- Returns:
- An AccountResponseDTO containing the information of the specified account.
-
getAccountByCustomerId
@GetMapping("/get-account-by-customer-id/{customerId}") public AccountResponseDTO getAccountByCustomerId(@PathVariable String customerId) Endpoint for retrieving account information by customer ID.- Parameters:
customerId
- The unique identifier of the customer associated with the account.- Returns:
- An AccountResponseDTO containing the information of the account associated with the specified customer.
-
getAllAccounts
Endpoint for retrieving a list of all accounts.- Returns:
- A list of AccountResponseDTO objects representing all accounts.
-
getOperationById
@GetMapping("/get-operation-by-id/{operationId}") public OperationResponseDTO getOperationById(@PathVariable String operationId) Endpoint for retrieving operation information by operation ID.- Parameters:
operationId
- The unique identifier of the operation to retrieve.- Returns:
- An OperationResponseDTO containing the information of the specified operation.
-
getOperationByAccountId
@GetMapping("/get-operation-by-account-id/{accountId}") public List<OperationResponseDTO> getOperationByAccountId(@PathVariable String accountId, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="100") int size) Endpoint for retrieving a list of operations by account ID with pagination support.- Parameters:
accountId
- The unique identifier of the account for which to retrieve operations.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 OperationResponseDTO objects representing operations associated with the specified account.
-
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).
-