Class GroupController
java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.group.GroupController
Controller for groups API, providing endpoints for group management
- Version:
- 2.0
- Author:
- Anders Austlid, Pedro Cardona, Birk
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?>
addConnection
(GroupConnectionRequest groupConnectionRequest, org.springframework.security.core.Authentication auth) Handles the HTTP POST request to add a new connection between a user and a group.org.springframework.http.ResponseEntity<?>
changeAuthority
(ChangeAuthorityRequest authorityRequest, org.springframework.security.core.Authentication auth) Changes the authority level of a user in a group.org.springframework.http.ResponseEntity<Boolean>
changeOpenValue
(long groupId, org.springframework.security.core.Authentication auth) Updates the open/closed status of the group with the specified ID.org.springframework.http.ResponseEntity<?>
createGroup
(GroupRequest groupRequest, org.springframework.security.core.Authentication auth) Creates a new grouporg.springframework.http.ResponseEntity<List<UserGroupAsso>>
getAllGroupsByUser
(org.springframework.security.core.Authentication auth) Handles the HTTP DELETE request to remove a user from a group.org.springframework.http.ResponseEntity<?>
getGroupById
(long groupId, org.springframework.security.core.Authentication auth) Gets a group by its idorg.springframework.http.ResponseEntity<Long>
getGroupLevel
(long groupId, org.springframework.security.core.Authentication auth) Gets the level of a grouporg.springframework.http.ResponseEntity<Integer>
getProgressOfLevel
(long groupId, org.springframework.security.core.Authentication auth) Returns the progress of the level for the group identified by the given ID.org.springframework.http.ResponseEntity<?>
markNewPrimaryGroup
(long newPrimaryGroupId, org.springframework.security.core.Authentication auth) Handles the HTTP PUT request to change the primary group of a user.org.springframework.http.ResponseEntity<?>
removeUserFromGroup
(long groupId, String username, org.springframework.security.core.Authentication auth) Handles the HTTP DELETE request to remove a user from a group.
-
Constructor Details
-
GroupController
public GroupController()
-
-
Method Details
-
getGroupById
@GetMapping("/{groupId}") public org.springframework.http.ResponseEntity<?> getGroupById(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication auth) Gets a group by its id- Parameters:
groupId
- the id of the groupauth
- the authentication of the user- Returns:
- a ResponseEntity containing the group if it exists, or a 404 if it doesn't
-
createGroup
@PostMapping("/group") public org.springframework.http.ResponseEntity<?> createGroup(@RequestBody GroupRequest groupRequest, org.springframework.security.core.Authentication auth) Creates a new group- Parameters:
groupRequest
- the group to createauth
- the authentication of the user- Returns:
- a ResponseEntity containing the created group if it was created successfully, or a 400 if the group name is invalid or already exists, or if the username is invalid
-
getGroupLevel
@GetMapping("/{groupId}/level") public org.springframework.http.ResponseEntity<Long> getGroupLevel(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication auth) Gets the level of a group- Parameters:
groupId
- the id of the groupauth
- the authentication of the user- Returns:
- a ResponseEntity containing the level of the group if it exists, or a 404 if it doesn't
-
getProgressOfLevel
@GetMapping("/{groupId}/progress") public org.springframework.http.ResponseEntity<Integer> getProgressOfLevel(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication auth) Returns the progress of the level for the group identified by the given ID. Returns a ResponseEntity containing the progress of the current level as a percentage, or a 404 Not Found response if no Group with the given ID was found.- Parameters:
groupId
- the ID of the group to queryauth
- the Authentication object containing the user's credentials- Returns:
- a ResponseEntity containing the progress of the current level as a percentage, or a 404 Not Found response if no Group with the given ID was found
-
changeOpenValue
@PutMapping("/{groupId}/changeOpen") public org.springframework.http.ResponseEntity<Boolean> changeOpenValue(@PathVariable("groupId") long groupId, org.springframework.security.core.Authentication auth) Updates the open/closed status of the group with the specified ID.- Parameters:
groupId
- the ID of the group to updateauth
- the authentication of the user- Returns:
- a ResponseEntity with a Boolean value indicating whether the operation was successful
-
markNewPrimaryGroup
@PutMapping("/markNewPrimary/{newPrimaryGroupId}") public org.springframework.http.ResponseEntity<?> markNewPrimaryGroup(@PathVariable("newPrimaryGroupId") long newPrimaryGroupId, org.springframework.security.core.Authentication auth) Handles the HTTP PUT request to change the primary group of a user.- Parameters:
newPrimaryGroupId
- the ID of the new primary groupauth
- the authentication of the user- Returns:
- a ResponseEntity object containing an HTTP status code and the updated UserGroupAsso object, or a ResponseEntity object with an HTTP status code indicating that the request was not successful
-
addConnection
@PostMapping("/connection") public org.springframework.http.ResponseEntity<?> addConnection(@RequestBody GroupConnectionRequest groupConnectionRequest, org.springframework.security.core.Authentication auth) Handles the HTTP POST request to add a new connection between a user and a group.- Parameters:
groupConnectionRequest
- the request object containing the username and link code of the user and group to be connectedauth
- the authentication of the user- Returns:
- a ResponseEntity object containing an HTTP status code and the newly created UserGroupAsso object, or a ResponseEntity object with an HTTP status code indicating that the request was not successful
-
changeAuthority
@PutMapping("/groupAuthority") public org.springframework.http.ResponseEntity<?> changeAuthority(@RequestBody ChangeAuthorityRequest authorityRequest, org.springframework.security.core.Authentication auth) Changes the authority level of a user in a group.- Parameters:
authorityRequest
- the request object containing the username and group ID of the user to change the authority ofauth
- the authentication of the user- Returns:
- a ResponseEntity object containing the updated UserGroupAsso object and an HTTP status code of 200, or a ResponseEntity object with an HTTP status code of 403 if the user is not authorized to change the authority, or a ResponseEntity object with an HTTP status code of 404 if the group or user does not exist
-
getAllGroupsByUser
@GetMapping("/") public org.springframework.http.ResponseEntity<List<UserGroupAsso>> getAllGroupsByUser(org.springframework.security.core.Authentication auth) Handles the HTTP DELETE request to remove a user from a group.- Parameters:
auth
- the authentication object containing the username of the user- Returns:
- a ResponseEntity object containing the list of groups the user is associated with and an HTTP status code of 200,
-
removeUserFromGroup
@DeleteMapping("/removeUser/{groupId}/{username}") public org.springframework.http.ResponseEntity<?> removeUserFromGroup(@PathVariable("groupId") long groupId, @PathVariable("username") String username, org.springframework.security.core.Authentication auth) Handles the HTTP DELETE request to remove a user from a group.- Parameters:
groupId
- the ID of the group to get the members ofusername
- the username of the user to remove from the groupauth
- the authentication object containing the username of the user- Returns:
- a ResponseEntity object containing the list of groups the user is associated with and an HTTP status code of 200,
-