diff --git a/src/Controllers/AdmissionApplicantController.php b/src/Controllers/AdmissionApplicantController.php index 9838959..3776424 100644 --- a/src/Controllers/AdmissionApplicantController.php +++ b/src/Controllers/AdmissionApplicantController.php @@ -52,7 +52,7 @@ public function index(): Collection throw new \Exception($items->count() . ' items were returned instead of ' . $totalCount . ' as specified on page 1.'); } - return Cache::remember($key, config('isams.cacheDuration'), function () use ($items) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($items) { return $items; }); } diff --git a/src/Controllers/AdmissionStatusController.php b/src/Controllers/AdmissionStatusController.php index d98a07b..df787b3 100644 --- a/src/Controllers/AdmissionStatusController.php +++ b/src/Controllers/AdmissionStatusController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', AdmissionStatus::class); }); } diff --git a/src/Controllers/CountryController.php b/src/Controllers/CountryController.php index 33b860f..591037b 100644 --- a/src/Controllers/CountryController.php +++ b/src/Controllers/CountryController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', Country::class); }); } diff --git a/src/Controllers/CountyController.php b/src/Controllers/CountyController.php index bb7a873..ff4a772 100644 --- a/src/Controllers/CountyController.php +++ b/src/Controllers/CountyController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', County::class); }); } diff --git a/src/Controllers/CurrentPupilController.php b/src/Controllers/CurrentPupilController.php index a133f8d..27d9af4 100644 --- a/src/Controllers/CurrentPupilController.php +++ b/src/Controllers/CurrentPupilController.php @@ -52,7 +52,7 @@ public function index(): Collection throw new \Exception($items->count() . ' items were returned instead of ' . $totalCount . ' as specified on page 1.'); } - return Cache::remember($key, config('isams.cacheDuration'), function () use ($items) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($items) { return $items; }); } diff --git a/src/Controllers/EstateBuildingController.php b/src/Controllers/EstateBuildingController.php index 83ec1b6..c041a12 100644 --- a/src/Controllers/EstateBuildingController.php +++ b/src/Controllers/EstateBuildingController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'buildings', EstateBuilding::class); }); } diff --git a/src/Controllers/EstateRoomController.php b/src/Controllers/EstateRoomController.php index 4280104..12b6e9b 100644 --- a/src/Controllers/EstateRoomController.php +++ b/src/Controllers/EstateRoomController.php @@ -32,7 +32,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'rooms', EstateRoom::class); }); } diff --git a/src/Controllers/HumanResourcesEmployeeController.php b/src/Controllers/HumanResourcesEmployeeController.php index 44465d4..60ff441 100644 --- a/src/Controllers/HumanResourcesEmployeeController.php +++ b/src/Controllers/HumanResourcesEmployeeController.php @@ -60,7 +60,7 @@ public function index(): Collection $items = $this->sortBySurname($items); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($items) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($items) { return $items; }); } diff --git a/src/Controllers/LanguageController.php b/src/Controllers/LanguageController.php index 65d14e6..f81a4f7 100644 --- a/src/Controllers/LanguageController.php +++ b/src/Controllers/LanguageController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', Language::class); }); } diff --git a/src/Controllers/NationalityController.php b/src/Controllers/NationalityController.php index e775bb9..568726e 100644 --- a/src/Controllers/NationalityController.php +++ b/src/Controllers/NationalityController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', Nationality::class); }); } diff --git a/src/Controllers/OtherSchoolController.php b/src/Controllers/OtherSchoolController.php index e3316d4..0afceba 100644 --- a/src/Controllers/OtherSchoolController.php +++ b/src/Controllers/OtherSchoolController.php @@ -52,7 +52,7 @@ public function index(): Collection throw new \Exception($items->count() . ' items were returned instead of ' . $totalCount . ' as specified on page 1.'); } - return Cache::remember($key, config('isams.cacheDuration'), function () use ($items) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($items) { return $items; }); } diff --git a/src/Controllers/PupilBoardingStatusController.php b/src/Controllers/PupilBoardingStatusController.php index 2262a13..0af6fc6 100644 --- a/src/Controllers/PupilBoardingStatusController.php +++ b/src/Controllers/PupilBoardingStatusController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', PupilBoardingStatus::class); }); } diff --git a/src/Controllers/SchoolDepartmentController.php b/src/Controllers/SchoolDepartmentController.php index cc98fc5..3101b92 100644 --- a/src/Controllers/SchoolDepartmentController.php +++ b/src/Controllers/SchoolDepartmentController.php @@ -46,7 +46,7 @@ public function index(string $departmentType) $response = $this->guzzle->request('GET', $this->endpoint . '/' . $departmentType, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'departments', SchoolDepartment::class); }); } diff --git a/src/Controllers/SchoolHouseController.php b/src/Controllers/SchoolHouseController.php index 4276053..ec69398 100644 --- a/src/Controllers/SchoolHouseController.php +++ b/src/Controllers/SchoolHouseController.php @@ -32,7 +32,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'houses', House::class); }); } diff --git a/src/Controllers/SchoolYearGroupController.php b/src/Controllers/SchoolYearGroupController.php index 1ddd403..c9d9bd2 100644 --- a/src/Controllers/SchoolYearGroupController.php +++ b/src/Controllers/SchoolYearGroupController.php @@ -32,7 +32,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'yearGroups', YearGroup::class); }); } diff --git a/src/Controllers/TeachingSubjectController.php b/src/Controllers/TeachingSubjectController.php index 616bd8a..739117f 100644 --- a/src/Controllers/TeachingSubjectController.php +++ b/src/Controllers/TeachingSubjectController.php @@ -32,7 +32,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'subjects', TeachingSubject::class); }); } diff --git a/src/Controllers/TitleController.php b/src/Controllers/TitleController.php index 09c3ade..d4fa631 100644 --- a/src/Controllers/TitleController.php +++ b/src/Controllers/TitleController.php @@ -33,7 +33,7 @@ public function index(): Collection $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); - return Cache::remember($key, config('isams.cacheDuration'), function () use ($response) { + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { return $this->wrapJson($response->getBody()->getContents(), 'items', Title::class); }); } diff --git a/src/Endpoint.php b/src/Endpoint.php index c89bd23..572f610 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -191,4 +191,12 @@ protected function response(int $expectedStatusCode, $response, $data, array $er return response()->json($json, $response->getStatusCode()); } + + /** + * @return \Carbon\Carbon + */ + protected function getCacheDuration() + { + return config('isams.cacheDuration', now()->addHours(12)); + } } diff --git a/src/Facade.php b/src/Facade.php index 7841402..300072f 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -64,8 +64,10 @@ private function getController(string $controllerClassName): string return self::CONTROLLER_NAMESPACE . $controllerClassName; } + throw new ControllerNotFound('Could not find Controller: ' . $controllerClassName, 500); + } /**