Skip to content

Commit

Permalink
refactor: fallback for cacheDuration when not found in config, give…
Browse files Browse the repository at this point in the history
… it default value
  • Loading branch information
fredbradley committed Oct 15, 2021
1 parent 870a9cd commit dc238de
Show file tree
Hide file tree
Showing 18 changed files with 25 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));
}
}

0 comments on commit dc238de

Please sign in to comment.