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
Branches
Tags
No related merge requests found
...@@ -80,34 +80,14 @@ public class QuestionByLecturerController extends AbstractController { ...@@ -80,34 +80,14 @@ public class QuestionByLecturerController extends AbstractController {
throw new BadRequestException(); throw new BadRequestException();
} }
@RequestMapping( @RequestMapping(value = "/{questionId}", method = RequestMethod.PUT)
value = "/question/bylecturer/{questionId}",
method = RequestMethod.PUT
)
@ResponseBody @ResponseBody
public final void updateQuestion( public final void updateQuestion(
@PathVariable final String questionId, @PathVariable final String questionId,
@RequestBody final Question question, @RequestBody final Question question,
final HttpServletResponse response final HttpServletResponse response
) { ) {
throw new NoContentException(); this.questionService.update(question);
/* 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;
*/
} }
@RequestMapping(value = "/{questionId}/publish", method = RequestMethod.POST) @RequestMapping(value = "/{questionId}/publish", method = RequestMethod.POST)
......
...@@ -109,7 +109,7 @@ public class QuestionService implements IQuestionService { ...@@ -109,7 +109,7 @@ public class QuestionService implements IQuestionService {
if (question == null) { if (question == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
User user = userService.getCurrentUser(); User user = userService.getCurrentUser();
Session session = databaseDao.getSession(question.getSessionKeyword()); Session session = databaseDao.getSession(question.getSessionKeyword());
if (user == null || session == null || !session.isCreator(user)) { if (user == null || session == null || !session.isCreator(user)) {
...@@ -117,7 +117,6 @@ public class QuestionService implements IQuestionService { ...@@ -117,7 +117,6 @@ public class QuestionService implements IQuestionService {
} }
databaseDao.deleteQuestion(question); databaseDao.deleteQuestion(question);
} }
@Override @Override
@Authenticated @Authenticated
...@@ -126,7 +125,7 @@ public class QuestionService implements IQuestionService { ...@@ -126,7 +125,7 @@ public class QuestionService implements IQuestionService {
if (question == null) { if (question == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
User user = userService.getCurrentUser(); User user = userService.getCurrentUser();
Session session = databaseDao.getSession(question.getSessionKeyword()); Session session = databaseDao.getSession(question.getSessionKeyword());
if (user == null || session == null || !session.isCreator(user)) { if (user == null || session == null || !session.isCreator(user)) {
...@@ -222,7 +221,17 @@ public class QuestionService implements IQuestionService { ...@@ -222,7 +221,17 @@ public class QuestionService implements IQuestionService {
} }
@Override @Override
@Authenticated
public void update(Question question) { 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); 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