Add courses
This commit is contained in:
parent
2ac35dd8c5
commit
df0ae96814
20
src/Api.php
20
src/Api.php
|
@ -194,6 +194,26 @@ class Api {
|
||||||
return $response->json()['data'];
|
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) {
|
public function member($groupId, $memberId) {
|
||||||
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
|
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
|
||||||
$response = $this->http()->get($url);
|
$response = $this->http()->get($url);
|
||||||
|
|
|
@ -235,6 +235,16 @@ class FakeBackend {
|
||||||
]) ?: '{}', 200);
|
]) ?: '{}', 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;
|
return $this;
|
||||||
|
@ -254,6 +264,20 @@ class FakeBackend {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{name: string, id: int}> $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<int, array{name: string, id: int}> $data
|
* @param array<int, array{name: string, id: int}> $data
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue