Class FridgeService

java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.group.FridgeService

@Service public class FridgeService extends Object
Service for management of a group fridge
Version:
2
Author:
Anders Austlid invalid input: '&' Birk
  • Constructor Details

    • FridgeService

      public FridgeService()
  • Method Details

    • getFridgeByGroupId

      public Optional<Fridge> getFridgeByGroupId(long groupId)
      Gets the fridge of a group
      Parameters:
      groupId - the id of the group
      Returns:
      the fridge of the group
    • getFridgeByFridgeId

      public Optional<Fridge> getFridgeByFridgeId(long fridgeId)
      Gets the fridge by its fridge id
      Parameters:
      fridgeId - the id of the fridge
      Returns:
      the fridge if it exists
    • addProductToFridge

      public Optional<Product> addProductToFridge(FridgeProductRequest fridgeProductRequest)
      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

      public Optional<FridgeProductAsso> updateProductInFridge(FridgeProductRequest request)
      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

      public Optional<FridgeProductAsso> deleteAmountFromFridge(long fridgeProductId, double amount)
      Delete an amount from a fridge product
      Parameters:
      fridgeProductId - the id of the fridge product
      amount - the amount to delete
      Returns:
      an optional containing the fridge product if it exists
    • wasteProductFromFridge

      public Optional<Waste> wasteProductFromFridge(long fridgeProductId)
      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

      public boolean isUserInGroupWithFridgeProduct(String username, long fridgeProductId)
      Get all the fridge products of a group
      Parameters:
      username - the username of the user
      fridgeProductId - the id of the fridge product
      Returns:
      true if the user is in the group of the fridge product
    • isUserInFridge

      public boolean isUserInFridge(String username, long fridgeId)
      check if user has accsess to fridge
      Parameters:
      username - the username of the user
      fridgeId - 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