GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Task #4027: User is able to request a question by its id

The URI to be used contains the session id the question is linked to. If
the resulting question object did not match the given session id an error
HTTP - NOT FOUND will be send. This will also be done if no question was
found.
parent 6fe0f02f
......@@ -127,6 +127,17 @@ public class SessionController {
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
......
......@@ -405,4 +405,26 @@ public class CouchDBDao implements IDatabaseDao {
}
return false;
}
@Override
public Question getQuestion(String id) {
try {
View view = new View("skill_question/by_id");
view.setKey(URLEncoder.encode("\"" + id + "\"", "UTF-8"));
ViewResults results = this.getDatabase().view(view);
if (results.getJSONArray("rows").optJSONObject(0) == null) {
return null;
}
return (Question) JSONObject.toBean(
results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"),
Question.class
);
} catch (IOException e) {
logger.error("Could not get question with id {}", id);
}
return null;
}
}
......@@ -34,4 +34,5 @@ public interface IDatabaseDao {
public boolean sessionKeyAvailable(String keyword);
public boolean saveQuestion(Session session, Question question);
public Question getQuestion(String id);
}
\ No newline at end of file
......@@ -45,4 +45,5 @@ public interface ISessionService {
public void broadcastFeedbackChanges(Map<String, Set<String>> affectedUsers, Set<String> allAffectedSessions);
public boolean saveQuestion(Question question);
public Question getQuestion(String id);
}
\ No newline at end of file
......@@ -148,4 +148,9 @@ public class SessionService implements ISessionService {
Session session = this.databaseDao.getSessionFromKeyword(question.getSession());
return this.databaseDao.saveQuestion(session, question);
}
@Override
public Question getQuestion(String id) {
return databaseDao.getQuestion(id);
}
}
Markdown is supported
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