Class UserController

java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.user.UserController

@RestController @RequestMapping("/api/user") public class UserController extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.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>
    getUser(String username, org.springframework.security.core.Authentication authentication)
    Get a user from the database.
    org.springframework.http.ResponseEntity<User>
    create a new user in the database uses the user service
    org.springframework.http.ResponseEntity<User>
    updateUser(String username, UpdateUserRequest updateUser, org.springframework.security.core.Authentication authentication)
    Update a user in the database.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 name
      authentication - 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 name
      authentication - 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.