Class FridgeController
java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.group.FridgeController
Controller for fridges API, providing endpoints for fridge management
- Since:
- 5.05.2023
- Version:
- 2.0
- Author:
- Anders Austlid invalid input: '&' Birk
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Product>
addProductToFridge
(FridgeProductRequest request, org.springframework.security.core.Authentication authentication) Adds a product to the fridge of a grouporg.springframework.http.ResponseEntity<?>
deleteAmountFridgeProduct
(long fridgeProductId, String amountStr, org.springframework.security.core.Authentication authentication) Deletes an amount of a product from a fridgeorg.springframework.http.ResponseEntity<Fridge>
getFridgeByFridgeId
(long fridgeId, org.springframework.security.core.Authentication authentication) Gets the fridge by its fridge idorg.springframework.http.ResponseEntity<Fridge>
getFridgeByGroupId
(long groupId, org.springframework.security.core.Authentication authentication) Gets the fridge of a grouporg.springframework.http.ResponseEntity<String>
removeProductFromFridge
(long fridgeProductId, org.springframework.security.core.Authentication authentication) Deletes a product from the fridgeorg.springframework.http.ResponseEntity<FridgeProductAsso>
updateProductInFridge
(FridgeProductRequest request, org.springframework.security.core.Authentication authentication) Updates a product in a fridgeorg.springframework.http.ResponseEntity<?>
wasteProductFromFridge
(long fridgeProductId, org.springframework.security.core.Authentication authentication) Deletes a product from the fridge and creates a waste object from it.
-
Constructor Details
-
FridgeController
public FridgeController()
-
-
Method Details
-
getFridgeByGroupId
@GetMapping("/group/{groupId}") public org.springframework.http.ResponseEntity<Fridge> getFridgeByGroupId(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication authentication) Gets the fridge of a group- Parameters:
groupId
- the id of the group must exist- Returns:
- the fridge of the group if it exists, or a 404 if it doesn't exist or the user is not in the group
-
getFridgeByFridgeId
@GetMapping("/fridge/{fridgeId}") public org.springframework.http.ResponseEntity<Fridge> getFridgeByFridgeId(@PathVariable("fridgeId") long fridgeId, org.springframework.security.core.Authentication authentication) Gets the fridge by its fridge id- Parameters:
fridgeId
- the id of the fridge to getauthentication
- a user authentication object for validation of user authorization- Returns:
- the fridge if it exists, or a 404 if it doesn't, or a 403 if the user is not in the fridge
-
addProductToFridge
@PostMapping("/group/product") public org.springframework.http.ResponseEntity<Product> addProductToFridge(@RequestBody FridgeProductRequest request, org.springframework.security.core.Authentication authentication) Adds a product to the fridge of a group- Parameters:
request
- the request containing the group id and product idauthentication
- a user authentication object for validation of user authorization- Returns:
- success if the product was added, bad request if the product was already in the fridge, or not found if the group or product doesn't exist
-
updateProductInFridge
@PutMapping("/group/product") public org.springframework.http.ResponseEntity<FridgeProductAsso> updateProductInFridge(@RequestBody FridgeProductRequest request, org.springframework.security.core.Authentication authentication) Updates a product in a fridge- Parameters:
request
- the request containing the group id and product idauthentication
- a user authentication object for validation of user authorization- Returns:
- success if the product was added, bad request if the product was already in the fridge, or not found if the group or product doesn't exist
-
deleteAmountFridgeProduct
@DeleteMapping("/group/delete/product/{fridgeProductId}/{amount}") public org.springframework.http.ResponseEntity<?> deleteAmountFridgeProduct(@PathVariable("fridgeProductId") long fridgeProductId, @PathVariable("amount") String amountStr, org.springframework.security.core.Authentication authentication) Deletes an amount of a product from a fridge- Parameters:
fridgeProductId
- the id of the fridge product to deleteamountStr
- the amount to deleteauthentication
- the authentication of the user- Returns:
- 200 if the amount was deleted, 404 if the fridge product doesn't exist, 403 if the user is not in the group
-
removeProductFromFridge
@DeleteMapping("/delete/product/{fridgeProductId}") public org.springframework.http.ResponseEntity<String> removeProductFromFridge(@PathVariable("fridgeProductId") long fridgeProductId, org.springframework.security.core.Authentication authentication) Deletes a product from the fridge- Parameters:
fridgeProductId
- the id of the fridge product associationauthentication
- the authentication of the user- Returns:
- success if the product was deleted, bad request if the product wasn't found , or forbidden if the user is not in the group
-
wasteProductFromFridge
@DeleteMapping("/waste/product/{fridgeProductId}") public org.springframework.http.ResponseEntity<?> wasteProductFromFridge(@PathVariable("fridgeProductId") long fridgeProductId, org.springframework.security.core.Authentication authentication) Deletes a product from the fridge and creates a waste object from it.- Parameters:
fridgeProductId
- The id of the fridge product association to be deletedauthentication
- The authentication of the user- Returns:
- A ResponseEntity with status code 200 if successful, or status code 404 if the specified fridge product association was not found. or status code 403 if the user is not in the group
-