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

Implemented update API for questions

parent 8cfa1d88
No related merge requests found
......@@ -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)
......
......@@ -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);
}
}
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