Request Entries from Rest API
Required for Request: SessionID (Login), tag in der woche (montag: 0) kalenderwoche semesterid (evtl.später semestername)
This commit is contained in:
Binary file not shown.
@@ -247,3 +247,43 @@ Wrong user name or password [28000-214]
|
|||||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:510)
|
at org.h2.message.DbException.getJdbcSQLException(DbException.java:510)
|
||||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)
|
at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)
|
||||||
... 16 more
|
... 16 more
|
||||||
|
2023-05-08 14:01:35 database: wrong user or password; user: "ADM"
|
||||||
|
org.h2.message.DbException: Falscher Benutzername oder Passwort
|
||||||
|
Wrong user name or password [28000-214]
|
||||||
|
at org.h2.message.DbException.get(DbException.java:223)
|
||||||
|
at org.h2.message.DbException.get(DbException.java:199)
|
||||||
|
at org.h2.message.DbException.get(DbException.java:188)
|
||||||
|
at org.h2.engine.Engine.openSession(Engine.java:154)
|
||||||
|
at org.h2.engine.Engine.openSession(Engine.java:222)
|
||||||
|
at org.h2.engine.Engine.createSession(Engine.java:201)
|
||||||
|
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338)
|
||||||
|
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:122)
|
||||||
|
at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:288)
|
||||||
|
at org.h2.server.web.WebServer.getConnection(WebServer.java:808)
|
||||||
|
at org.h2.server.web.WebApp.login(WebApp.java:1033)
|
||||||
|
at org.h2.server.web.WebApp.process(WebApp.java:226)
|
||||||
|
at org.h2.server.web.WebApp.processRequest(WebApp.java:176)
|
||||||
|
at org.h2.server.web.WebThread.process(WebThread.java:152)
|
||||||
|
at org.h2.server.web.WebThread.run(WebThread.java:101)
|
||||||
|
at java.base/java.lang.Thread.run(Thread.java:1623)
|
||||||
|
Caused by: org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Falscher Benutzername oder Passwort
|
||||||
|
Wrong user name or password [28000-214]
|
||||||
|
at org.h2.message.DbException.getJdbcSQLException(DbException.java:510)
|
||||||
|
at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)
|
||||||
|
... 16 more
|
||||||
|
2023-05-08 23:46:11 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Tabelle "WEEK" nicht gefunden
|
||||||
|
Table "WEEK" not found; SQL statement:
|
||||||
|
select * from week [42102-214]
|
||||||
|
2023-05-08 23:46:25 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Tabelle "SEMESTR" nicht gefunden
|
||||||
|
Table "SEMESTR" not found; SQL statement:
|
||||||
|
select * from semestr [42102-214]
|
||||||
|
2023-05-08 23:46:46 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Tabelle "WEEK" nicht gefunden
|
||||||
|
Table "WEEK" not found; SQL statement:
|
||||||
|
select * from week [42102-214]
|
||||||
|
2023-05-08 23:54:05 jdbc[3]: exception
|
||||||
|
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "select * [*]froms days"
|
||||||
|
Syntax error in SQL statement "select * [*]froms days"; SQL statement:
|
||||||
|
select * froms days [42000-214]
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package com.example.backend.anwprj;
|
package com.example.backend.anwprj;
|
||||||
|
|
||||||
|
import com.example.backend.anwprj.Entries.Entry;
|
||||||
import com.example.backend.anwprj.Semesters.Semester;
|
import com.example.backend.anwprj.Semesters.Semester;
|
||||||
import com.example.backend.anwprj.Users.User;
|
import com.example.backend.anwprj.Users.User;
|
||||||
|
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DataBaseHandler
|
public class DataBaseHandler
|
||||||
{
|
{
|
||||||
@@ -34,6 +39,52 @@ public class DataBaseHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Entry[] getEntries(int dayinweek, int weeknumber, int semesterid, User user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select distinct e.id, e.dayid, e.usercreatedbyid, e.timestart, e.timeend, e.info " +
|
||||||
|
"from entries e, days d, weeks w, semester s " +
|
||||||
|
"where e.dayid = d.id and " +
|
||||||
|
"d.weekid = w.id and " +
|
||||||
|
"w.semesterid = s.id and " +
|
||||||
|
"d.dayinweek = " + dayinweek + " and " +
|
||||||
|
"w.weeknumber = " + weeknumber + " and " +
|
||||||
|
"s.id = " + semesterid);
|
||||||
|
|
||||||
|
|
||||||
|
boolean editable = false;
|
||||||
|
|
||||||
|
List<Entry> temp = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
{
|
||||||
|
editable = false;
|
||||||
|
if(rs.getInt("usercreatedbyid") == user.getId())
|
||||||
|
{
|
||||||
|
editable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp.add(
|
||||||
|
new Entry(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getInt("dayid"),
|
||||||
|
rs.getInt("usercreatedbyid"),
|
||||||
|
rs.getInt("timestart"),
|
||||||
|
rs.getInt("timeend"),
|
||||||
|
rs.getString("info"),
|
||||||
|
editable
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp.toArray(new Entry[0]);
|
||||||
|
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Semester findSemester(String name)
|
public Semester findSemester(String name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.example.backend.anwprj.Entries;
|
||||||
|
|
||||||
|
public class Entry
|
||||||
|
{
|
||||||
|
private int id;
|
||||||
|
private int dayid;
|
||||||
|
private int usercreatedbyid;
|
||||||
|
private int timestart;
|
||||||
|
private int timeend;
|
||||||
|
private String info;
|
||||||
|
private boolean editable;
|
||||||
|
|
||||||
|
public Entry(int id, int dayid, int usercreatedbyid, int timestart, int timeend, String info, boolean editable)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
this.dayid = dayid;
|
||||||
|
this.usercreatedbyid = usercreatedbyid;
|
||||||
|
this.timestart = timestart;
|
||||||
|
this.timeend = timeend;
|
||||||
|
this.info = info;
|
||||||
|
this.editable = editable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDayid()
|
||||||
|
{
|
||||||
|
return dayid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUsercreatedbyid()
|
||||||
|
{
|
||||||
|
return usercreatedbyid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimestart()
|
||||||
|
{
|
||||||
|
return timestart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeend()
|
||||||
|
{
|
||||||
|
return timeend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo()
|
||||||
|
{
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDayid(int dayid)
|
||||||
|
{
|
||||||
|
this.dayid = dayid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestart(int timestart)
|
||||||
|
{
|
||||||
|
this.timestart = timestart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeend(int timeend)
|
||||||
|
{
|
||||||
|
this.timeend = timeend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfo(String info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,28 +10,37 @@ public class UserSessionIDHandler
|
|||||||
{
|
{
|
||||||
public static HashMap<String, User> mapping = new HashMap<>();
|
public static HashMap<String, User> mapping = new HashMap<>();
|
||||||
|
|
||||||
|
public static User getUserBySessionID(String sessionID)
|
||||||
|
{
|
||||||
|
return mapping.get(sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
public static String addUser(String mail, String password)
|
public static String addUser(String mail, String password)
|
||||||
{
|
{
|
||||||
User user = DataBaseHandler.getInstance().findUser(mail, password);
|
User user = DataBaseHandler.getInstance().findUser(mail, password);
|
||||||
|
|
||||||
if(user != null)
|
if(user != null)
|
||||||
{
|
{
|
||||||
byte[] array = new byte[30]; // length is bounded by 7
|
byte[] id = new byte[100];
|
||||||
new Random().nextBytes(array);
|
|
||||||
String generatedString = new String(array, StandardCharsets.UTF_8);
|
|
||||||
mapping.put(generatedString, user);
|
|
||||||
|
|
||||||
|
for(int i = 0; i < id.length; i++)
|
||||||
|
{
|
||||||
|
id[i] = (byte) (Math.random() * 26 + 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
String generatedString = new String(id, StandardCharsets.US_ASCII);
|
||||||
|
|
||||||
|
mapping.put(generatedString, user);
|
||||||
new java.util.Timer().schedule(new java.util.TimerTask(){
|
new java.util.Timer().schedule(new java.util.TimerTask(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
mapping.remove(generatedString);
|
mapping.remove(generatedString);
|
||||||
System.out.println("test");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//value to be higher
|
//value to be higher
|
||||||
}, 5000);
|
}, 5000000);
|
||||||
|
|
||||||
return generatedString;
|
return generatedString;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.example.backend.anwprj.controller;
|
||||||
|
|
||||||
|
import com.example.backend.anwprj.DataBaseHandler;
|
||||||
|
import com.example.backend.anwprj.Entries.Entry;
|
||||||
|
import com.example.backend.anwprj.Users.User;
|
||||||
|
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class EntriesController
|
||||||
|
{
|
||||||
|
private DataBaseHandler db;
|
||||||
|
|
||||||
|
{
|
||||||
|
db = DataBaseHandler.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/entries")
|
||||||
|
public ResponseEntity<Entry[]> getEntries(
|
||||||
|
@RequestParam(name = "sessionid") String sessionID,
|
||||||
|
@RequestParam(name = "dayinweek") int dayinweek,
|
||||||
|
@RequestParam(name = "weeknumber") int weeknumber,
|
||||||
|
@RequestParam(name = "semesterid") int semesterid)
|
||||||
|
{
|
||||||
|
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
|
if(user == null)
|
||||||
|
{
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry[] entries = db.getEntries(dayinweek, weeknumber, semesterid, user);
|
||||||
|
return new ResponseEntity<>(entries, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user