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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
addToFridge
(ItemDTO itemDTO, Long fridgeId) Adds an item to the fridge.org.springframework.http.ResponseEntity<Object>
deleteItemFromFridge
(ItemRemoveDTO itemRemoveDTO) This method updates and ultimately removes an item from a fridge based on amount of quantity in DTO.org.springframework.http.ResponseEntity<Object>
Retrieves items from a fridge.org.springframework.http.ResponseEntity<Object>
searchFridgeItems
(FridgeItemSearchDTO fridgeItemSearchDTO) Search and filter items from a fridge.org.springframework.http.ResponseEntity<Object>
updateFridgeItem
(FridgeItemUpdateDTO fridgeItemUpdateDTO, org.springframework.security.core.Authentication authentication) This method updates a given fridge item to contain the information received.
-
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 interfaceIFridgeItemsController
- 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 interfaceIFridgeItemsController
- 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 interfaceIFridgeItemsController
- Parameters:
fridgeItemUpdateDTO
- New fridge item information, given as a FridgeItemUpdateDTOauthentication
- 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 interfaceIFridgeItemsController
- 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.
-