Class AccountService
java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.service.AccountService
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindUserAccounts
(User user) Retrieves the saving and spending accounts associated with the specified user.saveAccount
(AccountDTO accountDTO, User user) Saves a new account based on the provided DTO and associates it with the given user.updateAccount
(AccountUpdateDTO accountUpdateDTO, User user) Updates an existing account of the specified user based on the provided update DTO.
-
Constructor Details
-
AccountService
public AccountService()
-
-
Method Details
-
saveAccount
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 detailsuser
- the user with whom the account will be associated- Returns:
- the saved account DTO
- Throws:
ObjectNotValidException
- if the account DTO fails validation checksAccountAlreadyExistsException
- if an account of the specified type already exists for the user
-
findUserAccounts
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 detailsuser
- 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 checksAccountNotFoundException
- if no account of the specified type exists for the user
-