Class FridgeService
java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.service.fridge.FridgeService
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addUserToFridge
(FridgeUserDTO fridgeUserDTO, String userTryingToAdd) This method adds a user to a given fridge.void
createFridge
(String fridgeName, String username) This method creates a new fridge and a new fridge member entry for a given user.void
deleteUserFromFridge
(FridgeUserDTO fridgeUserDTO, String userTryingToRemove) This method removes a user from a given fridge.void
initializeFridge
(String username) This method creates a new fridge and a new fridge member entry for a given user.retrieveFridgeIdsByUsername
(String username) This method retrieves all the fridge ids for a given user.retrieveFridgesByUsername
(String username) This method retrieves all the fridge ids for a given user.retrieveMembersByFridgeId
(Long fridgeId, String username) This method retrieves all the users for a given fridge.void
updateFridgeName
(FridgeDTO fridgeDTO, String userTryingToUpdate) This method updates fridge's name.void
updateUserFromFridge
(FridgeUserDTO fridgeUserDTO, String userTryingToUpdate) This method updates a user from a given fridge.boolean
userExistsInFridge
(Long fridgeId, String username) This method checks whether the effected user exists.
-
Constructor Details
-
FridgeService
public FridgeService()
-
-
Method Details
-
initializeFridge
This method creates a new fridge and a new fridge member entry for a given user.- Specified by:
initializeFridge
in interfaceIFridgeService
- Parameters:
username
- The username of the user, given as a String
-
createFridge
This method creates a new fridge and a new fridge member entry for a given user.- Specified by:
createFridge
in interfaceIFridgeService
- 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
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
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
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
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
This method retrieves all the users for a given fridge.- Specified by:
retrieveMembersByFridgeId
in interfaceIFridgeService
- 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
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
-