From ef1a67f30e8291a43a3b9d60e28b63d87228511b Mon Sep 17 00:00:00 2001 From: Christoph Thelen <christoph.thelen@mni.thm.de> Date: Wed, 13 Feb 2013 15:58:53 +0100 Subject: [PATCH] Implemented update API for questions --- .../QuestionByLecturerController.java | 24 ++----------------- .../thm/arsnova/services/QuestionService.java | 15 +++++++++--- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/thm/arsnova/controller/QuestionByLecturerController.java b/src/main/java/de/thm/arsnova/controller/QuestionByLecturerController.java index 15416422..ca5785b4 100644 --- a/src/main/java/de/thm/arsnova/controller/QuestionByLecturerController.java +++ b/src/main/java/de/thm/arsnova/controller/QuestionByLecturerController.java @@ -80,34 +80,14 @@ public class QuestionByLecturerController extends AbstractController { throw new BadRequestException(); } - @RequestMapping( - value = "/question/bylecturer/{questionId}", - method = RequestMethod.PUT - ) + @RequestMapping(value = "/{questionId}", method = RequestMethod.PUT) @ResponseBody public final void updateQuestion( @PathVariable final String questionId, @RequestBody final Question question, final HttpServletResponse response ) { - throw new NoContentException(); - - /* TODO: Not yet implemented! The following code has been copy-and-pasted from postQuestion */ - /* - if (!sessionkey.equals(question.getSession())) { - response.setStatus(HttpStatus.PRECONDITION_FAILED.value()); - return null; - } - - if (questionService.saveQuestion(question) != null) { - response.setStatus(HttpStatus.CREATED.value()); - return question; - } - - response.setStatus(HttpStatus.BAD_REQUEST.value()); - - return null; - */ + this.questionService.update(question); } @RequestMapping(value = "/{questionId}/publish", method = RequestMethod.POST) diff --git a/src/main/java/de/thm/arsnova/services/QuestionService.java b/src/main/java/de/thm/arsnova/services/QuestionService.java index 51244007..d3d519f5 100644 --- a/src/main/java/de/thm/arsnova/services/QuestionService.java +++ b/src/main/java/de/thm/arsnova/services/QuestionService.java @@ -109,7 +109,7 @@ public class QuestionService implements IQuestionService { if (question == null) { throw new NotFoundException(); } - + User user = userService.getCurrentUser(); Session session = databaseDao.getSession(question.getSessionKeyword()); if (user == null || session == null || !session.isCreator(user)) { @@ -117,7 +117,6 @@ public class QuestionService implements IQuestionService { } databaseDao.deleteQuestion(question); } - @Override @Authenticated @@ -126,7 +125,7 @@ public class QuestionService implements IQuestionService { if (question == null) { throw new NotFoundException(); } - + User user = userService.getCurrentUser(); Session session = databaseDao.getSession(question.getSessionKeyword()); if (user == null || session == null || !session.isCreator(user)) { @@ -222,7 +221,17 @@ public class QuestionService implements IQuestionService { } @Override + @Authenticated public void update(Question question) { + if (databaseDao.getQuestion(question.get_id()) == null) { + throw new NotFoundException(); + } + + User user = userService.getCurrentUser(); + Session session = databaseDao.getSession(question.getSessionKeyword()); + if (user == null || session == null || !session.isCreator(user)) { + throw new UnauthorizedException(); + } this.databaseDao.updateQuestion(question); } } -- GitLab