Skip to content
Snippets Groups Projects
Commit cb45cf97 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

API-Changes (QuestionByAudienceController):

Removed sessionKey from routes if it is not needed.
Changed sessionKey from PathVariable to RequestParam if still needed.
/session/{sessionKey}/question/* => /question/byaudience/*
Added redirections for legacy routes to LegacyController.
parent 75f9284d
Branches
Tags
No related merge requests found
......@@ -92,6 +92,36 @@ public class LegacyController extends AbstractController {
return String.format("forward:/question/bylecturer/myanswers?sessionkey=%s", sessionKey);
}
@RequestMapping(value = "/session/{sessionKey}/interposed")
public final String redirectQuestionByAudience(
@PathVariable final String sessionKey,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
return String.format("forward:/question/byaudience/?sessionkey=%s", sessionKey);
}
@RequestMapping(value = "/session/{sessionKey}/interposedcount")
public final String redirectQuestionByAudienceCount(
@PathVariable final String sessionKey,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
return String.format("forward:/question/byaudience/count?sessionkey=%s", sessionKey);
}
@RequestMapping(value = "/session/{sessionKey}/interposedreadingcount")
public final String redirectQuestionByAudienceReadCount(
@PathVariable final String sessionKey,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
return String.format("forward:/question/byaudience/readcount?sessionkey=%s", sessionKey);
}
/* generalized routes */
......@@ -118,4 +148,27 @@ public class LegacyController extends AbstractController {
return String.format("forward:/question/bylecturer/%s/%s?sessionkey=%s", arg1, arg2, sessionKey);
}
@RequestMapping(value = "/session/{sessionKey}/interposed/{arg1}")
public final String redirectQuestionByAudienceWithOneArgument(
@PathVariable final String sessionKey,
@PathVariable final String arg1,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
return String.format("forward:/question/byaudience/%s?sessionkey=%s", arg1, sessionKey);
}
@RequestMapping(value = "/session/{sessionKey}/interposed/{arg1}/{arg2}")
public final String redirectQuestionByAudienceWithTwoArguments(
@PathVariable final String sessionKey,
@PathVariable final String arg1,
@PathVariable final String arg2,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
return String.format("forward:/question/byaudience/%s/%s?sessionkey=%s", arg1, arg2, sessionKey);
}
}
......@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import de.thm.arsnova.entities.InterposedQuestion;
......@@ -38,6 +39,7 @@ import de.thm.arsnova.entities.InterposedReadingCount;
import de.thm.arsnova.services.IQuestionService;
@Controller
@RequestMapping("/question/byaudience")
public class QuestionByAudienceController extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(QuestionByAudienceController.class);
......@@ -45,47 +47,47 @@ public class QuestionByAudienceController extends AbstractController {
@Autowired
private IQuestionService questionService;
@RequestMapping(value = "/session/{sessionKey}/interposedcount", method = RequestMethod.GET)
@RequestMapping(value = "/count", method = RequestMethod.GET)
@ResponseBody
public final int getInterposedCount(
@PathVariable final String sessionKey,
@RequestParam final String sessionkey,
final HttpServletResponse response
) {
return questionService.getInterposedCount(sessionKey);
return questionService.getInterposedCount(sessionkey);
}
@RequestMapping(value = "/session/{sessionKey}/interposedreadingcount", method = RequestMethod.GET)
@RequestMapping(value = "/readcount", method = RequestMethod.GET)
@ResponseBody
public final InterposedReadingCount getUnreadInterposedCount(
@PathVariable final String sessionKey,
@RequestParam final String sessionkey,
final HttpServletResponse response
) {
return questionService.getInterposedReadingCount(sessionKey);
return questionService.getInterposedReadingCount(sessionkey);
}
@RequestMapping(value = "/session/{sessionKey}/interposed", method = RequestMethod.GET)
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public final List<InterposedQuestion> getInterposedQuestions(
@PathVariable final String sessionKey,
@RequestParam final String sessionkey,
final HttpServletResponse response
) {
return questionService.getInterposedQuestions(sessionKey);
return questionService.getInterposedQuestions(sessionkey);
}
@RequestMapping(value = "/session/{sessionKey}/interposed/{questionId}", method = RequestMethod.GET)
@RequestMapping(value = "/{questionId}", method = RequestMethod.GET)
@ResponseBody
public final InterposedQuestion getInterposedQuestions(
@PathVariable final String sessionKey,
@RequestParam final String sessionkey,
@PathVariable final String questionId,
final HttpServletResponse response
) {
return questionService.readInterposedQuestion(sessionKey, questionId);
return questionService.readInterposedQuestion(questionId);
}
@RequestMapping(value = "/session/{sessionkey}/interposed", method = RequestMethod.POST)
@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseBody
public final void postInterposedQuestion(
@PathVariable final String sessionkey,
@RequestParam final String sessionkey,
@RequestBody final InterposedQuestion question,
final HttpServletResponse response
) {
......@@ -103,10 +105,9 @@ public class QuestionByAudienceController extends AbstractController {
return;
}
@RequestMapping(value = "/session/{sessionkey}/interposed/{questionId}", method = RequestMethod.DELETE)
@RequestMapping(value = "/{questionId}", method = RequestMethod.DELETE)
@ResponseBody
public final void deleteInterposedQuestion(
@PathVariable final String sessionkey,
@PathVariable final String questionId,
final HttpServletResponse response
) {
......
......@@ -61,6 +61,6 @@ public interface IQuestionService {
List<InterposedQuestion> getInterposedQuestions(String sessionKey);
InterposedQuestion readInterposedQuestion(String sessionKey, String questionId);
InterposedQuestion readInterposedQuestion(String questionId);
}
......@@ -178,13 +178,10 @@ public class QuestionService implements IQuestionService {
@Override
@Authenticated
public InterposedQuestion readInterposedQuestion(String sessionKey, String questionId) {
public InterposedQuestion readInterposedQuestion(String questionId) {
try {
InterposedQuestion question = databaseDao.getInterposedQuestion(questionId);
Session session = this.databaseDao.getSessionFromKeyword(sessionKey);
if (session == null || !session.getKeyword().equals(question.getSessionId())) {
throw new NotFoundException();
}
Session session = this.databaseDao.getSessionFromKeyword(question.getSessionId());
User user = this.userService.getCurrentUser();
if (session.isCreator(user)) {
......
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