Add create member

This commit is contained in:
philipp lang 2021-06-23 01:57:19 +02:00
parent 38fe258f5c
commit a1b3d132bd
3 changed files with 17 additions and 6 deletions

View File

@ -90,10 +90,18 @@ class Api {
public function putMember(array $attributes) { public function putMember(array $attributes) {
$member = Member::fromAttributes($attributes); $member = Member::fromAttributes($attributes);
$response = $this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami()); if (data_get($attributes, 'id')) {
$response = $this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami());
if (data_get($response->json(), 'success') !== true) {
$this->exception('Update failed', $member->toNami(), $response->json());
}
} else {
$response = $this->http()->post(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id, $member->toNami());
if (data_get($response->json(), 'success') !== true) {
$this->exception('Update failed', $member->toNami(), $response->json());
}
if (data_get($response->json(), 'success') !== true) { return ['id' => $response->json()['data']];
$this->exception('Update failed', $member->toNami(), $response->json());
} }
return $response->json()['data']; return $response->json()['data'];

View File

@ -98,6 +98,8 @@ class Member extends Model {
'nameZusatz' => $this->further_address ?: '', 'nameZusatz' => $this->further_address ?: '',
'konfessionId' => $this->confession_id, 'konfessionId' => $this->confession_id,
'staatsangehoerigkeitText' => $this->other_country ?: '', 'staatsangehoerigkeitText' => $this->other_country ?: '',
'ersteTaetigkeitId' => $this->first_activity_id ?: null,
'ersteUntergliederungId' => $this->first_subactivity_id ?: null,
]; ];
} }

View File

@ -74,15 +74,16 @@ class PushMemberTest extends TestCase
*/ */
public function test_push_a_single_member($key, $values) { public function test_push_a_single_member($key, $values) {
Http::fake(array_merge($this->login(), [ Http::fake(array_merge($this->login(), [
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"id": 16}', 200), 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"success": true, "data": {"id": 16}}', 200),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http::response('{"id": 17}', 200), 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http::response('{"success": true, "data": {"id": 17}}', 200),
])); ]));
$this->setCredentials(); $this->setCredentials();
Nami::login(); Nami::login();
Nami::putMember($this->attributes[0]); Nami::putMember($this->attributes[0]);
Nami::putMember($this->attributes[1]); $res = Nami::putMember($this->attributes[1]);
$this->assertEquals(17, $res['id']);
Http::assertSent(function($request) use ($key, $values) { Http::assertSent(function($request) use ($key, $values) {
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16'