Package api.mpba.rastvdmy.controller
Class BankAccountController
java.lang.Object
api.mpba.rastvdmy.controller.BankAccountController
@RestController
@PreAuthorize("hasRole(\'ROLE_DEFAULT\')")
@RequestMapping(path="/api/v1/accounts")
public class BankAccountController
extends Object
Controller for managing bank accounts.
This controller provides endpoints for users to interact with their bank accounts,
including retrieving account information, adding new accounts, and removing accounts.
It utilizes the BankAccountService
for business logic and BankAccountMapper
for mapping between request and response objects.
-
Constructor Summary
ConstructorDescriptionBankAccountController
(BankAccountMapper accountMapper, BankAccountService accountService) Constructor for BankAccountController. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<BankAccountResponse> addAccount
(jakarta.servlet.http.HttpServletRequest request, String bankName) Adds a new bank account for the current user associated with a specific bank.org.springframework.http.ResponseEntity
<BankAccountResponse> getAccountById
(jakarta.servlet.http.HttpServletRequest request, String bankName, UUID accountId, String type) Retrieves a specific bank account by its ID.org.springframework.http.ResponseEntity
<Map<String, BigDecimal>> getTotalBalance
(jakarta.servlet.http.HttpServletRequest request) Retrieves the total balances for all bank accounts associated with the current user.org.springframework.http.ResponseEntity
<List<BankAccountResponse>> getUserAccounts
(jakarta.servlet.http.HttpServletRequest request, String bankName) Retrieves all bank accounts for the current user associated with a specific bank.org.springframework.http.ResponseEntity
<Void> removeAccount
(jakarta.servlet.http.HttpServletRequest request, String bankName, UUID accountId) Removes a specific bank account associated with the current user.org.springframework.http.ResponseEntity
<Void> removeAllAccounts
(jakarta.servlet.http.HttpServletRequest request, String bankName) Removes all bank accounts associated with the current user for a specific bank.
-
Constructor Details
-
BankAccountController
Constructor for BankAccountController.- Parameters:
accountMapper
- TheBankAccountMapper
to be used.accountService
- TheBankAccountService
to be used.
-
-
Method Details
-
getUserAccounts
@GetMapping(path="/{name}", produces="application/json") public org.springframework.http.ResponseEntity<List<BankAccountResponse>> getUserAccounts(jakarta.servlet.http.HttpServletRequest request, @PathVariable("name") String bankName) Retrieves all bank accounts for the current user associated with a specific bank.- Parameters:
request
- The HTTP servlet request containing user information.bankName
- The name of the bank for which to retrieve accounts.- Returns:
- A
ResponseEntity
containing a list ofBankAccountResponse
.
-
getAccountById
@GetMapping(path="/{name}/{accountId}", produces="application/json") public org.springframework.http.ResponseEntity<BankAccountResponse> getAccountById(jakarta.servlet.http.HttpServletRequest request, @PathVariable("name") String bankName, @PathVariable("accountId") UUID accountId, @RequestParam(value="type",defaultValue="non-visible") String type) Retrieves a specific bank account by its ID.- Parameters:
request
- The HTTP servlet request containing user information.bankName
- The name of the bank where the account is held.accountId
- The ID of the account to retrieve.type
- The type of account (optional, defaults to "non-visible").- Returns:
- A
ResponseEntity
containing the requestedBankAccountResponse
.
-
getTotalBalance
@GetMapping(path="/total", produces="application/json") public org.springframework.http.ResponseEntity<Map<String,BigDecimal>> getTotalBalance(jakarta.servlet.http.HttpServletRequest request) Retrieves the total balances for all bank accounts associated with the current user.- Parameters:
request
- The HTTP servlet request containing user information.- Returns:
- A
ResponseEntity
containing a map of total balances for all accounts.
-
addAccount
@PostMapping(path="/{name}", produces="application/json") public org.springframework.http.ResponseEntity<BankAccountResponse> addAccount(jakarta.servlet.http.HttpServletRequest request, @PathVariable("name") String bankName) throws Exception Adds a new bank account for the current user associated with a specific bank.- Parameters:
request
- The HTTP servlet request containing user information.bankName
- The name of the bank to connect the new account to.- Returns:
- A
ResponseEntity
containing the createdBankAccountResponse
. - Throws:
Exception
- If there is an error while adding the account.
-
removeAccount
@DeleteMapping(path="/{name}/{accountId}") public org.springframework.http.ResponseEntity<Void> removeAccount(jakarta.servlet.http.HttpServletRequest request, @PathVariable("name") String bankName, @PathVariable("accountId") UUID accountId) Removes a specific bank account associated with the current user.- Parameters:
request
- The HTTP servlet request containing user information.bankName
- The name of the bank where the account is held.accountId
- The ID of the account to remove.- Returns:
- A
ResponseEntity
with no content.
-
removeAllAccounts
@DeleteMapping(path="/{name}") public org.springframework.http.ResponseEntity<Void> removeAllAccounts(jakarta.servlet.http.HttpServletRequest request, @PathVariable("name") String bankName) Removes all bank accounts associated with the current user for a specific bank.- Parameters:
request
- The HTTP servlet request containing user information.bankName
- The name of the bank for which to remove all accounts.- Returns:
- A
ResponseEntity
with no content.
-