Add start and end data to the available_budget list endpoint API

This commit is contained in:
James Cole 2019-01-26 12:09:16 +01:00
parent d0d73c5e3e
commit d33c89a8ee

View File

@ -104,6 +104,17 @@ class AvailableBudgetController extends Controller
// get list of available budgets. Count it and split it.
$collection = $this->repository->getAvailableBudgets();
// filter list on start and end date, if present.
// TODO: put this in the query.
$start = $this->parameters->get('start');
$end = $this->parameters->get('end');
if(null !== $start && null !== $end) {
$collection = $collection->filter(function(AvailableBudget $availableBudget) use ($start, $end) {
return $availableBudget->start_date->gte($start) && $availableBudget->end_date->lte($end);
});
}
$count = $collection->count();
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);