Add: Pull Confession from member

This commit is contained in:
philipp lang 2020-06-30 00:01:17 +02:00
parent ca09bd7560
commit 5a4fa4d5ec
7 changed files with 106 additions and 11 deletions

View File

@ -106,6 +106,12 @@ class Api {
}); });
} }
public function confessions(): Collection {
return collect($this->http()->get(self::$url."/ica/rest/baseadmin/konfession")['data'])->map(function($gender) {
return Confession::fromNami($gender);
});
}
// ------------------------------------- // -------------------------------------
public function fees() { public function fees() {
@ -116,15 +122,6 @@ class Api {
return json_decode((string)$response->getBody()); return json_decode((string)$response->getBody());
} }
public function confessions() {
$response = $this->client->get("/ica/rest/baseadmin/konfession", [
'cookies' => $this->cookie
]);
return json_decode((string)$response->getBody());
}
public function regions() { public function regions() {
$response = $this->client->get("/ica/rest/baseadmin/region", [ $response = $this->client->get("/ica/rest/baseadmin/region", [
'cookies' => $this->cookie 'cookies' => $this->cookie

23
src/Confession.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
class Confession 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));
}
}

View File

@ -31,7 +31,8 @@ class Member extends Model {
'email' => 'email', 'email' => 'email',
'geschlechtId' => 'gender_id', 'geschlechtId' => 'gender_id',
'emailVertretungsberechtigter' => 'email_parents', 'emailVertretungsberechtigter' => 'email_parents',
'staatsangehoerigkeitId' => 'nationality_id' 'staatsangehoerigkeitId' => 'nationality_id',
'konfessionId' => 'confession_id'
]; ];
protected $guarded = []; protected $guarded = [];

View File

@ -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 PullConfessionTest extends TestCase
{
public function test_get_all_confessions() {
Http::fake(array_merge($this->login(), [
'https://nami.dpsg.de/ica/rest/baseadmin/konfession' => Http::response($this->fakeJson('confession.json'), 200)
]));
$this->setCredentials();
Nami::login();
$this->assertEquals([
1 => 'römisch-katholisch'
], Nami::confessions()->pluck('name', 'id')->toArray());
Http::assertSentCount(3);
}
}

View File

@ -32,6 +32,7 @@ class PullMemberTest extends TestCase
'email_parents' => ['email_parents', ['testp@example.com', 'test2p@example.com']], 'email_parents' => ['email_parents', ['testp@example.com', 'test2p@example.com']],
'gender_id' => ['gender_id', [19, null]], 'gender_id' => ['gender_id', [19, null]],
'nationality_id' => ['nationality_id', [1054, null]], 'nationality_id' => ['nationality_id', [1054, null]],
'confession_id' => ['confession_id', [1, null]],
]; ];
} }

View File

@ -0,0 +1,41 @@
{
"success": true,
"data":
[
{
"descriptor": "römisch-katholisch",
"name": "",
"representedClass": "de.iconcept.nami.entity.base.Konfession",
"id": 1
}
],
"responseType": "OK",
"totalEntries": 10,
"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
}
]
}
}

View File

@ -30,7 +30,7 @@
"status": "Aktiv", "status": "Aktiv",
"konfession": null, "konfession": null,
"fixBeitrag": null, "fixBeitrag": null,
"konfessionId": null, "konfessionId": 1,
"zeitschriftenversand": true, "zeitschriftenversand": true,
"pfadfinder": null, "pfadfinder": null,
"telefon3": "+11111", "telefon3": "+11111",