Class ShoppingListService

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

@Service public class ShoppingListService extends Object
Service for the shopping list
Version:
1.1
Author:
Stian Lyng, Birk
  • Constructor Details

    • ShoppingListService

      public ShoppingListService()
  • Method Details

    • getShoppingListById

      public Optional<ShoppingList> getShoppingListById(long id)
      Gets a shopping list by its ID
      Parameters:
      id - the ID of the shopping list
      Returns:
      an optional containing the shopping list if it exists
    • getShoppingListByGroupId

      public Optional<ShoppingList> getShoppingListByGroupId(long id)
      Gets a shopping list by its group ID
      Parameters:
      id - the ID of the group
      Returns:
      an optional containing the shopping list if it exists
    • getAllShoppingLists

      public List<ShoppingList> getAllShoppingLists()
      Gets all shopping lists
      Returns:
      an optional containing a list of all shopping lists if they exist
    • deleteShoppingListById

      public void deleteShoppingListById(long id)
      Deletes a shopping list by its ID
      Parameters:
      id - the ID of the shopping list
    • addProductToShoppingList

      public Optional<ShoppingList> addProductToShoppingList(long ean, long shoppingListId)
      Adds a product to a shopping list
      Parameters:
      ean - the ean of the product to add
      shoppingListId - the id of the shopping list to add the product to
      Returns:
      the product that was added to the shopping list
    • removeProductFromShoppingList

      public Optional<ShoppingList> removeProductFromShoppingList(long ean, long shoppingListId)
      Removes a product from a shopping list
      Parameters:
      ean - the ean of the product to remove
      shoppingListId - the id of the shopping list to remove the product from
      Returns:
      the shopping list that the product was removed from
    • isUserInShoppinglist

      public boolean isUserInShoppinglist(long id, String name)
      Check if user can edit/get shoppinglist
      Parameters:
      id - id of shoppinglist
      name - name of user
      Returns:
      true if user is in shoppinglist, false if not
    • getGroupIdByShoppingListId

      public long getGroupIdByShoppingListId(long shoppinglistId)
      Get group id by shoppinglist id
      Parameters:
      shoppinglistId - id of shoppinglist
      Returns:
      id of group