Class FileUserAdminRestController

java.lang.Object
se.bth.pulse.controller.FileUserAdminRestController

@RestController public class FileUserAdminRestController extends Object
This class is a rest controller that serves the file page. The page is only accessible if the user is logged in as an admin. It is used to upload a csv file containing users.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Object>
    check(String file, jakarta.servlet.http.HttpServletRequest request)
    This method is used to check if the csv file is valid then convert it to a list of users.
    org.springframework.http.ResponseEntity<Object>
    upload(List<User> userList)
    Takes a list of users and saves them to the database.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • check

      @PostMapping("/api/admin/file/check") public org.springframework.http.ResponseEntity<Object> check(@RequestBody String file, jakarta.servlet.http.HttpServletRequest request)
      This method is used to check if the csv file is valid then convert it to a list of users. The list of users is then returned as a response entity. The response entity is represented as a json object.
      Parameters:
      file - - the csv file containing the users
      request - - used to get the csrf token
      Returns:
      ResponseEntity - the response entity containing the users if the file is valid, an error message otherwise. It is represented as a json object.
    • upload

      @PostMapping(value="/api/admin/file/upload", consumes="application/json") @Transactional(rollbackFor=java.lang.Exception.class) public org.springframework.http.ResponseEntity<Object> upload(@RequestBody List<User> userList)
      Takes a list of users and saves them to the database. The users are created with a random password and the role "default". The users are also sent an email with their password. The method is transactional, meaning that if an error occurs during the saving of the users, the database will roll back to the state before the method was called.
      Parameters:
      userList - - the list of users to be saved to the database
      Returns:
      ResponseEntity - Contains the status code of the request