Class UserController
java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.user.UserController
The user controller is responsible for handling requests related to users.
It uses the user service to handle the requests.
- Version:
- 1.2
- Author:
- Birk
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
addAllergyToUser
(AllergyRequest allergyRequest, org.springframework.security.core.Authentication authentication) Adds the specified allergy to the user with the given username.org.springframework.http.ResponseEntity<String>
deleteAllergyFromUser
(AllergyRequest allergyRequest, org.springframework.security.core.Authentication authentication) Deletes the specified allergy from the user with the given username.org.springframework.http.ResponseEntity<User>
Get a user from the database.org.springframework.http.ResponseEntity<User>
register
(RegisterUserRequest user) create a new user in the database uses the user serviceorg.springframework.http.ResponseEntity<User>
updateUser
(String username, UpdateUserRequest updateUser, org.springframework.security.core.Authentication authentication) Update a user in the database.
-
Constructor Details
-
UserController
public UserController()
-
-
Method Details
-
register
@PostMapping("/register") public org.springframework.http.ResponseEntity<User> register(@RequestBody RegisterUserRequest user) create a new user in the database uses the user service- Parameters:
user
- The user to be registered.
-
getUser
@GetMapping("/get/{username}") public org.springframework.http.ResponseEntity<User> getUser(@PathVariable String username, org.springframework.security.core.Authentication authentication) Get a user from the database.- Parameters:
username
- The username of the user to be fetched.authentication
- The authentication object of the user.- Returns:
- The user with the given username.
-
addAllergyToUser
@PostMapping("/addAllergy") public org.springframework.http.ResponseEntity<String> addAllergyToUser(@RequestBody AllergyRequest allergyRequest, org.springframework.security.core.Authentication authentication) Adds the specified allergy to the user with the given username.- Parameters:
allergyRequest
- the request object containing the username and allergy nameauthentication
- The authentication object of the user.- Returns:
- a ResponseEntity with a boolean indicating whether the operation was successful
-
deleteAllergyFromUser
@DeleteMapping("/deleteAllergy") public org.springframework.http.ResponseEntity<String> deleteAllergyFromUser(@RequestBody AllergyRequest allergyRequest, org.springframework.security.core.Authentication authentication) Deletes the specified allergy from the user with the given username.- Parameters:
allergyRequest
- the request object containing the username and allergy nameauthentication
- The authentication object of the user.- Returns:
- a ResponseEntity with a boolean indicating whether the operation was successful
-
updateUser
@PutMapping("/update/{username}") public org.springframework.http.ResponseEntity<User> updateUser(@PathVariable String username, @RequestBody UpdateUserRequest updateUser, org.springframework.security.core.Authentication authentication) Update a user in the database.- Parameters:
username
- The username of the user to be updated.updateUser
- The new values for the user.authentication
- The authentication object of the user.- Returns:
- The updated user.
-