Module Controller Fixed
This commit is contained in:
Binary file not shown.
@@ -126737,3 +126737,34 @@ No data is available [2000-214]
|
|||||||
2023-05-22 22:54:50 jdbc[3]: exception
|
2023-05-22 22:54:50 jdbc[3]: exception
|
||||||
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
||||||
No data is available [2000-214]
|
No data is available [2000-214]
|
||||||
|
2023-05-23 18:20:34 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
||||||
|
No data is available [2000-214]
|
||||||
|
2023-05-23 18:22:59 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "INSERT INTO modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; erwartet "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"
|
||||||
|
Syntax error in SQL statement "INSERT INTO modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; expected "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"; SQL statement:
|
||||||
|
INSERT INTO modules (userid, semesterid, name, activated) Values (1, 59, Lineare Algebra, 1) [42001-214]
|
||||||
|
2023-05-23 18:23:50 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "INSERT INTO modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; erwartet "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"
|
||||||
|
Syntax error in SQL statement "INSERT INTO modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; expected "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"; SQL statement:
|
||||||
|
INSERT INTO modules (userid, semesterid, name, activated) Values (1, 59, Lineare Algebra, 1) [42001-214]
|
||||||
|
2023-05-23 18:25:06 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "insert into modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; erwartet "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"
|
||||||
|
Syntax error in SQL statement "insert into modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; expected "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"; SQL statement:
|
||||||
|
insert into modules (userid, semesterid, name, activated) Values (1, 59, Lineare Algebra, 1) [42001-214]
|
||||||
|
2023-05-23 18:26:07 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "insert into modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; erwartet "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"
|
||||||
|
Syntax error in SQL statement "insert into modules (userid, semesterid, name, activated) Values (1, 59, Lineare [*]Algebra, 1)"; expected "(, ., [, ::, AT, FORMAT, *, /, %, +, -, ||, NOT, IS, ILIKE, REGEXP, AND, OR, ,, )"; SQL statement:
|
||||||
|
insert into modules (userid, semesterid, name, activated) Values (1, 59, Lineare Algebra, 1) [42001-214]
|
||||||
|
2023-05-23 18:27:08 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
||||||
|
No data is available [2000-214]
|
||||||
|
2023-05-23 18:37:40 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
||||||
|
No data is available [2000-214]
|
||||||
|
2023-05-23 18:39:13 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
||||||
|
No data is available [2000-214]
|
||||||
|
2023-05-23 18:39:49 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
|
||||||
|
No data is available [2000-214]
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ public class DataBaseHandler
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//st.executeUpdate("DELETE FROM module 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);
|
||||||
}
|
}
|
||||||
@@ -346,17 +346,6 @@ public class DataBaseHandler
|
|||||||
MODULE
|
MODULE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//get a module object by its name
|
|
||||||
public Module getModule(String name) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("SELECT * FROM modules WHERE name = '" + name + "'");
|
|
||||||
return resultSetToModule(rs);
|
|
||||||
}
|
|
||||||
catch (Exception ex){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//get a module object by its id
|
//get a module object by its id
|
||||||
public Module getModule(int id) {
|
public Module getModule(int id) {
|
||||||
try {
|
try {
|
||||||
@@ -368,15 +357,49 @@ public class DataBaseHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Module getModule(int userid, int semesterid, String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid + " and name='" + name + "'");
|
||||||
|
|
||||||
|
return resultSetToModule(rs);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//get module objects by its semester and its lecturer
|
||||||
|
public Module[] getModules(int userid) {
|
||||||
|
try {
|
||||||
|
ResultSet rs = st.executeQuery("SELECT * FROM modules WHERE userid = " + userid);
|
||||||
|
List<Module> moduleList = new ArrayList<>();
|
||||||
|
Module m = null;
|
||||||
|
while((m = resultSetToModule(rs)) != null)
|
||||||
|
{
|
||||||
|
moduleList.add(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return moduleList.toArray(new Module[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Module addModule(Module m)
|
public Module addModule(Module m)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("INSERT INTO modules (lecturerId, semesterId, name) " +
|
st.executeUpdate("insert into modules (userid, semesterid, name, activated) " +
|
||||||
"Values (" + m.getLecturerId() + m.getSemesterId() + m.getName() + ")");
|
"Values (" + m.getUserid() + ", " + m.getSemesterId() + ", '" + m.getName() + "', " + m.getActivated() + ")");
|
||||||
return getModule(m.getId());
|
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -402,11 +425,11 @@ public class DataBaseHandler
|
|||||||
|
|
||||||
public Module updateModule(Module m)
|
public Module updateModule(Module m)
|
||||||
{
|
{
|
||||||
|
System.out.println(m.getActivated());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("UPDATE modules SET lecturerId=" + m.getLecturerId() + ", " +
|
st.executeUpdate("update modules set activated=" + m.getActivated() + " where userid=" + m.getUserid() + " and semesterid=" + m.getSemesterId() + " and name='" + m.getName() + "'");
|
||||||
"semesterId=" + m.getSemesterId() + ", " +
|
return getModule(m.getUserid(), m.getSemesterId(), m.getName());
|
||||||
"name='" + m.getName() + "'");
|
|
||||||
return getModule(m.getId());
|
|
||||||
}
|
}
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@@ -430,9 +453,10 @@ public class DataBaseHandler
|
|||||||
rs.next();
|
rs.next();
|
||||||
return new Module(
|
return new Module(
|
||||||
rs.getInt("id"),
|
rs.getInt("id"),
|
||||||
rs.getInt("lecturerId"),
|
rs.getInt("userid"),
|
||||||
rs.getInt("semesterId"),
|
rs.getInt("semesterid"),
|
||||||
rs.getString("name"));
|
rs.getString("name"),
|
||||||
|
rs.getInt("activated"));
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -2,24 +2,30 @@ package com.example.backend.anwprj.Module;
|
|||||||
|
|
||||||
//module data class
|
//module data class
|
||||||
public class Module {
|
public class Module {
|
||||||
private final int id;
|
private int id;
|
||||||
private final int lecturerId;
|
private int userid;
|
||||||
private final int semesterId;
|
private int semesterid;
|
||||||
private final String name;
|
private String name;
|
||||||
|
private int activated;
|
||||||
|
|
||||||
public Module(int id, int lecturerId, int semesterId, String name){
|
|
||||||
|
public Module(int id, int userid, int semesterid, String name, int activated)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.lecturerId = lecturerId;
|
this.userid = userid;
|
||||||
this.semesterId = semesterId;
|
this.semesterid = semesterid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.activated = activated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() { return id; }
|
public int getId() { return id; }
|
||||||
|
|
||||||
public int getLecturerId() { return lecturerId; }
|
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; }
|
||||||
|
|
||||||
|
public int getActivated() { return activated; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,39 +17,38 @@ public class ModuleController {
|
|||||||
db = DataBaseHandler.getInstance();
|
db = DataBaseHandler.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
// @CrossOrigin
|
||||||
@GetMapping("/module")
|
// @GetMapping("/module")
|
||||||
public ResponseEntity<Module> getModule(
|
// public ResponseEntity<Module> getModule(
|
||||||
@RequestParam(name="id") int id,
|
// @RequestParam(name="id") int id,
|
||||||
@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 module = db.getModule(id);
|
// Module module = db.getModule(id);
|
||||||
if(module != null) {
|
// if(module != null) {
|
||||||
return new ResponseEntity<>(module, HttpStatus.OK);
|
// return new ResponseEntity<>(module, HttpStatus.OK);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
// return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@GetMapping("/module/id")
|
@GetMapping("/module/id")
|
||||||
public ResponseEntity<Module> getModule(
|
public ResponseEntity<Module[]> getModules(
|
||||||
@RequestParam(name="name") String name,
|
|
||||||
@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 module = db.getModule(name);
|
Module[] modules = db.getModules(user.getId());
|
||||||
if (module != null) {
|
if (modules != null) {
|
||||||
return new ResponseEntity<>(module, HttpStatus.OK);
|
return new ResponseEntity<>(modules, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
|||||||
Reference in New Issue
Block a user