Add push member from array

This commit is contained in:
philipp lang 2021-05-14 20:10:22 +02:00
parent 920ea7a34e
commit 489b80ec12
3 changed files with 20 additions and 16 deletions

View File

@ -9,6 +9,7 @@ use App\Nami\Exceptions\TooManyLoginAttemptsException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Collection;
use Zoomyboy\LaravelNami\Backend\Backend;
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
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']);
}
public function putMember(Member $member) {
$this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, [
'vorname' => $member->firstname,
'nachname' => $member->lastname,
'spitzname' => $member->nickname ?: '',
'geschlechtId' => $member->gender_id ?: Gender::getNullValue(),
]);
public function putMember(array $attributes) {
$member = Member::fromAttributes($attributes);
$this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami());
}
public function membershipsOf($memberId): Collection {

View File

@ -64,6 +64,19 @@ class Member extends Model {
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) {
parent::__construct($member);
}
@ -110,8 +123,4 @@ class Member extends Model {
return Membership::fromNami(Nami::membership($this->id, $id));
}
public function store() {
app('nami.api')->putMember($this);
}
}

View File

@ -10,6 +10,7 @@ use Zoomyboy\LaravelNami\NamiServiceProvider;
use Zoomyboy\LaravelNami\LoginException;
use Zoomyboy\LaravelNami\Group;
use Zoomyboy\LaravelNami\Member;
use Illuminate\Database\Eloquent\Model;
class PushMemberTest extends TestCase
{
@ -74,11 +75,8 @@ class PushMemberTest extends TestCase
$this->setCredentials();
Nami::login();
$member1 = new Member($this->attributes[0]);
$member2 = new Member($this->attributes[1]);
$member1->store();
$member2->store();
Nami::putMember($this->attributes[0]);
Nami::putMember($this->attributes[1]);
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'