Add push member from array
This commit is contained in:
parent
920ea7a34e
commit
489b80ec12
11
src/Api.php
11
src/Api.php
|
@ -9,6 +9,7 @@ use App\Nami\Exceptions\TooManyLoginAttemptsException;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Zoomyboy\LaravelNami\Backend\Backend;
|
use Zoomyboy\LaravelNami\Backend\Backend;
|
||||||
|
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
|
||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
|
|
||||||
|
@ -64,13 +65,9 @@ class Api {
|
||||||
return collect($this->http()->get(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist')->json()['data']);
|
return collect($this->http()->get(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist')->json()['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putMember(Member $member) {
|
public function putMember(array $attributes) {
|
||||||
$this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, [
|
$member = Member::fromAttributes($attributes);
|
||||||
'vorname' => $member->firstname,
|
$this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami());
|
||||||
'nachname' => $member->lastname,
|
|
||||||
'spitzname' => $member->nickname ?: '',
|
|
||||||
'geschlechtId' => $member->gender_id ?: Gender::getNullValue(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function membershipsOf($memberId): Collection {
|
public function membershipsOf($memberId): Collection {
|
||||||
|
|
|
@ -64,6 +64,19 @@ class Member extends Model {
|
||||||
return (new self($item));
|
return (new self($item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function fromAttributes($attributes) {
|
||||||
|
return new self($attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toNami() {
|
||||||
|
return [
|
||||||
|
'vorname' => $this->firstname,
|
||||||
|
'nachname' => $this->lastname,
|
||||||
|
'spitzname' => $this->nickname ?: '',
|
||||||
|
'geschlechtId' => $this->gender_id ?: Gender::getNullValue(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct($member) {
|
public function __construct($member) {
|
||||||
parent::__construct($member);
|
parent::__construct($member);
|
||||||
}
|
}
|
||||||
|
@ -110,8 +123,4 @@ class Member extends Model {
|
||||||
return Membership::fromNami(Nami::membership($this->id, $id));
|
return Membership::fromNami(Nami::membership($this->id, $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store() {
|
|
||||||
app('nami.api')->putMember($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||||
use Zoomyboy\LaravelNami\LoginException;
|
use Zoomyboy\LaravelNami\LoginException;
|
||||||
use Zoomyboy\LaravelNami\Group;
|
use Zoomyboy\LaravelNami\Group;
|
||||||
use Zoomyboy\LaravelNami\Member;
|
use Zoomyboy\LaravelNami\Member;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class PushMemberTest extends TestCase
|
class PushMemberTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -74,11 +75,8 @@ class PushMemberTest extends TestCase
|
||||||
$this->setCredentials();
|
$this->setCredentials();
|
||||||
Nami::login();
|
Nami::login();
|
||||||
|
|
||||||
$member1 = new Member($this->attributes[0]);
|
Nami::putMember($this->attributes[0]);
|
||||||
$member2 = new Member($this->attributes[1]);
|
Nami::putMember($this->attributes[1]);
|
||||||
|
|
||||||
$member1->store();
|
|
||||||
$member2->store();
|
|
||||||
|
|
||||||
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'
|
||||||
|
|
Loading…
Reference in New Issue