java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.service.fridge.FridgeService
All Implemented Interfaces:
IFridgeService

@Service public class FridgeService extends Object implements IFridgeService
This service class handles the business logic for fridge-related operations. It implements the IFridgeService interface. It provides methods for updating and deleting users from a fridge, as well as authorization of these actions.
Author:
Trym Hamer Gudvangen
  • Constructor Details

    • FridgeService

      public FridgeService()
  • Method Details

    • initializeFridge

      @Transactional public void initializeFridge(String username)
      This method creates a new fridge and a new fridge member entry for a given user.
      Specified by:
      initializeFridge in interface IFridgeService
      Parameters:
      username - The username of the user, given as a String
    • createFridge

      @Transactional public void createFridge(String fridgeName, String username)
      This method creates a new fridge and a new fridge member entry for a given user.
      Specified by:
      createFridge in interface IFridgeService
      Parameters:
      fridgeName - The name of the fridge to be created, given as a String.
      username - The username of the user, given as a String
    • updateFridgeName

      @Transactional public void updateFridgeName(FridgeDTO fridgeDTO, String userTryingToUpdate)
      This method updates fridge's name. However, this is only possible if the person trying to update the user is already a part of the fridge and is a superuser.
      Parameters:
      fridgeDTO - The information surrounding the fridge, given as a FridgeDTO object.
      userTryingToUpdate - The username of the user trying to update the other user, given as a String
    • addUserToFridge

      @Transactional public void addUserToFridge(FridgeUserDTO fridgeUserDTO, String userTryingToAdd)
      This method adds a user to a given fridge. However, this is only possible if the person trying to add the user is already a part of the fridge and is a superuser.
      Parameters:
      fridgeUserDTO - The information surrounding the user and fridge, given as a FridgeUserDTO object.
      userTryingToAdd - The username of the user trying to add the other user, given as a String
    • deleteUserFromFridge

      @Transactional public void deleteUserFromFridge(FridgeUserDTO fridgeUserDTO, String userTryingToRemove)
      This method removes a user from a given fridge. However, this is only possible if the person trying to remove the user is already a part of the fridge and is a superuser.
      Parameters:
      fridgeUserDTO - The information surrounding the user and fridge, given as a FridgeUserDTO object.
      userTryingToRemove - The username of the user trying to remove the other user, given as a String
    • updateUserFromFridge

      @Transactional public void updateUserFromFridge(FridgeUserDTO fridgeUserDTO, String userTryingToUpdate)
      This method updates a user from a given fridge. However, this is only possible if the person trying to update the user is already a part of the fridge and is a superuser.
      Parameters:
      fridgeUserDTO - The information surrounding the user and fridge, given as a FridgeUserDTO object.
      userTryingToUpdate - The username of the user trying to update the other user, given as a String
    • retrieveFridgeIdsByUsername

      public List<Long> retrieveFridgeIdsByUsername(String username)
      This method retrieves all the fridge ids for a given user.
      Parameters:
      username - The username of the user, given as a String.
      Returns:
      List of fridge ids.
    • retrieveFridgesByUsername

      public FridgeLoadAllDTO retrieveFridgesByUsername(String username)
      This method retrieves all the fridge ids for a given user.
      Parameters:
      username - The username of the user, given as a String.
      Returns:
      FridgeDTO containing the list of Fridge objects
    • retrieveMembersByFridgeId

      public FridgeMemberLoadAllDTO retrieveMembersByFridgeId(Long fridgeId, String username)
      This method retrieves all the users for a given fridge.
      Specified by:
      retrieveMembersByFridgeId in interface IFridgeService
      Parameters:
      fridgeId - The id of the fridge, given as a Long object.
      username - The username of the user checking the fridge, given as a String.
      Returns:
      UserLoadALLDTO containing a list of all the users.
    • userExistsInFridge

      public boolean userExistsInFridge(Long fridgeId, String username)
      This method checks whether the effected user exists.
      Parameters:
      fridgeId - The id of the fridge, given as a Long object.
      username - The username of the user the action is being performed on, given as a String.
      Returns:
      Status of whether user exists in fridge, true, or not, false