class FrequentTenderersController extends GenericOCDSController {

    @ApiOperation(value = "Counts the tenders/awards where the given supplier id is among the winners. "
            + "This assumes there is only  one active award, which always seems to be the case, per tender. ")
    @RequestMapping(value = "/api/activeAwardsCount",
            method = {RequestMethod.POST, RequestMethod.GET},
            produces = "application/json")
    public List<Document> activeAwardsCount(@ModelAttribute @Valid final YearFilterPagingRequest filter) {

        Aggregation agg = newAggregation(
                match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString())
                        .andOperator(getYearDefaultFilterCriteria(
                                filter,
                                MongoConstants.FieldNames.TENDER_PERIOD_START_DATE
                        ))),
                unwind("awards"),
                match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString())
                        .andOperator(getYearDefaultFilterCriteria(
                                filter.awardFiltering(),
                                MongoConstants.FieldNames.TENDER_PERIOD_START_DATE
                        ))),
                unwind("awards.suppliers"),
                group(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).count().as("cnt"),
                project("cnt").and(Fields.UNDERSCORE_ID).as("supplierId")
                        .andExclude(Fields.UNDERSCORE_ID)
        );

        return releaseAgg(agg);
    }

}