From d33c89a8ee6883e6a4cd9a857a04049a0dcf15bd Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 26 Jan 2019 12:09:16 +0100 Subject: [PATCH] Add start and end data to the available_budget list endpoint API --- app/Api/V1/Controllers/AvailableBudgetController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Api/V1/Controllers/AvailableBudgetController.php b/app/Api/V1/Controllers/AvailableBudgetController.php index dee987c5cb..ccdd94b45d 100644 --- a/app/Api/V1/Controllers/AvailableBudgetController.php +++ b/app/Api/V1/Controllers/AvailableBudgetController.php @@ -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);