From df0ae96814c84177e9009c77551935f835ce4aac Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 18 Nov 2021 01:54:41 +0100 Subject: [PATCH] Add courses --- src/Api.php | 20 ++++++++++++++++++++ src/Backend/FakeBackend.php | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Api.php b/src/Api.php index 36d0644..9c2deaf 100644 --- a/src/Api.php +++ b/src/Api.php @@ -194,6 +194,26 @@ class Api { return $response->json()['data']; } + public function courses(): Collection + { + $url = self::$url.'/ica/rest/module/baustein'; + $response = $this->http()->get($url); + + return collect($response->json()['data'])->map(function($course) { + return (object) ['name' => $course['descriptor'], 'id' => $course['id']]; + }); + } + + public function coursesFor(int $memberId): Collection + { + $url = self::$url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/flist"; + $response = $this->http()->get($url); + + return collect($response->json()['data'])->map(function($course) { + return (object) ['id' => $course['id'], 'organizer' => $course['veranstalter'], 'course_id' => $course['bausteinId'], 'event_name' => $course['vstgName'], 'completed_at' => $course['vstgTag']]; + }); + } + public function member($groupId, $memberId) { $url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId; $response = $this->http()->get($url); diff --git a/src/Backend/FakeBackend.php b/src/Backend/FakeBackend.php index 42e6ae9..54fe713 100644 --- a/src/Backend/FakeBackend.php +++ b/src/Backend/FakeBackend.php @@ -235,6 +235,16 @@ class FakeBackend { ]) ?: '{}', 200); } } + + foreach ($data as $member) { + if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$member['id']}/flist") { + return Http::response(json_encode([ + 'success' => true, + 'totalEntries' => count($member['courses'] ?? []), + 'data' => collect($member['courses'] ?? []) + ]) ?: '{}', 200); + } + } }); return $this; @@ -254,6 +264,20 @@ class FakeBackend { return $this; } + /** + * @param array $data + */ + public function fakeCourses(array $data): self + { + Http::fake(function($request) use ($data) { + if ($request->url() === 'https://nami.dpsg.de/ica/rest/module/baustein') { + return $this->dataResponse($data); + } + }); + + return $this; + } + /** * @param array $data */