Class GroupService

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

@Service public class GroupService extends Object
Service for groups
Version:
1.3
Author:
Anders Austlid, Birk, Pedro
  • Constructor Details

    • GroupService

      public GroupService()
  • Method Details

    • getGroupByName

      public Optional<Group> getGroupByName(String name)
      Gets a group by its name
      Parameters:
      name - the name of the group
      Returns:
      an optional containing the group if it exists
    • getGroupById

      public Optional<Group> getGroupById(long id)
      Gets a group by its id
      Parameters:
      id - the id of the group
      Returns:
      an optional containing the group if it exists
    • createGroup

      public Group createGroup(Group group)
      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

      public Optional<Long> getLevelByGroupId(long id)
      Gets the level of a group
      Parameters:
      id - the id of the group
      Returns:
      the level of the group
    • setLevelByGroupId

      public Optional<Group> setLevelByGroupId(long id, long exp)
      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 update
      exp - 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

      public Optional<Integer> getProgressOfLevel(long id)
      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

      public Optional<Boolean> OpenOrCloseGroup(long id)
      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 fridge
      groupId - the id of the group
    • updateGroup

      public Optional<Group> updateGroup(Group group)
      Updates a group
      Parameters:
      group - the group to update
      Returns:
      an optional containing the updated group
    • getGroupByLinkCode

      public Optional<Group> getGroupByLinkCode(String linkCode)
      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

      public boolean isUserAssociatedWithGroup(String username, Long groupId)
      Checks if a user is associated with a group
      Parameters:
      username - the username of the user
      groupId - the id of the group
      Returns:
      true if the user is associated with the group, false otherwise
    • updateUserGroupAsso

      public UserGroupAsso updateUserGroupAsso(UserGroupAsso userGroupAsso)
      Updates a user group association
      Parameters:
      userGroupAsso - the user group association to update
      Returns:
      the updated user group association
    • findPrimaryUserGroupAssoForUser

      public Optional<UserGroupAsso> findPrimaryUserGroupAssoForUser(String username)
      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

      public Optional<UserGroupAsso> getUserGroupAsso(String username, Long groupId)
      Gets a user group association
      Parameters:
      username - the username of the user
      groupId - the id of the group
      Returns:
    • getUserGroupAssoAuthority

      public String getUserGroupAssoAuthority(String username, long groupId)
      Gets the authority of a user group association
      Parameters:
      username - the username of the user
      groupId - the id of the group
      Returns:
      the authority of the user group association
    • getUserGroupAssoByUserName

      public List<UserGroupAsso> getUserGroupAssoByUserName(String username)
      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

      public boolean removeUserFromGroup(UserGroupAsso userGroup)
      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