Class FridgeItemsController

java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.controller.FridgeItemsController
All Implemented Interfaces:
IFridgeItemsController

@RestController @CrossOrigin("*") @RequestMapping("/item/fridge") public class FridgeItemsController extends Object implements IFridgeItemsController
This class represents the REST controller for managing items in a fridge and shopping list. It handles requests related to adding, retrieving, and deleting items from a fridge and a shopping list.
  • Constructor Details

    • FridgeItemsController

      public FridgeItemsController()
  • Method Details

    • addToFridge

      @PostMapping("/add") public org.springframework.http.ResponseEntity<Object> addToFridge(@RequestBody ItemDTO itemDTO, @RequestParam(name="fridgeId") Long fridgeId)
      Adds an item to the fridge.
      Specified by:
      addToFridge in interface IFridgeItemsController
      Parameters:
      itemDTO - The item to add to the fridge.
      fridgeId - The id of the fridge to add the item to.
      Returns:
      A ResponseEntity indicating the success or failure of the operation.
    • deleteItemFromFridge

      @DeleteMapping("/delete") public org.springframework.http.ResponseEntity<Object> deleteItemFromFridge(@RequestBody ItemRemoveDTO itemRemoveDTO)
      This method updates and ultimately removes an item from a fridge based on amount of quantity in DTO.
      Specified by:
      deleteItemFromFridge in interface IFridgeItemsController
      Parameters:
      itemRemoveDTO - The item to remove from the fridge.
      Returns:
      A ResponseEntity indicating the success or failure of the operation.
    • updateFridgeItem

      @PutMapping("/update") public org.springframework.http.ResponseEntity<Object> updateFridgeItem(@RequestBody FridgeItemUpdateDTO fridgeItemUpdateDTO, org.springframework.security.core.Authentication authentication)
      This method updates a given fridge item to contain the information received.
      Specified by:
      updateFridgeItem in interface IFridgeItemsController
      Parameters:
      fridgeItemUpdateDTO - New fridge item information, given as a FridgeItemUpdateDTO
      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.
    • getFridge

      @GetMapping("/get") public org.springframework.http.ResponseEntity<Object> getFridge(@RequestParam(name="fridgeId") Long fridgeId)
      Retrieves items from a fridge.
      Specified by:
      getFridge in interface IFridgeItemsController
      Parameters:
      fridgeId - The id of the fridge to retrieve items from.
      Returns:
      A ResponseEntity containing the retrieved items, or indicating a failure if appropriate.
    • searchFridgeItems

      @PostMapping("/search") public org.springframework.http.ResponseEntity<Object> searchFridgeItems(@RequestBody FridgeItemSearchDTO fridgeItemSearchDTO)
      Search and filter items from a fridge.
      Parameters:
      fridgeItemSearchDTO - The search request containing the search parameters.