GitLab steht Mittwoch, den 23. September, zwischen 10:00 und 12:00 Uhr aufgrund von Wartungsarbeiten nicht zur Verfügung.

Commit c179b366 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Make API resource for interposed read statistics stateless

The resource by default now includes the total stats. A user parameter
has been added to request user specific data.

This change intends to restore compatibility with ARSnova Overlay.
parent f0fb2bf5
......@@ -54,8 +54,8 @@ public class AudienceQuestionController extends AbstractController {
@RequestMapping(value = "/readcount", method = RequestMethod.GET)
@DeprecatedApi
public final InterposedReadingCount getUnreadInterposedCount(@RequestParam("sessionkey") final String sessionkey) {
return questionService.getInterposedReadingCount(sessionkey);
public final InterposedReadingCount getUnreadInterposedCount(@RequestParam("sessionkey") final String sessionkey, String user) {
return questionService.getInterposedReadingCount(sessionkey, user);
}
@RequestMapping(value = "/", method = RequestMethod.GET)
......
......@@ -59,7 +59,7 @@ public interface IQuestionService {
int getInterposedCount(String sessionKey);
InterposedReadingCount getInterposedReadingCount(String sessionKey);
InterposedReadingCount getInterposedReadingCount(String sessionKey, String username);
List<InterposedQuestion> getInterposedQuestions(String sessionKey);
......
......@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.AbstractMap.SimpleEntry;
import de.thm.arsnova.exceptions.ForbiddenException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -339,16 +340,20 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
@Override
@PreAuthorize("isAuthenticated()")
public InterposedReadingCount getInterposedReadingCount(final String sessionKey) {
public InterposedReadingCount getInterposedReadingCount(final String sessionKey, String username) {
final Session session = databaseDao.getSessionFromKeyword(sessionKey);
final User user = getCurrentUser();
if (session == null) {
throw new NotFoundException();
}
if (session.isCreator(user)) {
if (username == null) {
return databaseDao.getInterposedReadingCount(session);
} else {
return databaseDao.getInterposedReadingCount(session, user);
User currentUser = userService.getCurrentUser();
if (!currentUser.getUsername().equals(username)) {
throw new ForbiddenException();
}
return databaseDao.getInterposedReadingCount(session, currentUser);
}
}
......
Markdown is supported
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