Class WasteController

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

@RestController @RequestMapping("/api/waste") public class WasteController extends Object
Controller for handling requests related to waste
Since:
04.05.2023
Version:
1.1
Author:
Pedro, birk
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Waste>
    createWaste(WasteRequest waste, org.springframework.security.core.Authentication authentication)
    Saves a new waste
    org.springframework.http.ResponseEntity<Double>
    getCO2Annually(long groupId, org.springframework.security.core.Authentication authentication)
    Retrieves the amount of CO2 emitted annually per person in a specific group.
    org.springframework.http.ResponseEntity<double[]>
    getInformationOfCakeGraph(long groupId, org.springframework.security.core.Authentication authentication)
    Retrieve information about the cake diagram for a given group ID using a GET request.
    org.springframework.http.ResponseEntity<double[]>
    Get the information of the last months of a specific group.
    org.springframework.http.ResponseEntity<Double>
    getLostMoney(long groupId, org.springframework.security.core.Authentication authentication)
    Retrieves the amount of money lost due to expired products in a specific group.
    org.springframework.http.ResponseEntity<List<Waste>>
    getWasteByGroupId(long groupId, org.springframework.security.core.Authentication authentication)
    Gets a waste by its group id
    org.springframework.http.ResponseEntity<Waste>
    getWasteById(long wasteId, org.springframework.security.core.Authentication authentication)
    Gets a waste by its id
    org.springframework.http.ResponseEntity<List<Waste>>
    getWasteOfCategoryByGroupId(long groupId, int categoryNumber, org.springframework.security.core.Authentication authentication)
    Retrieves a list of Waste objects of a specific category from a group

    Methods inherited from class java.lang.Object

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

    • WasteController

      public WasteController()
  • Method Details

    • createWaste

      @PostMapping("/waste") public org.springframework.http.ResponseEntity<Waste> createWaste(@RequestBody WasteRequest waste, org.springframework.security.core.Authentication authentication)
      Saves a new waste
      Parameters:
      waste - the waste to save
      authentication - the authentication of the user
      Returns:
      a ResponseEntity containing the saved waste if it was saved successfully, or a 400 if it wasn't or a 403 if the user is not associated with the group
    • getWasteById

      @GetMapping("/{wasteId}") public org.springframework.http.ResponseEntity<Waste> getWasteById(@PathVariable("wasteId") long wasteId, org.springframework.security.core.Authentication authentication)
      Gets a waste by its id
      Parameters:
      wasteId - the id of the waste
      authentication - the authentication of the user
      Returns:
      a ResponseEntity containing the waste if it exists, or a 404 if it doesn or a 403 if the user is not associated with the group
    • getWasteByGroupId

      @GetMapping("/group/{groupId}") public org.springframework.http.ResponseEntity<List<Waste>> getWasteByGroupId(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication authentication)
      Gets a waste by its group id
      Parameters:
      groupId - the id of the group
      authentication - the authentication of the user
      Returns:
      a ResponseEntity containing the waste if it exists, or a 404 if it doesn't or a 403 if the user is not associated with the group
    • getWasteOfCategoryByGroupId

      @GetMapping("/group/{groupId}/category/{categoryNumber}") public org.springframework.http.ResponseEntity<List<Waste>> getWasteOfCategoryByGroupId(@PathVariable("groupId") long groupId, @PathVariable("categoryNumber") int categoryNumber, org.springframework.security.core.Authentication authentication)
      Retrieves a list of Waste objects of a specific category from a group
      Parameters:
      groupId - the ID of the group to search for
      categoryNumber - the number representing the category to search for
      authentication - the authentication of the user
      Returns:
      a ResponseEntity containing a list of Waste objects if successful, or a not found ResponseEntity if the data is not found or a 403 if the user is not associated with the group
    • getInformationOfCakeGraph

      @GetMapping("/statistic/cakeGraph/{groupId}") public org.springframework.http.ResponseEntity<double[]> getInformationOfCakeGraph(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication authentication)
      Retrieve information about the cake diagram for a given group ID using a GET request.
      Parameters:
      groupId - The ID of the group for which to retrieve the cake diagram information.
      authentication - The authentication of the user.
      Returns:
      A ResponseEntity containing an array of doubles representing the cake diagram information if found, or a 404 Not Found response if not found. If the user is not associated with the group, a 403 Forbidden
    • getInformationOfLastMoths

      @GetMapping("/statistic/lastMonths/{groupId}") public org.springframework.http.ResponseEntity<double[]> getInformationOfLastMoths(@PathVariable("groupId") long groupId)
      Get the information of the last months of a specific group.
      Parameters:
      groupId - the id of the group to get the information for
      Returns:
      a ResponseEntity object containing an array of doubles representing the waste for each category in the last four months, or a not found response if the group does not exist or has no waste data
    • getLostMoney

      @GetMapping("/statistic/lostMoney/{groupId}") public org.springframework.http.ResponseEntity<Double> getLostMoney(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication authentication)
      Retrieves the amount of money lost due to expired products in a specific group. The amount is calculated based on the total cost of the expired products.
      Parameters:
      groupId - the ID of the group to retrieve the lost money from
      authentication - The authentication of the user.
      Returns:
      a ResponseEntity with the lost money as a Double if found, or a ResponseEntity with status 404 if the group is not found
    • getCO2Annually

      @GetMapping("/statistic/annuallyCO2/{groupId}") public org.springframework.http.ResponseEntity<Double> getCO2Annually(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication authentication)
      Retrieves the amount of CO2 emitted annually per person in a specific group.
      Parameters:
      groupId - the ID of the group to retrieve the statistic for
      authentication - The authentication of the user.
      Returns:
      a ResponseEntity containing the amount of CO2 emitted annually per person in the group, or a ResponseEntity with HTTP status 404 (not found) if the group or data is not found