Package com.omarigrant.budget.services
Class BudgetService
java.lang.Object
com.omarigrant.budget.services.BudgetService
- All Implemented Interfaces:
BudgetServiceInterface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcalculateResults(Budget budget, LocalDate baseDate) Function to calculate the results from a budget and attach the results to the budget.voidDelete a budget from the databasebooleandoesBudgetBelongToUser(User user, Long budgetId) Checks that the budget belongs to the user to prevent users affecting items that are not theirs.findAll()Return all BudgetDTO to the userGet Budget output model by idhandleControllerInputAndSave(BudgetInputDTO budgetInputDTO, LocalDate baseDate, User user) This functions primary use is for functions, so an input model is given, processed and saved before returning an output model to the user.voidRecalculate all budgetsSave Budget model to database.update(Long id, BudgetInputDTO updatedBudget, LocalDate baseDate) Update a Budget and return the output model.viewCalculationOnly(BudgetInputDTO budgetInputDTO, LocalDate baseDate) This functions primary use is for functions, so an input model is given, processed and an output model is returned to the user.
-
Constructor Details
-
BudgetService
public BudgetService()
-
-
Method Details
-
findAll
Description copied from interface:BudgetServiceInterfaceReturn all BudgetDTO to the user- Specified by:
findAllin interfaceBudgetServiceInterface- Returns:
- List of BudgetDTOs to output to user
-
findById
Description copied from interface:BudgetServiceInterfaceGet Budget output model by id- Specified by:
findByIdin interfaceBudgetServiceInterface- Parameters:
budgetId- The id of Budget model- Returns:
- BudgetDTO output model to return to user
-
save
Description copied from interface:BudgetServiceInterfaceSave Budget model to database.- Specified by:
savein interfaceBudgetServiceInterface- Parameters:
budget- Budget modelbaseDate- date to apply calculations against- Returns:
- BudgetDTO model to output to user.
-
update
Description copied from interface:BudgetServiceInterfaceUpdate a Budget and return the output model.- Specified by:
updatein interfaceBudgetServiceInterface- Parameters:
id- ID of Budget model to updateupdatedBudget- The Budget input model with updated fieldsbaseDate- date to apply calculations against- Returns:
- BudgetDTO an output model that has been updated.
-
delete
Description copied from interface:BudgetServiceInterfaceDelete a budget from the database- Specified by:
deletein interfaceBudgetServiceInterface- Parameters:
id- Budget id
-
handleControllerInputAndSave
public BudgetDTO handleControllerInputAndSave(BudgetInputDTO budgetInputDTO, LocalDate baseDate, User user) Description copied from interface:BudgetServiceInterfaceThis 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:
handleControllerInputAndSavein interfaceBudgetServiceInterface- Parameters:
budgetInputDTO- An input model for users to inputbaseDate- date to apply calculations againstuser- User model to attach budget too- Returns:
- BudgetDTO which displays all the information to the user.
-
viewCalculationOnly
Description copied from interface:BudgetServiceInterfaceThis 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:
viewCalculationOnlyin interfaceBudgetServiceInterface- Parameters:
budgetInputDTO- An input model for users to inputbaseDate- date to apply calculations against- Returns:
- BudgetDTO which displays all the information to the user.
-
calculateResults
Description copied from interface:BudgetServiceInterfaceFunction to calculate the results from a budget and attach the results to the budget.- Specified by:
calculateResultsin interfaceBudgetServiceInterface- Parameters:
budget- Budget modelbaseDate- date to apply calculations against
-
recalculateAll
@Scheduled(cron="0 0 * * * ?") public void recalculateAll()Description copied from interface:BudgetServiceInterfaceRecalculate all budgets- Specified by:
recalculateAllin interfaceBudgetServiceInterface
-
doesBudgetBelongToUser
Description copied from interface:BudgetServiceInterfaceChecks that the budget belongs to the user to prevent users affecting items that are not theirs.- Specified by:
doesBudgetBelongToUserin interfaceBudgetServiceInterface- Parameters:
user- User modelbudgetId- Id of budget to check- Returns:
- true if the budget belongs to user
-