Add parent_id in groups

This commit is contained in:
philipp lang 2020-07-04 17:50:55 +02:00
parent 1a685ffd40
commit 2e07084706
3 changed files with 10 additions and 10 deletions

View File

@ -98,9 +98,8 @@ class Api {
}
public function groups($parentGroupId = null): Collection {
$parentGroupId = $parentGroupId ?: 'root';
return collect($this->http()->get(self::$url.'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.$parentGroupId)->json()['data'])->map(function($group) {
return Group::fromResponse($group);
return collect($this->http()->get(self::$url.'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroupId ?: 'root'))->json()['data'])->map(function($group) use ($parentGroupId) {
return Group::fromResponse($group, $parentGroupId);
});
}

View File

@ -9,16 +9,17 @@ class Group implements Arrayable {
public $name;
public $id;
public static function fromResponse($response) {
public static function fromResponse($response, $parent) {
$group = new self();
$group->name = $response['descriptor'];
$group->id = $response['id'];
$group->parent_id = $parent;
return $group;
}
public function toArray() {
return [ 'id' => $this->id, 'name' => $this->name ];
return [ 'id' => $this->id, 'name' => $this->name, 'parent_id' => $this->parent_id ];
}
public function subgroups() {

View File

@ -29,7 +29,7 @@ class GetGroupsTest extends TestCase
Nami::login();
$this->assertEquals([
['id' => 100, 'name' => 'Group']
['id' => 100, 'name' => 'Group', 'parent_id' => null]
], Nami::groups()->toArray());
Http::assertSent(function($request) {
@ -70,10 +70,10 @@ class GetGroupsTest extends TestCase
$subgroups = Nami::group(100)->subgroups();
$this->assertEquals([
['id' => 101300, 'name' => 'Siebengebirge'],
['id' => 100900, 'name' => 'Sieg'],
['id' => 100900, 'name' => 'Sieg'],
['id' => 101000, 'name' => 'Voreifel']
['id' => 101300, 'parent_id' => 100, 'name' => 'Siebengebirge'],
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
['id' => 101000, 'parent_id' => 100, 'name' => 'Voreifel']
], $subgroups->toArray());
$subgroups->each(function($group) {