java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.service.AccountService

@Service public class AccountService extends Object
Provides account-related operations bound to the user's session context within the application. The service manages creation, retrieval, and updating of saving and spending accounts for users.
Author:
L.M.L Nilsen and H.L Xu
  • Constructor Details

    • AccountService

      public AccountService()
  • Method Details

    • saveAccount

      public AccountDTO saveAccount(AccountDTO accountDTO, User user) throws ObjectNotValidException
      Saves a new account based on the provided DTO and associates it with the given user. If the user already has an account of the same type, this method will throw an exception.
      Parameters:
      accountDTO - the data transfer object containing account details
      user - the user with whom the account will be associated
      Returns:
      the saved account DTO
      Throws:
      ObjectNotValidException - if the account DTO fails validation checks
      AccountAlreadyExistsException - if an account of the specified type already exists for the user
    • findUserAccounts

      public AccountResponseDTO findUserAccounts(User user)
      Retrieves the saving and spending accounts associated with the specified user.
      Parameters:
      user - the user whose accounts are to be retrieved
      Returns:
      a DTO containing the user's savings and spending accounts
    • updateAccount

      public AccountResponseDTO updateAccount(AccountUpdateDTO accountUpdateDTO, User user) throws ObjectNotValidException
      Updates an existing account of the specified user based on the provided update DTO. This method checks if the specified account type exists before updating.
      Parameters:
      accountUpdateDTO - the DTO containing the updated account details
      user - the user whose account is to be updated
      Returns:
      the updated account information encapsulated in a DTO
      Throws:
      ObjectNotValidException - if the update DTO fails validation checks
      AccountNotFoundException - if no account of the specified type exists for the user