Implement admin and user sidebars with routing and styling updates
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
|
||||
import com.jambotronGroup.jambotron.model.Tutorial;
|
||||
import com.jambotronGroup.jambotron.model.User;
|
||||
import com.jambotronGroup.jambotron.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -8,8 +9,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
@CrossOrigin(origins = "${app.origin}", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@@ -35,4 +35,31 @@ public class UsersController {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("users/{id}")
|
||||
public ResponseEntity<?> updateUserRoles(@PathVariable("id") long id, @RequestBody User user) {
|
||||
Optional<User> userData = userRepository.findById(id);
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
if (userData.isPresent()) {
|
||||
User servUser = userData.get();
|
||||
if(user.getRoles().size() > 0)
|
||||
servUser.setRoles(user.getRoles());
|
||||
else {
|
||||
map.put("status", 0);
|
||||
map.put("message", "User must have at least one role");
|
||||
return new ResponseEntity<>(map, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
servUser = userRepository.save(servUser);
|
||||
} catch (Exception e) {
|
||||
|
||||
map.put("status", 0);
|
||||
map.put("message", e.getMessage());
|
||||
return new ResponseEntity<>(map,HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
return new ResponseEntity<>(servUser, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user