Class GroupService
java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.group.GroupService
Service for groups
- Version:
- 1.3
- Author:
- Anders Austlid, Birk, Pedro
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFridgeToGroup
(long fridgeId, long groupId) Adds a group to a fridgecreateGroup
(Group group) Creates a new groupfindPrimaryUserGroupAssoForUser
(String username) Finds the primary group for a usergetGroupById
(long id) Gets a group by its idgetGroupByLinkCode
(String linkCode) Gets a group by its link codegetGroupByName
(String name) Gets a group by its namegetLevelByGroupId
(long id) Gets the level of a groupgetProgressOfLevel
(long id) Returns the progress of the level for the group identified by the given ID.getUserGroupAsso
(String username, Long groupId) Gets a user group associationgetUserGroupAssoAuthority
(String username, long groupId) Gets the authority of a user group associationgetUserGroupAssoByUserName
(String username) Gets all user group associations for a userboolean
isUserAssociatedWithGroup
(String username, Long groupId) Checks if a user is associated with a groupOpenOrCloseGroup
(long id) Updates the open/closed status of the group with the specified ID.boolean
removeUserFromGroup
(UserGroupAsso userGroup) removes user_group relatioonsetLevelByGroupId
(long id, long exp) Sets the level of the group identified by the given ID to the level corresponding to the given experience points.updateGroup
(Group group) Updates a groupupdateUserGroupAsso
(UserGroupAsso userGroupAsso) Updates a user group association
-
Constructor Details
-
GroupService
public GroupService()
-
-
Method Details
-
getGroupByName
Gets a group by its name- Parameters:
name
- the name of the group- Returns:
- an optional containing the group if it exists
-
getGroupById
Gets a group by its id- Parameters:
id
- the id of the group- Returns:
- an optional containing the group if it exists
-
createGroup
Creates a new group- Parameters:
group
- the group to create the group must not already exist the group must have a name- Returns:
- the created group
-
getLevelByGroupId
Gets the level of a group- Parameters:
id
- the id of the group- Returns:
- the level of the group
-
setLevelByGroupId
Sets the level of the group identified by the given ID to the level corresponding to the given experience points.- Parameters:
id
- the ID of the group to updateexp
- the new experience points of the group- Returns:
- an Optional containing the updated Group, or an empty Optional if no Group with the given ID was found
-
getProgressOfLevel
Returns the progress of the level for the group identified by the given ID.- Parameters:
id
- the ID of the group to query- Returns:
- an Optional containing the progress of the current level as a percentage, or an empty Optional if no Group with the given ID was found
-
OpenOrCloseGroup
Updates the open/closed status of the group with the specified ID.- Parameters:
id
- the ID of the group to update- Returns:
- an Optional with a Boolean value indicating whether the operation was successful
-
addFridgeToGroup
public void addFridgeToGroup(long fridgeId, long groupId) Adds a group to a fridge- Parameters:
fridgeId
- the id of the fridgegroupId
- the id of the group
-
updateGroup
Updates a group- Parameters:
group
- the group to update- Returns:
- an optional containing the updated group
-
getGroupByLinkCode
Gets a group by its link code- Parameters:
linkCode
- the link code of the group- Returns:
- an optional containing the group if it exists
-
isUserAssociatedWithGroup
Checks if a user is associated with a group- Parameters:
username
- the username of the usergroupId
- the id of the group- Returns:
- true if the user is associated with the group, false otherwise
-
updateUserGroupAsso
Updates a user group association- Parameters:
userGroupAsso
- the user group association to update- Returns:
- the updated user group association
-
findPrimaryUserGroupAssoForUser
Finds the primary group for a user- Parameters:
username
- the username of the user- Returns:
- an optional containing the primary group if it exists
-
getUserGroupAsso
Gets a user group association- Parameters:
username
- the username of the usergroupId
- the id of the group- Returns:
-
getUserGroupAssoAuthority
Gets the authority of a user group association- Parameters:
username
- the username of the usergroupId
- the id of the group- Returns:
- the authority of the user group association
-
getUserGroupAssoByUserName
Gets all user group associations for a user- Parameters:
username
- the username of the user- Returns:
- a list of all user group associations for the user
-
removeUserFromGroup
removes user_group relatioon- Parameters:
userGroup
- the user group association to remove- Returns:
- true if the user is the owner of the group, false otherwise
-