Skip to content

Commit

Permalink
Merge pull request #25 from fredbradley/master
Browse files Browse the repository at this point in the history
Fix issue when an app that uses this package hasn't got the cacheDuration config set
  • Loading branch information
fredbradley authored Oct 15, 2021
2 parents 7efce45 + 48119a8 commit ddba3d9
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/AdmissionApplicantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/AdmissionStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/CountryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/CountyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/CurrentPupilController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/EstateBuildingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/EstateRoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/HumanResourcesEmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/NationalityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/OtherSchoolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/PupilBoardingStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/SchoolDepartmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/SchoolHouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/SchoolYearGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/TeachingSubjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/TitleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
2 changes: 2 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ private function getController(string $controllerClassName): string
return self::CONTROLLER_NAMESPACE . $controllerClassName;
}


throw new ControllerNotFound('Could not find Controller: ' . $controllerClassName,
500);

}

/**
Expand Down

0 comments on commit ddba3d9

Please sign in to comment.