Class GoalService
java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.service.GoalService
Service class for handling business logic related to Goal entity and DTO's
- Since:
- 22.4.2024
- Version:
- 1.0
- Author:
- Harry X.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncompleteGoal
(Long goalId, User user) Completes a goal of a user, specified by its IDvoid
deleteUserGoal
(Long id, User user) Deletes a goal of a user, specified by its IDfindUserGoal
(Long id, User user) Finds a user's saving goal specified by its IDgetActiveUserGoals
(User user) Gets a list of active user goalsorg.springframework.data.domain.Page
<GoalResponseDTO> getCompletedUserGoals
(User user, org.springframework.data.domain.Pageable pageable) Gets a page of completed user goalsorg.springframework.data.domain.Page
<GoalResponseDTO> getUserGoals
(User user, org.springframework.data.domain.Pageable pageable) Gets a page of a user's saving goalssave
(GoalCreateDTO goalDTO, User user) Saves a goal entity.update
(Long id, GoalUpdateDTO goalDTO, User user) Updates a goal of a user, specified by its IDupdatePriorities
(List<Long> goalIds, User user) Updates the priority ordering of the list of active saving goals of a user
-
Constructor Details
-
GoalService
public GoalService()
-
-
Method Details
-
findUserGoal
Finds a user's saving goal specified by its ID- Parameters:
id
- Identifies goaluser
- User that owns the goal- Returns:
- Mapped GoalDTO from the Goal entity
-
getUserGoals
public org.springframework.data.domain.Page<GoalResponseDTO> getUserGoals(User user, org.springframework.data.domain.Pageable pageable) Gets a page of a user's saving goals- Parameters:
user
- User that owns the goalspageable
- Pageable object that configures the page dimensions- Returns:
- Page of goals
-
save
public GoalResponseDTO save(GoalCreateDTO goalDTO, User user) throws ObjectNotValidException, ActiveGoalLimitExceededException Saves a goal entity.- Parameters:
goalDTO
- Goal info that is to be saveduser
- User that owns the goal- Returns:
- Goal info of the saved goal
- Throws:
ObjectNotValidException
- If the input goal info fields are invalidActiveGoalLimitExceededException
- If there already are 10 active goals for the user
-
update
public GoalResponseDTO update(Long id, GoalUpdateDTO goalDTO, User user) throws ObjectNotValidException Updates a goal of a user, specified by its ID- Parameters:
id
- Identifies a goalgoalDTO
- New goal infouser
- user that owns the goal- Returns:
- Updated goal info
- Throws:
ObjectNotValidException
- If the input goal DTO fields are invalid
-
getActiveUserGoals
Gets a list of active user goals- Parameters:
user
- User that owns the goals- Returns:
- List of active user goals
-
getCompletedUserGoals
public org.springframework.data.domain.Page<GoalResponseDTO> getCompletedUserGoals(User user, org.springframework.data.domain.Pageable pageable) Gets a page of completed user goals- Parameters:
user
- User that owns the goalspageable
- Pageable object that configures the page dimensions- Returns:
- Page of a user's completed goals
-
completeGoal
Completes a goal of a user, specified by its ID- Parameters:
goalId
- Identifies the goaluser
- User that owns the goal- Returns:
- Completed goal info
-
updatePriorities
Updates the priority ordering of the list of active saving goals of a user- Parameters:
goalIds
- Ordered list of goal Id's, representing the new orderuser
- User that owns the goals- Returns:
- List of goals with the new priorities
-
deleteUserGoal
Deletes a goal of a user, specified by its ID- Parameters:
id
- Identifies a goaluser
- User that owns the goal
-