Class BudgetService

java.lang.Object
com.omarigrant.budget.services.BudgetService
All Implemented Interfaces:
BudgetServiceInterface

@Service public class BudgetService extends Object implements BudgetServiceInterface
  • Constructor Details

    • BudgetService

      public BudgetService()
  • Method Details

    • findAll

      public List<BudgetDTO> findAll()
      Description copied from interface: BudgetServiceInterface
      Return all BudgetDTO to the user
      Specified by:
      findAll in interface BudgetServiceInterface
      Returns:
      List of BudgetDTOs to output to user
    • findById

      public BudgetDTO findById(Long budgetId)
      Description copied from interface: BudgetServiceInterface
      Get Budget output model by id
      Specified by:
      findById in interface BudgetServiceInterface
      Parameters:
      budgetId - The id of Budget model
      Returns:
      BudgetDTO output model to return to user
    • save

      public BudgetDTO save(Budget budget, LocalDate baseDate)
      Description copied from interface: BudgetServiceInterface
      Save Budget model to database.
      Specified by:
      save in interface BudgetServiceInterface
      Parameters:
      budget - Budget model
      baseDate - date to apply calculations against
      Returns:
      BudgetDTO model to output to user.
    • update

      public BudgetDTO update(Long id, BudgetInputDTO updatedBudget, LocalDate baseDate)
      Description copied from interface: BudgetServiceInterface
      Update a Budget and return the output model.
      Specified by:
      update in interface BudgetServiceInterface
      Parameters:
      id - ID of Budget model to update
      updatedBudget - The Budget input model with updated fields
      baseDate - date to apply calculations against
      Returns:
      BudgetDTO an output model that has been updated.
    • delete

      public void delete(Long id)
      Description copied from interface: BudgetServiceInterface
      Delete a budget from the database
      Specified by:
      delete in interface BudgetServiceInterface
      Parameters:
      id - Budget id
    • handleControllerInputAndSave

      public BudgetDTO handleControllerInputAndSave(BudgetInputDTO budgetInputDTO, LocalDate baseDate, User user)
      Description copied from interface: BudgetServiceInterface
      This functions primary use is for functions, so an input model is given, processed and saved before returning an output model to the user.
      Specified by:
      handleControllerInputAndSave in interface BudgetServiceInterface
      Parameters:
      budgetInputDTO - An input model for users to input
      baseDate - date to apply calculations against
      user - User model to attach budget too
      Returns:
      BudgetDTO which displays all the information to the user.
    • viewCalculationOnly

      public BudgetDTO viewCalculationOnly(BudgetInputDTO budgetInputDTO, LocalDate baseDate)
      Description copied from interface: BudgetServiceInterface
      This functions primary use is for functions, so an input model is given, processed and an output model is returned to the user. This would be used when saving is not required.
      Specified by:
      viewCalculationOnly in interface BudgetServiceInterface
      Parameters:
      budgetInputDTO - An input model for users to input
      baseDate - date to apply calculations against
      Returns:
      BudgetDTO which displays all the information to the user.
    • calculateResults

      public void calculateResults(Budget budget, LocalDate baseDate)
      Description copied from interface: BudgetServiceInterface
      Function to calculate the results from a budget and attach the results to the budget.
      Specified by:
      calculateResults in interface BudgetServiceInterface
      Parameters:
      budget - Budget model
      baseDate - date to apply calculations against
    • recalculateAll

      @Scheduled(cron="0 0 * * * ?") public void recalculateAll()
      Description copied from interface: BudgetServiceInterface
      Recalculate all budgets
      Specified by:
      recalculateAll in interface BudgetServiceInterface
    • doesBudgetBelongToUser

      public boolean doesBudgetBelongToUser(User user, Long budgetId)
      Description copied from interface: BudgetServiceInterface
      Checks that the budget belongs to the user to prevent users affecting items that are not theirs.
      Specified by:
      doesBudgetBelongToUser in interface BudgetServiceInterface
      Parameters:
      user - User model
      budgetId - Id of budget to check
      Returns:
      true if the budget belongs to user