Test Input Form reload data
This commit is contained in:
@@ -22,26 +22,58 @@ export default function InputForm(p) {
|
|||||||
const [endDate, setEndDate] = useState(endDateParam);
|
const [endDate, setEndDate] = useState(endDateParam);
|
||||||
const [courseName, setCourseName] = useState(courseNameParam);
|
const [courseName, setCourseName] = useState(courseNameParam);
|
||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
|
const [moduleInfos, setModuleInfos] = useState([])
|
||||||
|
const [checkedSelected, setCheckedSelected] = useState(new Array(100).fill(false))
|
||||||
|
const [activatedSelected, setActivatedSelected] = useState(new Array(100).fill(false))
|
||||||
|
|
||||||
async function getAllUsers() {
|
async function getAllUsers() {
|
||||||
let sessionid = localStorage.getItem("sessionid");
|
let sessionid = localStorage.getItem("sessionid");
|
||||||
let url = "http://localhost:8080/users/all?sessionid=" + sessionid;
|
let url = "http://localhost:8080/users/all?sessionid=" + sessionid;
|
||||||
|
|
||||||
|
|
||||||
try {
|
await fetch(url).then(response => response.json()).then(async user => {
|
||||||
await fetch(url).then(response => response.json()).then(user => setUsers(user));
|
setUsers(user)
|
||||||
}
|
let mURL = "http://localhost:8080/module/suid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid") + "&userid=";
|
||||||
catch(e)
|
for(let i = 0; i < user.length; i++)
|
||||||
{
|
{
|
||||||
router.push("/")
|
mURL += user[i].id;
|
||||||
|
if(i < user.length - 1)
|
||||||
|
{
|
||||||
|
mURL += "a";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetch(mURL).then(result => result.json()).then(m => {
|
||||||
|
let temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < user.length; i++)
|
||||||
|
{
|
||||||
|
temp.push(m[i] != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
setCheckedSelected(temp);
|
||||||
|
|
||||||
|
temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < user.length; i++)
|
||||||
|
{
|
||||||
|
temp.push(m[i] != null && m[i].activated === 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
setActivatedSelected(temp);
|
||||||
|
|
||||||
|
setModuleInfos(m);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
userModuleMapping.clear()
|
getAllUsers()
|
||||||
getAllUsers();
|
userModuleMapping.clear();
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
async function onCreateClicked() {
|
async function onCreateClicked() {
|
||||||
let startSplit = startDate.split("-");
|
let startSplit = startDate.split("-");
|
||||||
let endSplit = endDate.split("-");
|
let endSplit = endDate.split("-");
|
||||||
@@ -76,16 +108,16 @@ export default function InputForm(p) {
|
|||||||
method: method,
|
method: method,
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify(json)
|
body: JSON.stringify(json)
|
||||||
}).then(response => response.json()).then(semester => {tempsid = semester.id});
|
}).then(response => response.json()).then(semester => {
|
||||||
|
tempsid = semester.id
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
if(method === "POST")
|
if (method === "POST") {
|
||||||
{
|
|
||||||
semesterid = tempsid;
|
semesterid = tempsid;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let [key, value] of userModuleMapping)
|
for (let [key, value] of userModuleMapping) {
|
||||||
{
|
|
||||||
let json1 = {
|
let json1 = {
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"userid": value.getUserid(),
|
"userid": value.getUserid(),
|
||||||
@@ -94,8 +126,7 @@ export default function InputForm(p) {
|
|||||||
"activated": value.getActivated()
|
"activated": value.getActivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value.getChecked())
|
if (value.getChecked()) {
|
||||||
{
|
|
||||||
await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
|
await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
@@ -107,76 +138,109 @@ export default function InputForm(p) {
|
|||||||
router.back();
|
router.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserModuleInfo
|
class UserModuleInfo {
|
||||||
{
|
constructor() {
|
||||||
constructor()
|
|
||||||
{
|
|
||||||
this.moduleName = "";
|
this.moduleName = "";
|
||||||
this.userid = 0;
|
this.userid = 0;
|
||||||
this.activated = 0
|
this.activated = 0
|
||||||
this.checked = false
|
this.checked = false
|
||||||
}
|
}
|
||||||
|
|
||||||
getModuleName() {return this.moduleName}
|
getModuleName() {
|
||||||
getUserid() {return this.userid}
|
return this.moduleName
|
||||||
getActivated() {return this.activated}
|
|
||||||
getChecked() {return this.checked}
|
|
||||||
|
|
||||||
setModuleName(name) {this.moduleName = name}
|
|
||||||
setUserid(id) {this.userid = id}
|
|
||||||
setActivated(a) {this.activated = a}
|
|
||||||
setChecked(b) {this.checked = b}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onModuleClicked(user, module) {
|
getUserid() {
|
||||||
|
return this.userid
|
||||||
|
}
|
||||||
|
|
||||||
if(userModuleMapping.has(user.id))
|
getActivated() {
|
||||||
{
|
return this.activated
|
||||||
|
}
|
||||||
|
|
||||||
|
getChecked() {
|
||||||
|
return this.checked
|
||||||
|
}
|
||||||
|
|
||||||
|
setModuleName(name) {
|
||||||
|
this.moduleName = name
|
||||||
|
}
|
||||||
|
|
||||||
|
setUserid(id) {
|
||||||
|
this.userid = id
|
||||||
|
}
|
||||||
|
|
||||||
|
setActivated(a) {
|
||||||
|
this.activated = a
|
||||||
|
}
|
||||||
|
|
||||||
|
setChecked(b) {
|
||||||
|
this.checked = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onModuleClicked(user, module, index) {
|
||||||
|
|
||||||
|
if (userModuleMapping.has(user.id)) {
|
||||||
let temp = userModuleMapping.get(user.id)
|
let temp = userModuleMapping.get(user.id)
|
||||||
temp.setModuleName(module)
|
temp.setModuleName(module)
|
||||||
temp.setUserid(user.id)
|
temp.setUserid(user.id)
|
||||||
console.log("test")
|
console.log("test")
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
let temp = new UserModuleInfo()
|
let temp = new UserModuleInfo()
|
||||||
temp.setModuleName(module)
|
temp.setModuleName(module)
|
||||||
temp.setUserid(user.id)
|
temp.setUserid(user.id)
|
||||||
userModuleMapping.set(user.id, temp)
|
userModuleMapping.set(user.id, temp)
|
||||||
console.log("test1")
|
console.log("test1")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSelectedCheckBox(user, state)
|
function onSelectedCheckBox(user, state, index) {
|
||||||
{
|
if (userModuleMapping.has(user.id)) {
|
||||||
if(userModuleMapping.has(user.id))
|
|
||||||
{
|
|
||||||
userModuleMapping.get(user.id).setChecked(state.target.checked);
|
userModuleMapping.get(user.id).setChecked(state.target.checked);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
let temp = new UserModuleInfo()
|
let temp = new UserModuleInfo()
|
||||||
temp.setChecked(state.target.checked)
|
temp.setChecked(state.target.checked)
|
||||||
temp.setUserid(user.id)
|
temp.setUserid(user.id)
|
||||||
userModuleMapping.set(user.id, temp)
|
userModuleMapping.set(user.id, temp)
|
||||||
}
|
}
|
||||||
|
let temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < checkedSelected.length; i++)
|
||||||
|
{
|
||||||
|
temp.push(checkedSelected[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onActivatedCheckBox(user, state)
|
temp[index] = state.target.checked;
|
||||||
{
|
|
||||||
if(userModuleMapping.has(user.id))
|
setCheckedSelected(temp);
|
||||||
{
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function onActivatedCheckBox(user, state, index) {
|
||||||
|
if (userModuleMapping.has(user.id)) {
|
||||||
let t = state.target.checked ? 1 : 0;
|
let t = state.target.checked ? 1 : 0;
|
||||||
userModuleMapping.get(user.id).setActivated(t);
|
userModuleMapping.get(user.id).setActivated(t);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
let temp = new UserModuleInfo()
|
let temp = new UserModuleInfo()
|
||||||
let t = state.target.checked ? 1 : 0;
|
let t = state.target.checked ? 1 : 0;
|
||||||
temp.setActivated(t)
|
temp.setActivated(t)
|
||||||
temp.setUserid(user.id)
|
temp.setUserid(user.id)
|
||||||
userModuleMapping.set(user.id, temp)
|
userModuleMapping.set(user.id, temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < checkedSelected.length; i++)
|
||||||
|
{
|
||||||
|
temp.push(activatedSelected[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp[index] = state.target.checked;
|
||||||
|
|
||||||
|
setActivatedSelected(temp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -247,24 +311,28 @@ export default function InputForm(p) {
|
|||||||
}}>Modul
|
}}>Modul
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
{users.map(user => (
|
{users.map((user, i) => (
|
||||||
<tr>
|
<tr>
|
||||||
|
|
||||||
<td><div style={{
|
<td>
|
||||||
|
<div style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
}}><input type="checkbox" onChange={(e) => {
|
}}><input type="checkbox" onChange={(e) => {
|
||||||
onSelectedCheckBox(user, e)
|
onSelectedCheckBox(user, e, i)
|
||||||
}}/></div></td>
|
}} checked={checkedSelected[i]}/></div>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td><div style={{
|
<td>
|
||||||
|
<div style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
}}><input type="checkbox" onChange={(e) => {
|
}}><input type="checkbox" onChange={(e) => {
|
||||||
onActivatedCheckBox(user, e);
|
onActivatedCheckBox(user, e, i);
|
||||||
}}/></div></td>
|
}} checked={activatedSelected[i]}/></div>
|
||||||
|
</td>
|
||||||
<td style={{textAlign: "center"}}>{user.firstName + " " + user.lastName}</td>
|
<td style={{textAlign: "center"}}>{user.firstName + " " + user.lastName}</td>
|
||||||
<select id={"userSelect"} name={"userSelect"} className={"box-shadow selector"}
|
<select id={"userSelect"} name={"userSelect"} className={"box-shadow selector"}
|
||||||
multiple={false} style={{
|
multiple={false} style={{
|
||||||
@@ -272,8 +340,8 @@ export default function InputForm(p) {
|
|||||||
marginTop: 10,
|
marginTop: 10,
|
||||||
padding: "5px 2px"
|
padding: "5px 2px"
|
||||||
}} onChange={(e) => {
|
}} onChange={(e) => {
|
||||||
onModuleClicked(user, e.target.value)
|
onModuleClicked(user, e.target.value, i)
|
||||||
}}>
|
}} value={moduleInfos[i] != null ? moduleInfos[i].name : "Please Select"}>
|
||||||
<option value={"Please Select"}>Please Select</option>
|
<option value={"Please Select"}>Please Select</option>
|
||||||
<option value={"Programmieren"}>Programmieren</option>
|
<option value={"Programmieren"}>Programmieren</option>
|
||||||
<option value={"BWL"}>BWL</option>
|
<option value={"BWL"}>BWL</option>
|
||||||
|
|||||||
@@ -8,16 +8,6 @@ export default function CreateSemester()
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
let {courseName, startDate, endDate} = router.query;
|
let {courseName, startDate, endDate} = router.query;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let checkURL = "http://localhost:8080/users/check?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
try {
|
|
||||||
fetch(checkURL).then(r => console.log(r))
|
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
router.push("/")
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"normal-centered"}>
|
<div className={"normal-centered"}>
|
||||||
|
|||||||
@@ -13,14 +13,11 @@ export default function SemesterOverview(p)
|
|||||||
{
|
{
|
||||||
let urlTest = "http://localhost:8080/semester/all?sessionid=" + localStorage.getItem("sessionid");
|
let urlTest = "http://localhost:8080/semester/all?sessionid=" + localStorage.getItem("sessionid");
|
||||||
|
|
||||||
try {
|
|
||||||
await fetch(urlTest).then(response => response.json()).then(s => {
|
await fetch(urlTest).then(response => response.json()).then(s => {
|
||||||
setEntries(s)
|
setEntries(s)
|
||||||
})
|
})
|
||||||
} catch(e)
|
|
||||||
{
|
|
||||||
router.push("/")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClickSemester(e, m)
|
function onClickSemester(e, m)
|
||||||
@@ -33,6 +30,7 @@ export default function SemesterOverview(p)
|
|||||||
|
|
||||||
function onClickNewSemester()
|
function onClickNewSemester()
|
||||||
{
|
{
|
||||||
|
localStorage.setItem("currentsid", 0);
|
||||||
router.push("/createSemester");
|
router.push("/createSemester");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,14 +87,7 @@ export default function SemesterOverview(p)
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSemesters();
|
getSemesters();
|
||||||
let checkURL = "http://localhost:8080/users/check?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
try {
|
|
||||||
fetch(checkURL).then(r => console.log(r))
|
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
router.push("/")
|
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+134469
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ import com.example.backend.anwprj.Module.Module;
|
|||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DataBaseHandler
|
public class DataBaseHandler
|
||||||
@@ -423,12 +424,35 @@ public class DataBaseHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Module getModulesBySemesterUserID(int userid, int semesterid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid);
|
||||||
|
return resultSetToModule(rs);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return new Module(-1, 0, 0, "", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Module updateModule(Module m)
|
public Module updateModule(Module m)
|
||||||
{
|
{
|
||||||
System.out.println(m.getActivated());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
System.out.println(m.getId());
|
||||||
|
Module module = getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
||||||
|
if(module == null)
|
||||||
|
{
|
||||||
|
addModule(m);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("test");
|
||||||
st.executeUpdate("update modules set activated=" + m.getActivated() + " where userid=" + m.getUserid() + " and semesterid=" + m.getSemesterId() + " and name='" + m.getName() + "'");
|
st.executeUpdate("update modules set activated=" + m.getActivated() + " where userid=" + m.getUserid() + " and semesterid=" + m.getSemesterId() + " and name='" + m.getName() + "'");
|
||||||
|
}
|
||||||
|
|
||||||
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
||||||
}
|
}
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class ModuleController {
|
public class ModuleController
|
||||||
|
{
|
||||||
private final DataBaseHandler db;
|
private final DataBaseHandler db;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -40,14 +44,16 @@ public class ModuleController {
|
|||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@GetMapping("/module/id")
|
@GetMapping("/module/id")
|
||||||
public ResponseEntity<Module[]> getModules(
|
public ResponseEntity<Module[]> getModules(
|
||||||
@RequestParam(name="sessionid") String sessionID) {
|
@RequestParam(name = "sessionid") String sessionID)
|
||||||
|
{
|
||||||
|
|
||||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
Module[] modules = db.getModules(user.getId());
|
Module[] modules = db.getModules(user.getId());
|
||||||
if (modules != null) {
|
if (modules != null)
|
||||||
|
{
|
||||||
return new ResponseEntity<>(modules, HttpStatus.OK);
|
return new ResponseEntity<>(modules, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,13 +63,43 @@ public class ModuleController {
|
|||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/module/suid")
|
||||||
|
public ResponseEntity<Module[]> getModulesBySemesterUserID(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name = "userid") String userid, @RequestParam(name = "semesterid") int semesterid)
|
||||||
|
{
|
||||||
|
User user = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||||
|
String[] userIDSSplit = userid.split("a");
|
||||||
|
int[] userIDS = new int[userIDSSplit.length];
|
||||||
|
for(int i = 0; i < userIDS.length; i++)
|
||||||
|
{
|
||||||
|
userIDS[i] = Integer.parseInt(userIDSSplit[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user != null && user.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
|
List<Module> result = new ArrayList<>();
|
||||||
|
|
||||||
|
for(int i = 0; i < userIDS.length; i++)
|
||||||
|
{
|
||||||
|
result.add(db.getModulesBySemesterUserID(userIDS[i], semesterid));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(result.toArray(new Module[0]), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@GetMapping("/module/all")
|
@GetMapping("/module/all")
|
||||||
public ResponseEntity<Module[]> getModule(@RequestParam(name="sessionid") String sessionid) {
|
public ResponseEntity<Module[]> getModule(@RequestParam(name = "sessionid") String sessionid)
|
||||||
|
{
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||||
|
|
||||||
if(u != null) {
|
if (u != null)
|
||||||
if(u.getPermissions() == UserPermissions.admin.getValue()) {
|
{
|
||||||
|
if (u.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
return new ResponseEntity<>(db.getAllModules(), HttpStatus.OK);
|
return new ResponseEntity<>(db.getAllModules(), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,12 +109,15 @@ public class ModuleController {
|
|||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PostMapping("/module")
|
@PostMapping("/module")
|
||||||
public ResponseEntity<Module> addModule(@RequestBody Module module, @RequestParam(name="sessionid") String sessionID) {
|
public ResponseEntity<Module> addModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
||||||
|
{
|
||||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
if(user.getPermissions() == UserPermissions.admin.getValue()) {
|
if (user.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
Module m = db.addModule(module);
|
Module m = db.addModule(module);
|
||||||
if(m != null) {
|
if (m != null)
|
||||||
|
{
|
||||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
return new ResponseEntity<>(m, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,12 +130,15 @@ public class ModuleController {
|
|||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PutMapping("/module")
|
@PutMapping("/module")
|
||||||
public ResponseEntity<Module> updateModule(@RequestBody Module module, @RequestParam(name="sessionid") String sessionID) {
|
public ResponseEntity<Module> updateModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
||||||
|
{
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
if(u != null && u.getPermissions() == UserPermissions.admin.getValue()) {
|
if (u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
Module m = db.updateModule(module);
|
Module m = db.updateModule(module);
|
||||||
|
|
||||||
if(m != null) {
|
if (m != null)
|
||||||
|
{
|
||||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
return new ResponseEntity<>(m, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,9 +150,11 @@ public class ModuleController {
|
|||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@DeleteMapping("/module")
|
@DeleteMapping("/module")
|
||||||
public void deleteModule(@RequestParam(name="sessionid") String sessionid, @RequestParam(name="id") int id) {
|
public void deleteModule(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name = "id") int id)
|
||||||
|
{
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||||
if(u != null && u.getPermissions() == UserPermissions.admin.getValue()) {
|
if (u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
db.deleteModule(id);
|
db.deleteModule(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user