diff --git a/src/Api.php b/src/Api.php index da9cdb3..7ee0e3a 100644 --- a/src/Api.php +++ b/src/Api.php @@ -100,6 +100,12 @@ class Api { }); } + public function nationalities(): Collection { + return collect($this->http()->get(self::$url."/ica/rest/baseadmin/staatsangehoerigkeit")['data'])->map(function($gender) { + return Nationality::fromNami($gender); + }); + } + // ------------------------------------- public function fees() { @@ -110,14 +116,6 @@ class Api { return json_decode((string)$response->getBody()); } - public function nationalities() { - $response = $this->client->get("/ica/rest/baseadmin/staatsangehoerigkeit", [ - 'cookies' => $this->cookie - ]); - - return json_decode((string)$response->getBody()); - } - public function confessions() { $response = $this->client->get("/ica/rest/baseadmin/konfession", [ 'cookies' => $this->cookie diff --git a/src/Member.php b/src/Member.php index 28758fd..aa846bb 100644 --- a/src/Member.php +++ b/src/Member.php @@ -30,7 +30,8 @@ class Member extends Model { 'telefax' => 'fax', 'email' => 'email', 'geschlechtId' => 'gender_id', - 'emailVertretungsberechtigter' => 'email_parents' + 'emailVertretungsberechtigter' => 'email_parents', + 'staatsangehoerigkeitId' => 'nationality_id' ]; protected $guarded = []; @@ -42,7 +43,6 @@ class Member extends Model { return [ data_get(static::$overviewAttributes, $key, $key) => $item ]; }) ->toArray(); - return (new self($item)); } diff --git a/src/Nationality.php b/src/Nationality.php new file mode 100644 index 0000000..052ec7b --- /dev/null +++ b/src/Nationality.php @@ -0,0 +1,23 @@ +only(['descriptor', 'id']) + ->mapWithKeys(function($item,$key) { + if ($key == 'id') { return ['id' => $item]; } + return ['name' => $item]; + })->toArray(); + + return (new self($item)); + } + +} diff --git a/tests/Unit/PullMemberTest.php b/tests/Unit/PullMemberTest.php index 88d1b23..a40e008 100644 --- a/tests/Unit/PullMemberTest.php +++ b/tests/Unit/PullMemberTest.php @@ -31,6 +31,7 @@ class PullMemberTest extends TestCase 'email' => ['email', ['test@example.com', 'test2@example.com']], 'email_parents' => ['email_parents', ['testp@example.com', 'test2p@example.com']], 'gender_id' => ['gender_id', [19, null]], + 'nationality_id' => ['nationality_id', [1054, null]], ]; } diff --git a/tests/Unit/PullNationalityTest.php b/tests/Unit/PullNationalityTest.php new file mode 100644 index 0000000..c70038b --- /dev/null +++ b/tests/Unit/PullNationalityTest.php @@ -0,0 +1,32 @@ +login(), [ + 'https://nami.dpsg.de/ica/rest/baseadmin/staatsangehoerigkeit' => Http::response($this->fakeJson('nationalities.json')) + ])); + + $this->setCredentials(); + + Nami::login(); + + $this->assertEquals([ + ['name' => 'deutsch', 'id' => 1054] + ], Nami::nationalities()->toArray()); + + Http::assertSentCount(3); + } + +} diff --git a/tests/json/member-17.json b/tests/json/member-17.json index f0420c1..1dce126 100644 --- a/tests/json/member-17.json +++ b/tests/json/member-17.json @@ -13,7 +13,7 @@ "ersteTaetigkeit": null, "nameZusatz": "", "id": 17, - "staatsangehoerigkeitId": 1054, + "staatsangehoerigkeitId": null, "version": 17, "sonst01": false, "sonst02": false, diff --git a/tests/json/nationalities.json b/tests/json/nationalities.json new file mode 100644 index 0000000..7b621cd --- /dev/null +++ b/tests/json/nationalities.json @@ -0,0 +1,41 @@ +{ + "success": true, + "data": + [ + { + "descriptor": "deutsch", + "name": "", + "representedClass": "de.iconcept.nami.entity.base.Staatsangehoerigkeit", + "id": 1054 + } + ], + "responseType": "OK", + "totalEntries": 255, + "metaData": + { + "totalProperty": "totalEntries", + "root": "data", + "id": "id", + "fields": + [ + { + "name": "id", + "header": null, + "hidden": false, + "width": 80 + }, + { + "name": "descriptor", + "header": null, + "hidden": false, + "flex": 3 + }, + { + "name": "name", + "header": null, + "hidden": false, + "flex": 3 + } + ] + } +}