Package se.bth.pulse.controller
Class FileUserAdminRestController
java.lang.Object
se.bth.pulse.controller.FileUserAdminRestController
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 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 usersrequest
- - 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
-