class TendersByItemClassification extends GenericOCDSController {

    @ApiOperation(value = "This should show the number of tenders per tender.items.classification."
            + "The tender date is taken from tender.tenderPeriod.startDate.")
    @RequestMapping(value = "/api/tendersByItemClassification", method = { RequestMethod.POST,
            RequestMethod.GET }, produces = "application/json")
    public List<Document> tendersByItemClassification(
            @ModelAttribute @Valid final YearFilterPagingRequest filter) {

        DBObject project = new BasicDBObject();
        project.put(Fields.UNDERSCORE_ID, 0);
        project.put("tender." + Keys.ITEMS_CLASSIFICATION, 1);
        project.put(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, 1);

        Aggregation agg = newAggregation(
                match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true)
                        .andOperator(getYearDefaultFilterCriteria(filter,
                                MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))),
                new CustomProjectionOperation(project), unwind("tender.items"),
                group("$tender." + Keys.ITEMS_CLASSIFICATION).count().as(Keys.TOTAL_TENDERS)
                        .sum(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT).as(Keys.TOTAL_TENDER_AMOUNT),
                sort(Direction.ASC, Fields.UNDERSCORE_ID));

        return releaseAgg(agg);
    }

}