Merge branch 'JonasTestBranch' into main
This commit is contained in:
commit
0c42a5820a
9 files changed
+138311
-127
No files matched your search
@@ -22,26 +22,87 @@ 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 [checkedSelected, setCheckedSelected] = useState(new Array(100).fill(false))
|
||||||
|
const [activatedSelected, setActivatedSelected] = useState(new Array(100).fill(false))
|
||||||
|
const [modulesNames, setModulesNames] = useState(new Array(100).fill("Please Select"))
|
||||||
|
|
||||||
async function getAllUsers() {
|
async function getAllUsers() {
|
||||||
|
console.log("update")
|
||||||
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);
|
||||||
|
|
||||||
|
if(m[i] != null) {
|
||||||
|
let tempModuleInfo = new UserModuleInfo();
|
||||||
|
tempModuleInfo.setModuleName(m[i].name);
|
||||||
|
tempModuleInfo.setActivated(m[i].activated);
|
||||||
|
tempModuleInfo.setChecked(true);
|
||||||
|
tempModuleInfo.setUserid(user[i].id)
|
||||||
|
userModuleMapping.set(user[i].id, tempModuleInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setActivatedSelected(temp);
|
||||||
|
|
||||||
|
temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < user.length; i++)
|
||||||
|
{
|
||||||
|
temp.push(m[i] == null ? "Please Select" : m[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
setModulesNames(temp);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
for(let i = 0; i < user.length; i++)
|
||||||
|
{
|
||||||
|
if(!userModuleMapping.has(user[i].id)) {
|
||||||
|
let tempModuleInfo = new UserModuleInfo();
|
||||||
|
tempModuleInfo.setModuleName("Please Select");
|
||||||
|
tempModuleInfo.setActivated(0);
|
||||||
|
tempModuleInfo.setChecked(false);
|
||||||
|
tempModuleInfo.setUserid(user[i].id)
|
||||||
|
userModuleMapping.set(user[i].id, tempModuleInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +137,17 @@ 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(),
|
||||||
@@ -93,90 +155,129 @@ export default function InputForm(p) {
|
|||||||
"name": value.getModuleName(),
|
"name": value.getModuleName(),
|
||||||
"activated": value.getActivated()
|
"activated": value.getActivated()
|
||||||
}
|
}
|
||||||
|
if (value.getChecked()) {
|
||||||
if(value.getChecked())
|
let updateURL = "http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid");
|
||||||
{
|
await fetch(updateURL, {
|
||||||
await fetch("http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid"), {
|
|
||||||
method: method,
|
method: method,
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify(json1)
|
body: JSON.stringify(json1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let deleteURL = "http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid") +
|
||||||
|
"&semesterid=" + semesterid +
|
||||||
|
"&userid=" + value.getUserid();
|
||||||
|
await fetch(deleteURL, {
|
||||||
|
method: "DELETE"
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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}
|
getUserid() {
|
||||||
setUserid(id) {this.userid = id}
|
return this.userid
|
||||||
setActivated(a) {this.activated = a}
|
}
|
||||||
setChecked(b) {this.checked = b}
|
|
||||||
|
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) {
|
function onModuleClicked(user, module, index) {
|
||||||
|
|
||||||
if(userModuleMapping.has(user.id))
|
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")
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
let temp = [];
|
||||||
|
|
||||||
|
for(let i = 0; i < modulesNames.length; i++)
|
||||||
{
|
{
|
||||||
let temp = new UserModuleInfo()
|
temp.push(modulesNames[i]);
|
||||||
temp.setModuleName(module)
|
|
||||||
temp.setUserid(user.id)
|
|
||||||
userModuleMapping.set(user.id, temp)
|
|
||||||
console.log("test1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp[index] = module;
|
||||||
|
|
||||||
|
setModulesNames(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp[index] = state.target.checked;
|
||||||
|
|
||||||
|
setCheckedSelected(temp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onActivatedCheckBox(user, state)
|
function onActivatedCheckBox(user, state, index) {
|
||||||
{
|
if (userModuleMapping.has(user.id)) {
|
||||||
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);
|
||||||
|
console.log(userModuleMapping.get(user.id).getActivated())
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
let temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < checkedSelected.length; i++)
|
||||||
{
|
{
|
||||||
let temp = new UserModuleInfo()
|
temp.push(activatedSelected[i]);
|
||||||
let t = state.target.checked ? 1 : 0;
|
|
||||||
temp.setActivated(t)
|
|
||||||
temp.setUserid(user.id)
|
|
||||||
userModuleMapping.set(user.id, temp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp[index] = state.target.checked;
|
||||||
|
|
||||||
|
setActivatedSelected(temp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -247,24 +348,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>
|
||||||
display: "flex",
|
<div style={{
|
||||||
flexDirection: "row",
|
display: "flex",
|
||||||
justifyContent: "center",
|
flexDirection: "row",
|
||||||
}}><input type="checkbox" onChange={(e) => {
|
justifyContent: "center",
|
||||||
onSelectedCheckBox(user, e)
|
}}><input type="checkbox" onChange={(e) => {
|
||||||
}}/></div></td>
|
onSelectedCheckBox(user, e, i)
|
||||||
|
}} checked={checkedSelected[i]}/></div>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td><div style={{
|
<td>
|
||||||
display: "flex",
|
<div style={{
|
||||||
flexDirection: "row",
|
display: "flex",
|
||||||
justifyContent: "center",
|
flexDirection: "row",
|
||||||
}}><input type="checkbox" onChange={(e) => {
|
justifyContent: "center",
|
||||||
onActivatedCheckBox(user, e);
|
}}><input type="checkbox" onChange={(e) => {
|
||||||
}}/></div></td>
|
onActivatedCheckBox(user, e, i);
|
||||||
|
}} 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 +377,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={modulesNames[i]}>
|
||||||
<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.
+138030
File diff suppressed because it is too large.
Load diff
@@ -43,7 +43,6 @@ public class DataBaseHandler
|
|||||||
} catch (SQLException e)
|
} catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("No Connection!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -357,11 +356,11 @@ public class DataBaseHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Module getModule(int userid, int semesterid, String name)
|
public Module getModule(int userid, int semesterid)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid + " and name='" + name + "'");
|
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid);
|
||||||
|
|
||||||
return resultSetToModule(rs);
|
return resultSetToModule(rs);
|
||||||
}
|
}
|
||||||
@@ -394,8 +393,8 @@ public class DataBaseHandler
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("insert into modules (userid, semesterid, name, activated) " +
|
st.executeUpdate("insert into modules (userid, semesterid, name, activated) " +
|
||||||
"Values (" + m.getUserid() + ", " + m.getSemesterId() + ", '" + m.getName() + "', " + m.getActivated() + ")");
|
"Values (" + m.getUserid() + ", " + m.getsemesterid() + ", '" + m.getName() + "', " + m.getActivated() + ")");
|
||||||
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
return getModule(m.getUserid(), m.getsemesterid());
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@@ -423,13 +422,36 @@ 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 {
|
||||||
st.executeUpdate("update modules set activated=" + m.getActivated() + " where userid=" + m.getUserid() + " and semesterid=" + m.getSemesterId() + " and name='" + m.getName() + "'");
|
Module module = getModule(m.getUserid(), m.getsemesterid());
|
||||||
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
if(module == null)
|
||||||
|
{
|
||||||
|
addModule(m);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
st.executeUpdate("update modules set activated=" + m.getActivated() + ", semesterid=" + m.getsemesterid() + ", name='" + m.getName() + "' where id=" + module.getid());
|
||||||
|
}
|
||||||
|
|
||||||
|
Module test = getModule(m.getUserid(), m.getsemesterid());
|
||||||
|
System.out.println(test.getActivated());
|
||||||
|
return test;
|
||||||
}
|
}
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@@ -437,10 +459,10 @@ public class DataBaseHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteModule(int id)
|
public boolean deleteModule(int semesterid, int userid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("DELETE FROM modules WHERE id=" + id);
|
st.executeUpdate("delete from modules where semesterid=" + semesterid + " and userid=" + userid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(Exception ex) {
|
catch(Exception ex) {
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ public class Module {
|
|||||||
this.activated = activated;
|
this.activated = activated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() { return id; }
|
public int getid() { return id; }
|
||||||
|
|
||||||
public int getUserid() { return userid; }
|
public int getUserid() { return userid; }
|
||||||
|
|
||||||
public int getSemesterId() { return semesterid; }
|
public int getsemesterid() { return semesterid; }
|
||||||
|
|
||||||
public String getName() { return name; }
|
public String getName() { return name; }
|
||||||
|
|
||||||
|
|||||||
@@ -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,17 @@ 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
System.out.println("test1");
|
||||||
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 +132,16 @@ 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,10 +153,12 @@ 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 = "semesterid") int semesterid, @RequestParam(name = "userid") int userid)
|
||||||
|
{
|
||||||
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(semesterid, userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class SemesterController
|
|||||||
Semester s = db.addSemester(semester);
|
Semester s = db.addSemester(semester);
|
||||||
if(s != null)
|
if(s != null)
|
||||||
{
|
{
|
||||||
System.out.println(s.getStartday());
|
|
||||||
return new ResponseEntity<>(s, HttpStatus.OK);
|
return new ResponseEntity<>(s, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,6 @@ public class SemesterController
|
|||||||
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())
|
||||||
{
|
{
|
||||||
System.out.println(semester.getId());
|
|
||||||
Semester s = db.updateSemester(semester);
|
Semester s = db.updateSemester(semester);
|
||||||
|
|
||||||
if(s != null)
|
if(s != null)
|
||||||
|
|||||||
Reference in new issue
Block a user