Class FridgeController

java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.group.FridgeController

@RestController @RequestMapping("/api/fridges") public class FridgeController extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Product>
    addProductToFridge(FridgeProductRequest request, org.springframework.security.core.Authentication authentication)
    Adds a product to the fridge of a group
    org.springframework.http.ResponseEntity<?>
    deleteAmountFridgeProduct(long fridgeProductId, String amountStr, org.springframework.security.core.Authentication authentication)
    Deletes an amount of a product from a fridge
    org.springframework.http.ResponseEntity<Fridge>
    getFridgeByFridgeId(long fridgeId, org.springframework.security.core.Authentication authentication)
    Gets the fridge by its fridge id
    org.springframework.http.ResponseEntity<Fridge>
    getFridgeByGroupId(long groupId, org.springframework.security.core.Authentication authentication)
    Gets the fridge of a group
    org.springframework.http.ResponseEntity<String>
    removeProductFromFridge(long fridgeProductId, org.springframework.security.core.Authentication authentication)
    Deletes a product from the fridge
    org.springframework.http.ResponseEntity<FridgeProductAsso>
    updateProductInFridge(FridgeProductRequest request, org.springframework.security.core.Authentication authentication)
    Updates a product in a fridge
    org.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 get
      authentication - 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 id
      authentication - 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 id
      authentication - 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 delete
      amountStr - the amount to delete
      authentication - 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 association
      authentication - 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 deleted
      authentication - 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