Skip to content
Snippets Groups Projects
Commit 5861a3ee authored by Julian Hochstetter's avatar Julian Hochstetter
Browse files

add missing method which gone away during merge

remove methods from session controller which are now in its own
controller
parent 0c661e6c
No related merge requests found
......@@ -39,13 +39,14 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.services.IUserService;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
import de.thm.arsnova.socket.message.Question;
@Controller
public class SessionController extends AbstractController {
......@@ -79,32 +80,6 @@ public class SessionController extends AbstractController {
return sessionService.getSession(sessionkey);
}
@RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.GET)
@ResponseBody
public Feedback getFeedback(@PathVariable String sessionkey) {
return sessionService.getFeedback(sessionkey);
}
@RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.POST)
@ResponseBody
public Feedback postFeedback(@PathVariable String sessionkey, @RequestBody int value, HttpServletResponse response) {
User user = userService.getUser(SecurityContextHolder.getContext().getAuthentication());
if (sessionService.saveFeedback(sessionkey, value, user)) {
Feedback feedback = sessionService.getFeedback(sessionkey);
if (feedback != null) {
// TODO: Broadcast feedback changes via websocket
response.setStatus(HttpStatus.CREATED.value());
return feedback;
}
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return null;
}
response.setStatus(HttpStatus.BAD_REQUEST.value());
return null;
}
@RequestMapping(value="/session/{sessionkey}/online", method=RequestMethod.POST)
@ResponseBody
public LoggedIn registerAsOnlineUser(@PathVariable String sessionkey, HttpServletResponse response) {
......@@ -132,35 +107,7 @@ public class SessionController extends AbstractController {
return null;
}
@RequestMapping(value="/session/{sessionkey}/question/{questionId}", method=RequestMethod.GET)
@ResponseBody
public Question getQuestion(@PathVariable String sessionkey, @PathVariable String questionId, HttpServletResponse response) {
Question question = sessionService.getQuestion(questionId);
if (question != null && question.getSession().equals(sessionkey)) {
return question;
}
response.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
@RequestMapping(value="/session/{sessionkey}/question", method=RequestMethod.POST)
@ResponseBody
public void postQuestion(@PathVariable String sessionkey, @RequestBody Question question, HttpServletResponse response) {
if (! sessionkey.equals(question.getSession())) {
response.setStatus(HttpStatus.PRECONDITION_FAILED.value());
return;
}
if (sessionService.saveQuestion(question)) {
response.setStatus(HttpStatus.CREATED.value());
return;
}
response.setStatus(HttpStatus.BAD_REQUEST.value());
return;
}
@RequestMapping(value="/socketurl", method=RequestMethod.GET)
@ResponseBody
public String getSocketUrl() {
......@@ -187,16 +134,5 @@ public class SessionController extends AbstractController {
}
return sessions;
}
@RequestMapping(value="/getSkillQuestions/{sessionkey}", method=RequestMethod.GET)
@ResponseBody
public List<Question> getSkillQuestions(@PathVariable String sessionkey, @RequestParam(value="sort", required=false) String sort, HttpServletResponse response) {
List<Question> questions = sessionService.getSkillQuestions(sessionkey, sort);
if(questions == null || questions.isEmpty()) {
response.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
logger.info(questions.toString());
return questions;
}
}
......@@ -69,8 +69,6 @@ import de.thm.arsnova.exceptions.ForbiddenException;
import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.services.IUserService;
import de.thm.arsnova.socket.message.PossibleAnswer;
import de.thm.arsnova.socket.message.Question;
@Component
public class CouchDBDao implements IDatabaseDao {
......@@ -521,4 +519,45 @@ public class CouchDBDao implements IDatabaseDao {
}
return null;
}
@Override
public LoggedIn registerAsOnlineUser(User u, Session s) {
try {
View view = new View("logged_in/all");
view.setKey(URLEncoder.encode("\"" + u.getUsername() + "\"", "UTF-8"));
ViewResults results = this.getDatabase().view(view);
LoggedIn loggedIn = new LoggedIn();
if (results.getJSONArray("rows").optJSONObject(0) != null) {
JSONObject json = results.getJSONArray("rows").optJSONObject(0).optJSONObject("value");
loggedIn = (LoggedIn) JSONObject.toBean(json, LoggedIn.class);
Collection<VisitedSession> visitedSessions = JSONArray.toCollection(json.getJSONArray("visitedSessions"), VisitedSession.class);
loggedIn.setVisitedSessions(new ArrayList<VisitedSession>(visitedSessions));
}
loggedIn.setUser(u.getUsername());
loggedIn.setSessionId(s.get_id());
loggedIn.addVisitedSession(s);
JSONObject json = JSONObject.fromObject(loggedIn);
Document doc = new Document(json);
if (doc.getId() == "") {
// If this is a new user without a logged_in document, we have to remove the following
// pre-filled fields. Otherwise, CouchDB will take these empty fields as genuine
// identifiers, and will throw errors afterwards.
doc.remove("_id");
doc.remove("_rev");
}
this.getDatabase().saveDocument(doc);
LoggedIn l = (LoggedIn) JSONObject.toBean(doc.getJSONObject(), LoggedIn.class);
Collection<VisitedSession> visitedSessions = JSONArray.toCollection(doc.getJSONObject().getJSONArray("visitedSessions"), VisitedSession.class);
l.setVisitedSessions(new ArrayList<VisitedSession>(visitedSessions));
return l;
} catch (UnsupportedEncodingException e) {
return null;
} catch (IOException e) {
return null;
}
}
}
......@@ -47,6 +47,7 @@ public interface ISessionService {
public List<Session> getMySessions(String username);
public boolean saveQuestion(Question question);
public Question getQuestion(String id);
public LoggedIn registerAsOnlineUser(User user, String sessionkey);
public List<Question> getSkillQuestions(String sessionkey, String sort);
public int getSkillQuestionCount(String sessionkey);
}
\ No newline at end of file
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