Class ShoppingItemsController

java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.controller.ShoppingItemsController
All Implemented Interfaces:
IShoppingItemsController

@RestController @CrossOrigin("*") @RequestMapping("/item/shopping") public class ShoppingItemsController extends Object implements IShoppingItemsController
A controller class handling shopping items and their operations.
Author:
Trym Hamer Gudvangen
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Object>
    acceptSuggestion(ItemRemoveDTO itemDTO, org.springframework.security.core.Authentication authentication)
    Accepts a suggested item on the shopping list for a given fridge.
    org.springframework.http.ResponseEntity<Object>
    addToShoppingList(ItemDTO itemDTO, Long fridgeId, boolean suggestion, org.springframework.security.core.Authentication authentication)
    Adds items to the shopping list for a given fridge.
    org.springframework.http.ResponseEntity<Object>
    buyItemsFromShoppingList(List<ItemMoveDTO> itemMoveDTO, org.springframework.security.core.Authentication authentication)
    Buys the items on the shopping list for a given fridge and places it in fridge items.
    org.springframework.http.ResponseEntity<Object>
    deleteAllItemsFromShoppingList(List<ItemRemoveDTO> itemDTOList, org.springframework.security.core.Authentication authentication)
    Deletes the items on the shopping list for a given fridge.
    org.springframework.http.ResponseEntity<Object>
    deleteItemFromShoppingList(ItemRemoveDTO itemRemoveDTO, boolean suggestion, org.springframework.security.core.Authentication authentication)
    An item can be deleted from a shopping list of a fridge given the following conditions: - User is a superuser, then user can delete both suggested and actual items - User is a normal user, then user can delete suggested items but not actual items.
    org.springframework.http.ResponseEntity<Object>
    Gets the items on the shopping list for a given fridge.
    org.springframework.http.ResponseEntity<Object>
    updateShoppingListItem(ShoppingItemUpdateDTO shoppingItemUpdateDTO, org.springframework.security.core.Authentication authentication)
    This method updates a given fridge item to contain the information received.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ShoppingItemsController

      public ShoppingItemsController()
  • Method Details

    • addToShoppingList

      @PostMapping("/add") public org.springframework.http.ResponseEntity<Object> addToShoppingList(@RequestBody ItemDTO itemDTO, @RequestParam(name="fridgeId") Long fridgeId, @RequestParam(name="suggestion") boolean suggestion, org.springframework.security.core.Authentication authentication)
      Adds items to the shopping list for a given fridge.
      Specified by:
      addToShoppingList in interface IShoppingItemsController
      Parameters:
      itemDTO - the item to add to the shopping list
      fridgeId - the ID of the fridge for which to add items to the shopping list
      suggestion - whether or not the item was a suggestion
      Returns:
      a response entity indicating success
    • deleteItemFromShoppingList

      @DeleteMapping("/delete") public org.springframework.http.ResponseEntity<Object> deleteItemFromShoppingList(@RequestBody ItemRemoveDTO itemRemoveDTO, @RequestParam(name="suggestion") boolean suggestion, org.springframework.security.core.Authentication authentication)
      An item can be deleted from a shopping list of a fridge given the following conditions: - User is a superuser, then user can delete both suggested and actual items - User is a normal user, then user can delete suggested items but not actual items.
      Specified by:
      deleteItemFromShoppingList in interface IShoppingItemsController
      Parameters:
      itemRemoveDTO - the item to remove from the shopping list
      suggestion - whether the item was a suggestion
      Returns:
      a response entity indicating success
    • deleteAllItemsFromShoppingList

      @PostMapping(value="/delete/all", consumes="application/json") public org.springframework.http.ResponseEntity<Object> deleteAllItemsFromShoppingList(@RequestBody List<ItemRemoveDTO> itemDTOList, org.springframework.security.core.Authentication authentication)
      Deletes the items on the shopping list for a given fridge.
      Specified by:
      deleteAllItemsFromShoppingList in interface IShoppingItemsController
      Parameters:
      itemDTOList - the list of items to buy
      Returns:
      a response entity indicating success
    • updateShoppingListItem

      @PutMapping("/update") public org.springframework.http.ResponseEntity<Object> updateShoppingListItem(@RequestBody ShoppingItemUpdateDTO shoppingItemUpdateDTO, org.springframework.security.core.Authentication authentication)
      This method updates a given fridge item to contain the information received.
      Specified by:
      updateShoppingListItem in interface IShoppingItemsController
      Parameters:
      shoppingItemUpdateDTO - New shopping item information, given as a ShoppingItemUpdateDTO
      authentication - The authentication of the user who sent in the request, given as an Authentication object.
      Returns:
      A ResponseEntity indicating the success or failure of the operation.
    • buyItemsFromShoppingList

      @PostMapping(value="/buy", consumes="application/json") public org.springframework.http.ResponseEntity<Object> buyItemsFromShoppingList(@RequestBody List<ItemMoveDTO> itemMoveDTO, org.springframework.security.core.Authentication authentication)
      Buys the items on the shopping list for a given fridge and places it in fridge items.
      Specified by:
      buyItemsFromShoppingList in interface IShoppingItemsController
      Parameters:
      itemMoveDTO - the list of items to buy
      Returns:
      a response entity indicating success
    • getShoppingList

      @GetMapping("/get") public org.springframework.http.ResponseEntity<Object> getShoppingList(@RequestParam(name="fridgeId") Long fridgeId)
      Gets the items on the shopping list for a given fridge.
      Specified by:
      getShoppingList in interface IShoppingItemsController
      Parameters:
      fridgeId - the ID of the fridge for which to retrieve items from the shopping list
      Returns:
      a response entity containing the shopping list items
    • acceptSuggestion

      @PostMapping("/suggestion") public org.springframework.http.ResponseEntity<Object> acceptSuggestion(@RequestBody ItemRemoveDTO itemDTO, org.springframework.security.core.Authentication authentication)
      Accepts a suggested item on the shopping list for a given fridge.
      Specified by:
      acceptSuggestion in interface IShoppingItemsController
      Parameters:
      itemDTO - the item to accept
      Returns:
      a response entity indicating success