Class UserController

java.lang.Object
no.idata1002.group19.web.api.UserController

@RestController @CrossOrigin public class UserController extends Object
Controller class responsible for providing RESTful services for the /users endpoint. Provides and specifies the functionality which are to be given to the client when using different HTTP request methods.
Since:
16.04.2023
Version:
16.04.2023
Author:
Group19
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<?>
    addUser(UserCredentials credentials)
    Adds a new user to the system using the UserService and returns an appropriate HTTP response.
    org.springframework.http.ResponseEntity<?>
    delete(long id)
    Deletes a user with the specified ID using the UserService and returns an appropriate HTTP response.
    org.springframework.http.ResponseEntity<?>
    getUserById(long id)
    Retrieves a user from userRepository and returns them as an HTTP response
    Retrieves a list of all users from the UserService and returns them as an HTTP response.
    org.springframework.http.ResponseEntity<?>
    update(long id, UserCredentials credentials)
    Updates a user with the specified ID using the UserService and returns an appropriate HTTP response.

    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

    • getUsers

      @GetMapping("/users") public Iterable<User> getUsers()
      Retrieves a list of all users from the UserService and returns them as an HTTP response.
      Returns:
      ResponseEntityinvalid input: '<'List> - an HTTP response containing a list of all users
    • getUserById

      @GetMapping("/users/{id}") public org.springframework.http.ResponseEntity<?> getUserById(@PathVariable long id)
      Retrieves a user from userRepository and returns them as an HTTP response
      Parameters:
      id - of the user that you want to get
      Returns:
      ResponseEntity.ok - and HTTP response containing the user.
    • addUser

      @PostMapping("/users") public org.springframework.http.ResponseEntity<?> addUser(@RequestBody UserCredentials credentials)
      Adds a new user to the system using the UserService and returns an appropriate HTTP response.
      Parameters:
      user - - the User object representing the user to add.
      Returns:
      ResponseEntity - an HTTP response indicating whether the user was added successfully.
    • update

      @PutMapping("/users/{id}") public org.springframework.http.ResponseEntity<?> update(@PathVariable long id, @RequestBody UserCredentials credentials)
      Updates a user with the specified ID using the UserService and returns an appropriate HTTP response.
      Parameters:
      id - - the ID of the user to update.
      user - - the User object representing the updated user.
      Returns:
      ResponseEntity - an HTTP response indicating whether the user was updated successfully.
    • delete

      @DeleteMapping("/users/{id}") public org.springframework.http.ResponseEntity<?> delete(@PathVariable long id)
      Deletes a user with the specified ID using the UserService and returns an appropriate HTTP response.
      Parameters:
      id - - the ID of the user to delete.
      Returns:
      ResponseEntity - an HTTP response indicating whether the user was deleted successfully.