class CorruptionRiskDashboardTablesController extends GenericOCDSController {

    @ApiOperation(value = "Returns data to show in the table on corruption risk overview page."
            + "This is presented as releases only with the information in the table present and unwinded by "
            + "flags.flaggedStats")
    @RequestMapping(value = "/api/corruptionRiskOverviewTable",
            method = {RequestMethod.POST, RequestMethod.GET},
            produces = "application/json")
    public List<Document> corruptionRiskOverviewTable(
            @ModelAttribute @Valid final YearFilterPagingRequest filter) {


        Aggregation agg = newAggregation(
                match(where("flags.flaggedStats.0").exists(true)
                        .andOperator(getYearDefaultFilterCriteria(filter,
                                MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))),
                unwind("flags.flaggedStats"),
                project("ocid", "tender.procuringEntity.name", "tender.tenderPeriod", "flags",
                        "tender.title", "tag")
                        .and("tender.value").as("tender.value").and("awards.value").as("awards.value")
                        .and(MongoConstants.FieldNames.AWARDS_STATUS).as(MongoConstants.FieldNames.AWARDS_STATUS)
                        .andExclude(Fields.UNDERSCORE_ID),
                sort(Sort.Direction.DESC, "flags.flaggedStats.count"),
                skip(filter.getSkip()),
                limit(filter.getPageSize())
        );

        return releaseAgg(agg);
    }

}