diff --git a/backend/database.mv.db b/backend/database.mv.db index 329f459..bfe9e72 100644 Binary files a/backend/database.mv.db and b/backend/database.mv.db differ diff --git a/backend/database.trace.db b/backend/database.trace.db index 59af940..bea65a2 100644 --- a/backend/database.trace.db +++ b/backend/database.trace.db @@ -126737,3 +126737,34 @@ No data is available [2000-214] 2023-05-22 22:54:50 jdbc[3]: exception org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar 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] diff --git a/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java b/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java index 9ee6585..fdec47c 100644 --- a/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java +++ b/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java @@ -110,20 +110,20 @@ public class DataBaseHandler } } - /** - DAYS - */ - public Day addDay(Day day) + /** + DAYS + */ + public Day addDay(Day day) + { + try { - try - { - st.executeUpdate("insert into days (dayinyear, yearnumber, semesterid) values (" + day.getDayinyear() + ", " + day.getYearnumber() + ", " + day.getSemesterid() + ")"); - return getDay(day.getDayinyear(), day.getYearnumber(), day.getSemesterid()); - } catch (SQLException e) - { - return null; - } + st.executeUpdate("insert into days (dayinyear, yearnumber, semesterid) values (" + day.getDayinyear() + ", " + day.getYearnumber() + ", " + day.getSemesterid() + ")"); + return getDay(day.getDayinyear(), day.getYearnumber(), day.getSemesterid()); + } catch (SQLException e) + { + return null; } + } public Day getDay(int id) { @@ -172,7 +172,7 @@ public class DataBaseHandler } /** - ENTRIES + ENTRIES */ //method that returns all entries of a day based on the given parameters public Entry[] getEntries(int dayinweek, int weeknumber, int semesterid, User user) @@ -227,7 +227,7 @@ public class DataBaseHandler } /** - SEMESTER + SEMESTER */ //get a semester object by its name public Semester getSemester(String name) @@ -312,7 +312,7 @@ public class DataBaseHandler { 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); } @@ -346,17 +346,6 @@ public class DataBaseHandler 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 public Module getModule(int id) { 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 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) { try { - st.executeUpdate("INSERT INTO modules (lecturerId, semesterId, name) " + - "Values (" + m.getLecturerId() + m.getSemesterId() + m.getName() + ")"); - return getModule(m.getId()); + st.executeUpdate("insert into modules (userid, semesterid, name, activated) " + + "Values (" + m.getUserid() + ", " + m.getSemesterId() + ", '" + m.getName() + "', " + m.getActivated() + ")"); + return getModule(m.getUserid(), m.getSemesterId(), m.getName()); } catch (Exception e) { + e.printStackTrace(); return null; } } @@ -402,11 +425,11 @@ public class DataBaseHandler public Module updateModule(Module m) { + System.out.println(m.getActivated()); + try { - st.executeUpdate("UPDATE modules SET lecturerId=" + m.getLecturerId() + ", " + - "semesterId=" + m.getSemesterId() + ", " + - "name='" + m.getName() + "'"); - return getModule(m.getId()); + 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()); } catch (SQLException ex) { ex.printStackTrace(); @@ -430,9 +453,10 @@ public class DataBaseHandler rs.next(); return new Module( rs.getInt("id"), - rs.getInt("lecturerId"), - rs.getInt("semesterId"), - rs.getString("name")); + rs.getInt("userid"), + rs.getInt("semesterid"), + rs.getString("name"), + rs.getInt("activated")); } catch (Exception ex) { return null; @@ -440,7 +464,7 @@ public class DataBaseHandler } /** - USER + USER */ diff --git a/backend/src/main/java/com/example/backend/anwprj/Module/Module.java b/backend/src/main/java/com/example/backend/anwprj/Module/Module.java index 4046fc8..e9e2c64 100644 --- a/backend/src/main/java/com/example/backend/anwprj/Module/Module.java +++ b/backend/src/main/java/com/example/backend/anwprj/Module/Module.java @@ -2,24 +2,30 @@ package com.example.backend.anwprj.Module; //module data class public class Module { - private final int id; - private final int lecturerId; - private final int semesterId; - private final String name; + private int id; + private int userid; + private int semesterid; + 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.lecturerId = lecturerId; - this.semesterId = semesterId; + this.userid = userid; + this.semesterid = semesterid; this.name = name; + this.activated = activated; } 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 int getActivated() { return activated; } + } diff --git a/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java b/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java index 220e622..a2a7a23 100644 --- a/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java +++ b/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java @@ -17,39 +17,38 @@ public class ModuleController { db = DataBaseHandler.getInstance(); } - @CrossOrigin - @GetMapping("/module") - public ResponseEntity getModule( - @RequestParam(name="id") int id, - @RequestParam(name="sessionid") String sessionID) { - - User user = UserSessionIDHandler.getUserBySessionID(sessionID); - - if (user != null){ - Module module = db.getModule(id); - if(module != null) { - return new ResponseEntity<>(module, HttpStatus.OK); - } - - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - - return new ResponseEntity<>(HttpStatus.FORBIDDEN); - } +// @CrossOrigin +// @GetMapping("/module") +// public ResponseEntity getModule( +// @RequestParam(name="id") int id, +// @RequestParam(name="sessionid") String sessionID) { +// +// User user = UserSessionIDHandler.getUserBySessionID(sessionID); +// +// if (user != null){ +// Module module = db.getModule(id); +// if(module != null) { +// return new ResponseEntity<>(module, HttpStatus.OK); +// } +// +// return new ResponseEntity<>(HttpStatus.NOT_FOUND); +// } +// +// return new ResponseEntity<>(HttpStatus.FORBIDDEN); +// } @CrossOrigin @GetMapping("/module/id") - public ResponseEntity getModule( - @RequestParam(name="name") String name, + public ResponseEntity getModules( @RequestParam(name="sessionid") String sessionID) { User user = UserSessionIDHandler.getUserBySessionID(sessionID); if(user != null) { - Module module = db.getModule(name); - if (module != null) { - return new ResponseEntity<>(module, HttpStatus.OK); + Module[] modules = db.getModules(user.getId()); + if (modules != null) { + return new ResponseEntity<>(modules, HttpStatus.OK); } return new ResponseEntity<>(HttpStatus.NOT_FOUND);