Skip to content
Snippets Groups Projects
Commit ff7993d8 authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Fixed #6619: Added method to delete all questions of session

parent 62fa5edc
No related merge requests found
......@@ -146,6 +146,12 @@ public class LecturerQuestionController extends AbstractController {
return questions;
}
@RequestMapping(value = { "/" }, method = RequestMethod.DELETE)
@ResponseBody
public final void deleteSkillQuestions(@RequestParam final String sessionkey, final HttpServletResponse response) {
this.questionService.deleteAllQuestions(sessionkey);
}
@RequestMapping(value = "/count", method = RequestMethod.GET)
@ResponseBody
public final int getSkillQuestionCount(@RequestParam final String sessionkey, final HttpServletResponse response) {
......
......@@ -781,6 +781,24 @@ public class CouchDBDao implements IDatabaseDao {
LOGGER.error("IOException: Could not delete question {}", question.get_id());
}
}
@Override
public final void deleteAllQuestionsWithAnswers(Session session) {
try {
View view = new View("skill_question/by_session");
view.setStartKey("[" + URLEncoder.encode("\"" + session.get_id() + "\"", "UTF-8") + "]");
view.setEndKey("[" + URLEncoder.encode("\"" + session.get_id() + "\", {}", "UTF-8") + "]");
ViewResults results = this.getDatabase().view(view);
for (Document d : results.getResults()) {
Question q = new Question();
q.set_id(d.getId());
this.deleteQuestionWithAnswers(q);
}
} catch (IOException e) {
LOGGER.error("IOException: Could not delete questions for session {}", session.getKeyword());
}
}
private void deleteDocument(final String documentId) throws IOException {
Document d = this.getDatabase().getDocument(documentId);
......
......@@ -69,6 +69,8 @@ public interface IDatabaseDao {
void deleteQuestionWithAnswers(Question question);
void deleteAllQuestionsWithAnswers(Session session);
List<String> getUnAnsweredQuestionIds(Session session, User user);
Answer getMyAnswer(String questionId, int piRound);
......
......@@ -41,6 +41,8 @@ public interface IQuestionService {
void deleteQuestion(String questionId);
void deleteAllQuestions(String sessionKeyword);
List<String> getUnAnsweredQuestionIds(String sessionKey);
Answer getMyAnswer(String questionId);
......
......@@ -148,6 +148,17 @@ public class QuestionService implements IQuestionService {
databaseDao.deleteQuestionWithAnswers(question);
}
@Override
@Authenticated
public void deleteAllQuestions(String sessionKeyword) {
User user = userService.getCurrentUser();
Session session = databaseDao.getSession(sessionKeyword);
if (user == null || session == null || !session.isCreator(user)) {
throw new UnauthorizedException();
}
databaseDao.deleteAllQuestionsWithAnswers(session);
}
@Override
@Authenticated
public void deleteInterposedQuestion(String questionId) {
......
......@@ -439,4 +439,10 @@ public class StubDatabaseDao implements IDatabaseDao {
public void deleteSession(Session session) {
// TODO Auto-generated method stub
}
@Override
public void deleteAllQuestionsWithAnswers(Session session) {
// TODO Auto-generated method stub
}
}
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