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

@Service public class GoalService extends Object
Service class for handling business logic related to Goal entity and DTO's
Since:
22.4.2024
Version:
1.0
Author:
Harry X.
  • Constructor Details

    • GoalService

      public GoalService()
  • Method Details

    • findUserGoal

      public GoalResponseDTO findUserGoal(Long id, User user)
      Finds a user's saving goal specified by its ID
      Parameters:
      id - Identifies goal
      user - 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 goals
      pageable - Pageable object that configures the page dimensions
      Returns:
      Page of goals
    • save

      Saves a goal entity.
      Parameters:
      goalDTO - Goal info that is to be saved
      user - User that owns the goal
      Returns:
      Goal info of the saved goal
      Throws:
      ObjectNotValidException - If the input goal info fields are invalid
      ActiveGoalLimitExceededException - 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 goal
      goalDTO - New goal info
      user - user that owns the goal
      Returns:
      Updated goal info
      Throws:
      ObjectNotValidException - If the input goal DTO fields are invalid
    • getActiveUserGoals

      public List<GoalResponseDTO> getActiveUserGoals(User user)
      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 goals
      pageable - Pageable object that configures the page dimensions
      Returns:
      Page of a user's completed goals
    • completeGoal

      public GoalResponseDTO completeGoal(Long goalId, User user)
      Completes a goal of a user, specified by its ID
      Parameters:
      goalId - Identifies the goal
      user - User that owns the goal
      Returns:
      Completed goal info
    • updatePriorities

      public List<GoalResponseDTO> updatePriorities(List<Long> goalIds, User user)
      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 order
      user - User that owns the goals
      Returns:
      List of goals with the new priorities
    • deleteUserGoal

      public void deleteUserGoal(Long id, User user)
      Deletes a goal of a user, specified by its ID
      Parameters:
      id - Identifies a goal
      user - User that owns the goal