Skip to content
Snippets Groups Projects
Commit ef99ca56 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Task #3845: Sessions will be created using server side implementation

parent f1f132c7
Branches
Tags
No related merge requests found
...@@ -47,6 +47,18 @@ public class SessionController { ...@@ -47,6 +47,18 @@ public class SessionController {
return null; return null;
} }
@RequestMapping(value="/session", method=RequestMethod.POST)
public Session postNewSession(@RequestBody Session session, HttpServletResponse response) {
Session newSession = sessionService.saveSession(session);
if (session != null) {
response.setStatus(HttpStatus.CREATED.value());
return newSession;
}
response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value());
return null;
}
@RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.GET) @RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.GET)
public Feedback getFeedback(@PathVariable String sessionkey, HttpServletResponse response) { public Feedback getFeedback(@PathVariable String sessionkey, HttpServletResponse response) {
Feedback feedback = sessionService.getFeedback(sessionkey); Feedback feedback = sessionService.getFeedback(sessionkey);
......
...@@ -25,8 +25,10 @@ import de.thm.arsnova.entities.Session; ...@@ -25,8 +25,10 @@ import de.thm.arsnova.entities.Session;
public interface ISessionService { public interface ISessionService {
public Session getSession(String keyword); public Session getSession(String keyword);
public Session saveSession(Session session);
public Feedback getFeedback(String keyword); public Feedback getFeedback(String keyword);
public boolean postFeedback(String keyword, int value); public boolean postFeedback(String keyword, int value);
public boolean sessionKeyAvailable(String keyword); public boolean sessionKeyAvailable(String keyword);
public String generateKeyword();
} }
\ No newline at end of file
...@@ -71,6 +71,25 @@ public class SessionService implements ISessionService { ...@@ -71,6 +71,25 @@ public class SessionService implements ISessionService {
return null; return null;
} }
@Override
public Session saveSession(Session session) {
Document sessionDocument = new Document();
sessionDocument.put("type","session");
sessionDocument.put("name", session.getName());
sessionDocument.put("shortName", session.getShortName());
sessionDocument.put("keyword", this.generateKeyword());
sessionDocument.put("creator", this.actualUserName());
sessionDocument.put("active", true);
try {
database.saveDocument(sessionDocument);
} catch (IOException e) {
return null;
}
return this.getSession(sessionDocument.getString("keyword"));
}
@Override @Override
public Feedback getFeedback(String keyword) { public Feedback getFeedback(String keyword) {
...@@ -196,10 +215,13 @@ public class SessionService implements ISessionService { ...@@ -196,10 +215,13 @@ public class SessionService implements ISessionService {
return null; return null;
} }
@Override
public String generateKeyword() { public String generateKeyword() {
// Generates a number between >=low and <high, so our keyword has exactly 8 digits.
final int low = 10000000; final int low = 10000000;
final int high = 100000000; final int high = 100000000;
return String.valueOf((int)(Math.random() * (high - low) + low)); String keyword = String.valueOf((int)(Math.random() * (high - low) + low));
if (this.sessionKeyAvailable(keyword)) return keyword;
return generateKeyword();
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment