From 4d312f1313a733d7f8396a3489c672fd1849879d Mon Sep 17 00:00:00 2001 From: Simon Mitchell Date: Fri, 16 Sep 2022 14:34:09 +0100 Subject: [PATCH] feat: add teaching sets --- src/Controllers/TeachingSetController.php | 62 +++++++++++++++++++++++ src/Wrappers/TeachingSet.php | 26 ++++++++++ src/Wrappers/TeachingSetList.php | 33 ++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 src/Controllers/TeachingSetController.php create mode 100644 src/Wrappers/TeachingSet.php create mode 100644 src/Wrappers/TeachingSetList.php diff --git a/src/Controllers/TeachingSetController.php b/src/Controllers/TeachingSetController.php new file mode 100644 index 0000000..fc3d9da --- /dev/null +++ b/src/Controllers/TeachingSetController.php @@ -0,0 +1,62 @@ +endpoint = $this->getDomain() . '/api/teaching/sets'; + } + + /** + * Display a listing of the resource. + * + * @return Collection + * + * @throws GuzzleException + */ + public function index(): Collection + { + $key = $this->institution->getConfigName() . 'teachingSubjects.index'; + + $response = $this->guzzle->request('GET', $this->endpoint, ['headers' => $this->getHeaders()]); + + return Cache::remember($key, $this->getCacheDuration(), function () use ($response) { + return $this->wrapJson($response->getBody()->getContents(), 'sets', TeachingSet::class); + }); + } + + /** + * Show the specified resource. + * + * @param int $id + * @return TeachingSetList + * + * @throws GuzzleException + */ + public function show(int $id): TeachingSetList + { + $response = $this->guzzle->request('GET', $this->endpoint . '/' . $id .'/setList', ['headers' => $this->getHeaders()]); + + $decoded = json_decode($response->getBody()->getContents()); + + return new TeachingSetList($decoded); + } +} diff --git a/src/Wrappers/TeachingSet.php b/src/Wrappers/TeachingSet.php new file mode 100644 index 0000000..7d80974 --- /dev/null +++ b/src/Wrappers/TeachingSet.php @@ -0,0 +1,26 @@ +isHidden = (bool) optional($this->item)->hidden; + } +} diff --git a/src/Wrappers/TeachingSetList.php b/src/Wrappers/TeachingSetList.php new file mode 100644 index 0000000..22e25e8 --- /dev/null +++ b/src/Wrappers/TeachingSetList.php @@ -0,0 +1,33 @@ +isHidden = (bool) optional($this->item)->hidden; + $this->item->students = collect($this->students)->map(function($item){ + return $item->schoolId; + }); + unset($this->students); + $this->students = $this->item->students->toArray(); + } +}