Add: Pull nationality
This commit is contained in:
parent
c0fe5623a8
commit
ca09bd7560
14
src/Api.php
14
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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Nationality extends Model {
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function fromNami($item) {
|
||||
$item = collect($item)
|
||||
->only(['descriptor', 'id'])
|
||||
->mapWithKeys(function($item,$key) {
|
||||
if ($key == 'id') { return ['id' => $item]; }
|
||||
return ['name' => $item];
|
||||
})->toArray();
|
||||
|
||||
return (new self($item));
|
||||
}
|
||||
|
||||
}
|
|
@ -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]],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
|
||||
class PullNationalityTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_get_all_nationalities() {
|
||||
Http::fake(array_merge($this->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);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
"ersteTaetigkeit": null,
|
||||
"nameZusatz": "",
|
||||
"id": 17,
|
||||
"staatsangehoerigkeitId": 1054,
|
||||
"staatsangehoerigkeitId": null,
|
||||
"version": 17,
|
||||
"sonst01": false,
|
||||
"sonst02": false,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue