use of org.mamute.dto.FlaggableAndFlagCount in project mamute by caelum.
the class FlagController method topFlagged.
@CustomBrutauthRules(ModeratorOnlyRule.class)
@Get
public void topFlagged() {
List<FlaggableAndFlagCount> flaggedQuestions = flaggables.flaggedButVisible(Question.class);
List<FlaggableAndFlagCount> flaggedAnswers = flaggables.flaggedButVisible(Answer.class);
List<FlaggableAndFlagCount> flaggedComments = flaggables.flaggedButVisible(Comment.class);
List<Question> commentQuestions = new ArrayList<>();
Iterator<FlaggableAndFlagCount> iterator = flaggedComments.iterator();
while (iterator.hasNext()) {
Comment comment = (Comment) iterator.next().getFlaggable();
Question q = questions.fromCommentId(comment.getId());
if (q != null) {
commentQuestions.add(q);
continue;
}
Answer answerFromComment = answers.fromCommentId(comment.getId());
if (answerFromComment != null) {
commentQuestions.add(answerFromComment.getQuestion());
continue;
}
// some flags may be related to news (not questions nor answers)
iterator.remove();
}
result.include("questions", flaggedQuestions);
result.include("answers", flaggedAnswers);
result.include("comments", flaggedComments);
result.include("commentQuestions", commentQuestions);
}
Aggregations