Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09d46a9faf | ||
|
|
ac9fa44b99 | ||
|
|
00d57da32d | ||
|
|
15d325815d | ||
|
|
7703b0676d | ||
|
|
f42f2df078 | ||
|
|
337aea6a65 | ||
|
|
9255fb8e9b |
@@ -3,26 +3,11 @@ import {useRouter} from "next/router";
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import Background from "@/components/Background";
|
import Background from "@/components/Background";
|
||||||
|
|
||||||
let userInfo = []
|
|
||||||
|
let userModuleMapping = new Map()
|
||||||
|
|
||||||
export default function InputForm(p) {
|
export default function InputForm(p) {
|
||||||
|
|
||||||
class UserInfo {
|
|
||||||
constructor(userid, modules) {
|
|
||||||
this.userid = userid;
|
|
||||||
this.module = modules;
|
|
||||||
this.checked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
setChecked(checked) {
|
|
||||||
this.checked = checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
setModule(module) {
|
|
||||||
this.module = module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let startDateParam = "";
|
let startDateParam = "";
|
||||||
let endDateParam = "";
|
let endDateParam = "";
|
||||||
let courseNameParam = "";
|
let courseNameParam = "";
|
||||||
@@ -37,21 +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;
|
||||||
|
|
||||||
|
|
||||||
await fetch(url).then(response => response.json()).then(user => setUsers(user));
|
await fetch(url).then(response => response.json()).then(async user => {
|
||||||
|
setUsers(user)
|
||||||
|
let mURL = "http://localhost:8080/module/suid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid") + "&userid=";
|
||||||
|
for(let i = 0; i < user.length; i++)
|
||||||
|
{
|
||||||
|
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(() => {
|
||||||
|
getAllUsers()
|
||||||
userInfo = [];
|
userModuleMapping.clear();
|
||||||
getAllUsers();
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
async function onCreateClicked() {
|
async function onCreateClicked() {
|
||||||
let startSplit = startDate.split("-");
|
let startSplit = startDate.split("-");
|
||||||
let endSplit = endDate.split("-");
|
let endSplit = endDate.split("-");
|
||||||
@@ -80,51 +131,153 @@ export default function InputForm(p) {
|
|||||||
let method = p.courseName == null ? "POST" : "PUT";
|
let method = p.courseName == null ? "POST" : "PUT";
|
||||||
|
|
||||||
|
|
||||||
|
let semesterid = localStorage.getItem("currentsid");
|
||||||
|
let tempsid = 0;
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
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 => console.log(semester));
|
}).then(response => response.json()).then(semester => {
|
||||||
|
tempsid = semester.id
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (method === "POST") {
|
||||||
|
semesterid = tempsid;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let [key, value] of userModuleMapping) {
|
||||||
|
|
||||||
|
let json1 = {
|
||||||
|
"id": 0,
|
||||||
|
"userid": value.getUserid(),
|
||||||
|
"semesterid": semesterid,
|
||||||
|
"name": value.getModuleName(),
|
||||||
|
"activated": value.getActivated()
|
||||||
|
}
|
||||||
|
if (value.getChecked()) {
|
||||||
|
let updateURL = "http://localhost:8080/module?sessionid=" + localStorage.getItem("sessionid");
|
||||||
|
await fetch(updateURL, {
|
||||||
|
method: method,
|
||||||
|
headers: {"Content-Type": "application/json"},
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onModuleClicked(user, module) {
|
class UserModuleInfo {
|
||||||
|
constructor() {
|
||||||
let found = false;
|
this.moduleName = "";
|
||||||
|
this.userid = 0;
|
||||||
for (let i = 0; i < userInfo.length; i++) {
|
this.activated = 0
|
||||||
let current = userInfo[i];
|
this.checked = false
|
||||||
if (current !== undefined && current.userid === user.id) {
|
|
||||||
userInfo[i].setModule(module);
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
getModuleName() {
|
||||||
userInfo.push(new UserInfo(user.id, module));
|
return this.moduleName
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserid() {
|
||||||
|
return this.userid
|
||||||
|
}
|
||||||
|
|
||||||
|
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 onCheckBoxClicked(user, e) {
|
function onModuleClicked(user, module, index) {
|
||||||
onModuleClicked(user, "");
|
|
||||||
|
|
||||||
let found = false;
|
if (userModuleMapping.has(user.id)) {
|
||||||
|
let temp = userModuleMapping.get(user.id)
|
||||||
for (let i = 0; i < userInfo.length; i++) {
|
temp.setModuleName(module)
|
||||||
let current = userInfo[i];
|
temp.setUserid(user.id)
|
||||||
if (current !== undefined && current.userid === user.id) {
|
|
||||||
userInfo[i].setChecked(e.target.checked);
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
let temp = [];
|
||||||
let temp = new UserInfo(user.id, "");
|
|
||||||
temp.setChecked(e.target.checked);
|
for(let i = 0; i < modulesNames.length; i++)
|
||||||
userInfo.push(temp);
|
{
|
||||||
|
temp.push(modulesNames[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp[index] = module;
|
||||||
|
|
||||||
|
setModulesNames(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSelectedCheckBox(user, state, index) {
|
||||||
|
if (userModuleMapping.has(user.id)) {
|
||||||
|
userModuleMapping.get(user.id).setChecked(state.target.checked);
|
||||||
|
} else {
|
||||||
|
let temp = new UserModuleInfo()
|
||||||
|
temp.setChecked(state.target.checked)
|
||||||
|
temp.setUserid(user.id)
|
||||||
|
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, index) {
|
||||||
|
if (userModuleMapping.has(user.id)) {
|
||||||
|
let t = state.target.checked ? 1 : 0;
|
||||||
|
userModuleMapping.get(user.id).setActivated(t);
|
||||||
|
console.log(userModuleMapping.get(user.id).getActivated())
|
||||||
|
}
|
||||||
|
|
||||||
|
let temp = []
|
||||||
|
|
||||||
|
for(let i = 0; i < checkedSelected.length; i++)
|
||||||
|
{
|
||||||
|
temp.push(activatedSelected[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp[index] = state.target.checked;
|
||||||
|
|
||||||
|
setActivatedSelected(temp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -195,33 +348,38 @@ 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",
|
||||||
onCheckBoxClicked(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",
|
||||||
onCheckBoxClicked(user, e);
|
}}><input type="checkbox" onChange={(e) => {
|
||||||
}}/></div></td>
|
onActivatedCheckBox(user, e, i);
|
||||||
<td style={{}}>{user.firstName + " " + user.lastName}</td>
|
}} checked={activatedSelected[i]}/></div>
|
||||||
|
</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={{
|
||||||
maxHeight: 80,
|
maxHeight: 80,
|
||||||
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={"Programmieren"}>Programmieren</option>
|
<option value={"Programmieren"}>Programmieren</option>
|
||||||
<option value={"BWL"}>BWL</option>
|
<option value={"BWL"}>BWL</option>
|
||||||
<option value={"Lineare Algebra"}>Lineare Algebra</option>
|
<option value={"Lineare Algebra"}>Lineare Algebra</option>
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import Button from "@/components/Button";
|
||||||
|
import {useRouter} from "next/router";
|
||||||
|
|
||||||
|
export default function Logout()
|
||||||
|
{
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
async function logout()
|
||||||
|
{
|
||||||
|
let url = "http://localhost:8080/users/logout?sessionid=" + localStorage.getItem("sessionid");
|
||||||
|
await fetch(url)
|
||||||
|
await router.push("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
position: "absolute",
|
||||||
|
left: 20,
|
||||||
|
top: 20,
|
||||||
|
width: 130,
|
||||||
|
height: 60,
|
||||||
|
borderBottomRightRadius: 10,
|
||||||
|
|
||||||
|
}}>
|
||||||
|
<Button onClick={() => logout()} text={"Logout"} color={"#77932b"} width={100} height={40}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
import InputForm from "@/components/InputForm";
|
import InputForm from "@/components/InputForm";
|
||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
|
import Logout from "@/components/Logout";
|
||||||
|
import {useEffect} from "react";
|
||||||
|
|
||||||
export default function CreateSemester()
|
export default function CreateSemester()
|
||||||
{
|
{
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
let {courseName, startDate, endDate} = router.query;
|
let {courseName, startDate, endDate} = router.query;
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"normal-centered"}>
|
<div className={"normal-centered"}>
|
||||||
|
<Logout/>
|
||||||
<InputForm startDate={startDate} endDate={endDate} courseName={courseName}/>
|
<InputForm startDate={startDate} endDate={endDate} courseName={courseName}/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import InputForm from "@/components/InputForm";
|
|||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
import PopUp from "@/components/PopUp";
|
import PopUp from "@/components/PopUp";
|
||||||
import Background from "@/components/Background";
|
import Background from "@/components/Background";
|
||||||
|
import Logout from "@/components/Logout";
|
||||||
|
|
||||||
export default function SemesterOverview(p)
|
export default function SemesterOverview(p)
|
||||||
{
|
{
|
||||||
@@ -12,9 +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");
|
||||||
|
|
||||||
await fetch(urlTest).then(response => response.json()).then(s => {
|
|
||||||
setEntries(s)
|
await fetch(urlTest).then(response => response.json()).then(s => {
|
||||||
})
|
setEntries(s)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClickSemester(e, m)
|
function onClickSemester(e, m)
|
||||||
@@ -27,6 +30,7 @@ export default function SemesterOverview(p)
|
|||||||
|
|
||||||
function onClickNewSemester()
|
function onClickNewSemester()
|
||||||
{
|
{
|
||||||
|
localStorage.setItem("currentsid", 0);
|
||||||
router.push("/createSemester");
|
router.push("/createSemester");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +87,10 @@ export default function SemesterOverview(p)
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSemesters();
|
getSemesters();
|
||||||
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
const [entries, setEntries] = useState([])
|
const [entries, setEntries] = useState([])
|
||||||
const [modalDisplay, setModalDisplay] = useState("none");
|
const [modalDisplay, setModalDisplay] = useState("none");
|
||||||
const [modalHint, setModalHint] = useState("");
|
const [modalHint, setModalHint] = useState("");
|
||||||
@@ -92,6 +98,7 @@ export default function SemesterOverview(p)
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"semester-overview"}>
|
<div className={"semester-overview"}>
|
||||||
|
<Logout/>
|
||||||
<Background/>
|
<Background/>
|
||||||
{
|
{
|
||||||
entries.map(e => (<SemesterTile text={e.name} onClick={(f) => onClickSemester(e, f)} onButtonDeleteClick={() => {
|
entries.map(e => (<SemesterTile text={e.name} onClick={(f) => onClickSemester(e, f)} onButtonDeleteClick={() => {
|
||||||
|
|||||||
Binary file not shown.
+142781
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!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -312,7 +311,7 @@ public class DataBaseHandler
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
st.executeUpdate("DELETE FROM modules WHERE semesterId = " + id);
|
st.executeUpdate("DELETE FROM modules WHERE semesterid=" + id);
|
||||||
|
|
||||||
st.executeUpdate("delete from semester where id=" + id);
|
st.executeUpdate("delete from semester where id=" + id);
|
||||||
}
|
}
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -140,6 +140,20 @@ public class UserController {
|
|||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/users/check")
|
||||||
|
public ResponseEntity<User> checkLogin(@RequestParam(name="sessionid") String sessionid)
|
||||||
|
{
|
||||||
|
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
||||||
|
|
||||||
|
if(u != null)
|
||||||
|
{
|
||||||
|
return new ResponseEntity<>(db.getUser(u.getId()), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@DeleteMapping("/users")
|
@DeleteMapping("/users")
|
||||||
public ResponseEntity<Boolean> deleteUser(@RequestParam(name = "sessionid") String sessionID, @RequestParam(name = "mail") String mail) {
|
public ResponseEntity<Boolean> deleteUser(@RequestParam(name = "sessionid") String sessionID, @RequestParam(name = "mail") String mail) {
|
||||||
|
|||||||
Reference in New Issue
Block a user