Class WasteService

java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.group.WasteService

@Service public class WasteService extends Object
Service for waste
Version:
1.1
Author:
Anders, Pedro, Birk
  • Constructor Details

    • WasteService

      public WasteService()
  • Method Details

    • createWaste

      public Optional<Waste> createWaste(WasteRequest wasteRequest)
      Creates a new waste
      Parameters:
      wasteRequest - the waste to create
      Returns:
      an optional containing the waste if it was created
    • getWasteById

      public Optional<Waste> getWasteById(long id)
      Gets a waste by its id
      Parameters:
      id - the id of the waste
      Returns:
      an optional containing the waste if it exists
    • getWasteByGroupId

      public Optional<List<Waste>> getWasteByGroupId(long groupId)
      Gets a waste by its group id
      Parameters:
      groupId - the id of the group
      Returns:
      an optional containing the waste if it exists
    • getWasteOfCategoryByGroupId

      public Optional<List<Waste>> getWasteOfCategoryByGroupId(long groupId, String categoryName)
      Returns an Optional containing a List of Waste objects for a specific category and group id, or an empty Optional if there are no wastes for that category and group id.
      Parameters:
      groupId - the ID of the group to search in
      categoryName - the name of the category to search for
      Returns:
      an Optional containing a List of Waste objects, or an empty Optional if there are no wastes for that category and group id
    • getCakeDiagram

      public Optional<double[]> getCakeDiagram(long groupId)
      Get the cake diagram for a group of waste.
      Parameters:
      groupId - The ID of the group for which to retrieve the cake diagram.
      Returns:
      An Optional containing an array of doubles representing the cake diagram for the group, or an empty Optional if the group is not found.
    • getLastMonth

      public Optional<double[]> getLastMonth(long groupId)
      Retrieve an optional array of doubles representing the amount of waste produced in each of the last 4 months for a given group.
      Parameters:
      groupId - a long representing the id of the group whose waste production statistics are to be retrieved
      Returns:
      an optional array of doubles representing the amount of waste produced in each of the last 4 months for the given group, or an empty optional if the group could not be found or no waste was produced in the last 4 months
    • getLostMoney

      public Optional<Double> getLostMoney(long groupId)
      Retrieves the lost money in the last month for the group with the given ID.
      Parameters:
      groupId - the ID of the group to retrieve the lost money for
      Returns:
      an Optional containing the lost money if the group exists, or empty if it doesn't exist or there are no wastes in the last month
    • getCO2PerPerson

      public Optional<Double> getCO2PerPerson(long groupId)
      Calculates the annual average CO2 emissions per person in the specified group.
      Parameters:
      groupId - the ID of the group for which to calculate CO2 emissions
      Returns:
      an Optional containing the annual average CO2 emissions per person, or empty if the group has no users or does not exist
    • isUserAssosiatedWithWaste

      public boolean isUserAssosiatedWithWaste(String username, long wasteId)
      Checks if the user is assosiated with the waste their trying to retrive
      Parameters:
      username - the username of the user
      wasteId - the id of the waste
      Returns:
      true if the user is associated with the waste, false otherwise