Class FridgeService
java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.group.FridgeService
Service for management of a group fridge
- Version:
- 2
- Author:
- Anders Austlid invalid input: '&' Birk
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddProductToFridge
(FridgeProductRequest fridgeProductRequest) Adds a product to the fridge of a groupdeleteAmountFromFridge
(long fridgeProductId, double amount) Delete an amount from a fridge productgetFridgeByFridgeId
(long fridgeId) Gets the fridge by its fridge idgetFridgeByGroupId
(long groupId) Gets the fridge of a grouplong
getGroupIdFromFridgeProuctId
(long fridgeProductId) Get the group id of a fridge productboolean
isUserInFridge
(String username, long fridgeId) check if user has accsess to fridgeboolean
isUserInGroupWithFridgeProduct
(String username, long fridgeProductId) Get all the fridge products of a groupboolean
removeProductFromFridge
(long FPId) Remove a product from the fridge of a groupUpdates a product in the fridge of a groupwasteProductFromFridge
(long fridgeProductId) Deletes a product from the fridge and saves a waste object representing the discarded product.
-
Constructor Details
-
FridgeService
public FridgeService()
-
-
Method Details
-
getFridgeByGroupId
Gets the fridge of a group- Parameters:
groupId
- the id of the group- Returns:
- the fridge of the group
-
getFridgeByFridgeId
Gets the fridge by its fridge id- Parameters:
fridgeId
- the id of the fridge- Returns:
- the fridge if it exists
-
addProductToFridge
Adds a product to the fridge of a group- Parameters:
fridgeProductRequest
- the fridge product request- Returns:
- the product that was added to the fridge
-
updateProductInFridge
Updates a product in the fridge of a group- Parameters:
request
- the fridge product request- Returns:
- the product that was added to the fridge
-
removeProductFromFridge
public boolean removeProductFromFridge(long FPId) Remove a product from the fridge of a group- Parameters:
FPId
- the id of the fridge product association- Returns:
- true if the product was removed
-
deleteAmountFromFridge
Delete an amount from a fridge product- Parameters:
fridgeProductId
- the id of the fridge productamount
- the amount to delete- Returns:
- an optional containing the fridge product if it exists
-
wasteProductFromFridge
Deletes a product from the fridge and saves a waste object representing the discarded product.- Parameters:
fridgeProductId
- the ID of the fridge product association to delete- Returns:
- an Optional containing the saved waste object, or an empty Optional if the fridge product association with the given ID is not found
-
isUserInGroupWithFridgeProduct
Get all the fridge products of a group- Parameters:
username
- the username of the userfridgeProductId
- the id of the fridge product- Returns:
- true if the user is in the group of the fridge product
-
isUserInFridge
check if user has accsess to fridge- Parameters:
username
- the username of the userfridgeId
- the id of the fridge- Returns:
- true if the user is in the group of the fridge
-
getGroupIdFromFridgeProuctId
public long getGroupIdFromFridgeProuctId(long fridgeProductId) Get the group id of a fridge product- Parameters:
fridgeProductId
- the id of the fridge product- Returns:
- the id of the group of the fridge product
-