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 Details

  • 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 of BankAccountResponse.
    • 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 requested BankAccountResponse.
    • 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 created BankAccountResponse.
      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.