class TenderPriceByTypeYearController extends GenericOCDSController {

    @ApiOperation(value = "Returns the tender price by OCDS type (procurementMethod), by year. "
            + "The OCDS type is read from tender.procurementMethod. The tender price is read from "
            + MongoConstants.FieldNames.TENDER_VALUE_AMOUNT)
    @RequestMapping(value = "/api/tenderPriceByProcurementMethod", method = {RequestMethod.POST,
            RequestMethod.GET}, produces = "application/json")
    public List<Document> tenderPriceByProcurementMethod(
            @ModelAttribute @Valid final YearFilterPagingRequest filter) {

        DBObject project = new BasicDBObject();
        project.put("tender." + Keys.PROCUREMENT_METHOD, 1);
        project.put("tender.value", 1);

        Aggregation agg = newAggregation(
                match(where("awards").elemMatch(where("status").is(Award.Status.active.toString()))
                        .and("tender.value")
                        .exists(true)
                        .andOperator(getYearDefaultFilterCriteria(
                                filter,
                                MongoConstants.FieldNames.TENDER_PERIOD_START_DATE
                        ))),
                new CustomProjectionOperation(project), group("tender." + Keys.PROCUREMENT_METHOD)
                        .sum(ref(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT)).as(Keys.TOTAL_TENDER_AMOUNT),
                project().and(Fields.UNDERSCORE_ID).as(Keys.PROCUREMENT_METHOD).andInclude(Keys.TOTAL_TENDER_AMOUNT)
                        .andExclude(Fields.UNDERSCORE_ID),
                sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT)
        );

        return releaseAgg(agg);
    }

}