From 82a8f89354a1ef980422c72ec2e1ce7bf949757a Mon Sep 17 00:00:00 2001 From: stollr Date: Sat, 13 Jan 2024 17:58:27 +0100 Subject: [PATCH 1/5] Added model for group type roles --- .../Groups/GroupTypeRole/GroupTypeRole.php | 141 ++++++++++++++++++ .../GroupTypeRole/GroupTypeRoleRequest.php | 32 ++++ .../GroupTypeRoleRequestBuilder.php | 18 +++ 3 files changed, 191 insertions(+) create mode 100644 src/Models/Groups/GroupTypeRole/GroupTypeRole.php create mode 100644 src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php create mode 100644 src/Models/Groups/GroupTypeRole/GroupTypeRoleRequestBuilder.php diff --git a/src/Models/Groups/GroupTypeRole/GroupTypeRole.php b/src/Models/Groups/GroupTypeRole/GroupTypeRole.php new file mode 100644 index 00000000..f995bb64 --- /dev/null +++ b/src/Models/Groups/GroupTypeRole/GroupTypeRole.php @@ -0,0 +1,141 @@ +id = $id; + return $this; + } + + public function getGroupTypeId(): ?int + { + return $this->groupTypeId; + } + + public function setGroupTypeId(?int $groupTypeId) + { + $this->groupTypeId = $groupTypeId; + return $this; + } + + public function getGrowPathId(): ?int + { + return $this->growPathId; + } + + public function setGrowPathId(?int $growPathId) + { + $this->growPathId = $growPathId; + return $this; + } + + + public function getName(): ?string + { + return $this->name; + } + + public function setName(?string $name): static + { + $this->name = $name; + return $this; + } + + public function getNameTranslated(): ?string + { + return $this->nameTranslated; + } + + public function setNameTranslated(?string $nameTranslated): static + { + $this->nameTranslated = $nameTranslated; + return $this; + } + + public function getShorty(): ?string + { + return $this->shorty; + } + + public function setShorty(?string $shorty): static + { + $this->shorty = $shorty; + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(?string $type): static + { + $this->type = $type; + return $this; + } + + public function getIsDefault(): ?bool + { + return $this->isDefault; + } + + public function setIsDefault(?bool $isDefault): static + { + $this->isDefault = $isDefault; + return $this; + } + + public function getIsHidden(): ?bool + { + return $this->isHidden; + } + + public function setIsHidden(?bool $isHidden): static + { + $this->isHidden = $isHidden; + return $this; + } + + public function getIsLeader(): ?bool + { + return $this->isLeader; + } + + public function setIsLeader(?bool $isLeader): static + { + $this->isLeader = $isLeader; + return $this; + } + + public function getSortKey(): ?int + { + return $this->sortKey; + } + + public function setSortKey(?int $sortKey): static + { + $this->sortKey = $sortKey; + return $this; + } +} diff --git a/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php b/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php new file mode 100644 index 00000000..9739082a --- /dev/null +++ b/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php @@ -0,0 +1,32 @@ +all(); + } + + public static function where(string $key, $value): GroupTypeRoleRequestBuilder + { + return (new GroupTypeRoleRequestBuilder())->where($key, $value); + } + + public static function orderBy(string $key, $orderAscending = true): GroupTypeRoleRequestBuilder + { + return (new GroupTypeRoleRequestBuilder())->orderBy($key, $orderAscending); + } + + public static function findOrFail(int $id): GroupTypeRole + { + return (new GroupTypeRoleRequestBuilder())->findOrFail($id); + } + + public static function find(int $id): ?GroupType + { + return (new GroupTypeRoleRequestBuilder())->find($id); + } +} diff --git a/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequestBuilder.php b/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequestBuilder.php new file mode 100644 index 00000000..35e527c1 --- /dev/null +++ b/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequestBuilder.php @@ -0,0 +1,18 @@ + Date: Sat, 13 Jan 2024 18:03:49 +0100 Subject: [PATCH 2/5] Added PR197 to changelog file --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ebf650..9874eb3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Retrieve, create and delete SongArrangement comments ([PR187](https://github.com/5pm-HDH/churchtools-api/pull/187)) - Get GroupTypes ([PR188](https://github.com/5pm-HDH/churchtools-api/pull/188)) +- Get GroupTypeRoles ([PR197](https://github.com/5pm-HDH/churchtools-api/pull/197)) - PHP coding standard ([PR193](https://github.com/5pm-HDH/churchtools-api/pull/193)) ### Changed From ec492fc1a917ff847d3c740cb245bfe2788c4020 Mon Sep 17 00:00:00 2001 From: stollr Date: Sat, 13 Jan 2024 18:12:53 +0100 Subject: [PATCH 3/5] Fixed code style and return type of method --- src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php b/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php index 9739082a..bc8c03df 100644 --- a/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php +++ b/src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php @@ -2,7 +2,6 @@ namespace CTApi\Models\Groups\GroupTypeRole; - class GroupTypeRoleRequest { public static function all(): array @@ -25,7 +24,7 @@ public static function findOrFail(int $id): GroupTypeRole return (new GroupTypeRoleRequestBuilder())->findOrFail($id); } - public static function find(int $id): ?GroupType + public static function find(int $id): ?GroupTypeRole { return (new GroupTypeRoleRequestBuilder())->find($id); } From 8abde4b51f526e9a51ca89eaeef8555da371f64a Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 15 Jan 2024 10:45:21 +0100 Subject: [PATCH 4/5] add request group type --- src/Models/Groups/GroupTypeRole/GroupTypeRole.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Models/Groups/GroupTypeRole/GroupTypeRole.php b/src/Models/Groups/GroupTypeRole/GroupTypeRole.php index f995bb64..7d0da993 100644 --- a/src/Models/Groups/GroupTypeRole/GroupTypeRole.php +++ b/src/Models/Groups/GroupTypeRole/GroupTypeRole.php @@ -3,6 +3,8 @@ namespace CTApi\Models\Groups\GroupTypeRole; use CTApi\Models\AbstractModel; +use CTApi\Models\Groups\Group\GroupType; +use CTApi\Models\Groups\Group\GroupTypeRequest; use CTApi\Traits\Model\FillWithData; use CTApi\Traits\Model\MetaAttribute; @@ -28,6 +30,14 @@ public function setId(?string $id): static return $this; } + public function requestGroupType(): ?GroupType + { + if($this->groupTypeId != null) { + return GroupTypeRequest::find((int) $this->groupTypeId); + } + return null; + } + public function getGroupTypeId(): ?int { return $this->groupTypeId; From 5191c1e8bf96bec6075fabfa93fc90faa0c19def Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 15 Jan 2024 10:46:18 +0100 Subject: [PATCH 5/5] docs unit-test integration-test --- docs/out/GroupAPI.md | 42 ++++ docs/src/ressources/GroupAPI.md | 6 +- .../Requests/GroupTypeRoleRequestTest.php | 69 ++++++ tests/Integration/integration-test-data.json | 24 ++ tests/Unit/Docs/GroupTypeRoleRequestTest.php | 28 +++ tests/Unit/HttpMock/data/api_group_roles.json | 228 ++++++++++++++++++ 6 files changed, 396 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/Requests/GroupTypeRoleRequestTest.php create mode 100644 tests/Unit/Docs/GroupTypeRoleRequestTest.php create mode 100644 tests/Unit/HttpMock/data/api_group_roles.json diff --git a/docs/out/GroupAPI.md b/docs/out/GroupAPI.md index ad92b206..6cd94137 100644 --- a/docs/out/GroupAPI.md +++ b/docs/out/GroupAPI.md @@ -570,4 +570,46 @@ // Output: 0 +``` + +## Group Roles + +```php + use CTApi\Models\Groups\GroupTypeRole\GroupTypeRoleRequest; + + $roles = GroupTypeRoleRequest::all(); + $role = $roles[0]; + + var_dump( $role->getId()); + // Output: 15 + + var_dump( $role->getGroupTypeId()); + // Output: 2 + + $groupType = $role->requestGroupType(); + var_dump( $role->getGrowPathId()); + // Output: null + + var_dump( $role->getName()); + // Output: "Mitarbeiter" + + var_dump( $role->getShorty()); + // Output: "MA" + + var_dump( $role->getType()); + // Output: "participant" + + var_dump( $role->getIsDefault()); + // Output: true + + var_dump( $role->getIsHidden()); + // Output: false + + var_dump( $role->getIsLeader()); + // Output: false + + var_dump( $role->getSortKey()); + // Output: 0 + + ``` \ No newline at end of file diff --git a/docs/src/ressources/GroupAPI.md b/docs/src/ressources/GroupAPI.md index a98e7b1d..5b77bd06 100644 --- a/docs/src/ressources/GroupAPI.md +++ b/docs/src/ressources/GroupAPI.md @@ -22,4 +22,8 @@ {{ \CTApi\Test\Unit\Docs\GroupTypeRequestTest.testGetAll }} -{{ \CTApi\Test\Unit\Docs\GroupTypeRequestTest.testFind }} \ No newline at end of file +{{ \CTApi\Test\Unit\Docs\GroupTypeRequestTest.testFind }} + +## Group Roles + +{{ \CTApi\Test\Unit\Docs\GroupTypeRoleRequestTest.testGetGroupTypeRoleRequest }} \ No newline at end of file diff --git a/tests/Integration/Requests/GroupTypeRoleRequestTest.php b/tests/Integration/Requests/GroupTypeRoleRequestTest.php new file mode 100644 index 00000000..5c1de31e --- /dev/null +++ b/tests/Integration/Requests/GroupTypeRoleRequestTest.php @@ -0,0 +1,69 @@ +id = IntegrationTestData::getResultAsInt("group_type_roles", "any_group_type_role.id"); + } + + public function testGetAll() + { + CTLog::enableHttpLog(); + $groupTypeRoles = GroupTypeRoleRequest::all(); + + $foundGroupTypeRole = null; + foreach ($groupTypeRoles as $groupTypeRole) { + if ($groupTypeRole->getIdAsInteger() === $this->id) { + $foundGroupTypeRole = $groupTypeRole; + } + } + + $this->assertNotNull($foundGroupTypeRole); + $this->assertGroupTypeRole($foundGroupTypeRole); + } + + public function testGetGroupTypeRole() + { + $groupTypeRole = GroupTypeRoleRequest::findOrFail($this->id); + $this->assertGroupTypeRole($groupTypeRole); + + $groupType = $groupTypeRole->requestGroupType(); + $this->assertGroupType($groupType); + } + + private function assertGroupTypeRole(GroupTypeRole $groupTypeRole): void + { + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.id", $groupTypeRole->getGroupTypeId()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.name", $groupTypeRole->getName()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.shorty", $groupTypeRole->getShorty()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.type", $groupTypeRole->getType()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.isDefault", $groupTypeRole->getIsDefault()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.isHidden", $groupTypeRole->getIsHidden()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.isLeader", $groupTypeRole->getIsLeader()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.sortKey", $groupTypeRole->getSortKey()); + } + + private function assertGroupType(GroupType $groupType): void + { + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.id", $groupType->getId()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.availableForNewPerson", $groupType->getAvailableForNewPerson()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.isLeaderNecessary", $groupType->getIsLeaderNecessary()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.name", $groupType->getName()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.permissionDepth", $groupType->getPermissionDepth()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.shorty", $groupType->getShorty()); + $this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.sortKey", $groupType->getSortKey()); + } +} diff --git a/tests/Integration/integration-test-data.json b/tests/Integration/integration-test-data.json index ffa91467..f1e85653 100644 --- a/tests/Integration/integration-test-data.json +++ b/tests/Integration/integration-test-data.json @@ -113,6 +113,30 @@ } } }, + "group_type_roles": { + "description": "Get group type roles.", + "result": { + "any_group_type_role": { + "id": 12, + "groupType": { + "id": 1, + "availableForNewPerson": false, + "isLeaderNecessary": true, + "name": "Kleingruppe", + "permissionDepth": 1, + "shorty": "KG", + "sortKey": 0 + }, + "name": "Organisator", + "shorty": "O", + "type": "participant", + "isDefault": false, + "isHidden": false, + "isLeader": false, + "sortKey": 4 + } + } + }, "update_group_member": { "description": "Add person to group and remove them again.", "filter": { diff --git a/tests/Unit/Docs/GroupTypeRoleRequestTest.php b/tests/Unit/Docs/GroupTypeRoleRequestTest.php new file mode 100644 index 00000000..4798945d --- /dev/null +++ b/tests/Unit/Docs/GroupTypeRoleRequestTest.php @@ -0,0 +1,28 @@ +assertEquals(15, $role->getId()); + $this->assertEquals(2, $role->getGroupTypeId()); + $groupType = $role->requestGroupType(); + $this->assertEquals(null, $role->getGrowPathId()); + $this->assertEquals("Mitarbeiter", $role->getName()); + $this->assertEquals("MA", $role->getShorty()); + $this->assertEquals("participant", $role->getType()); + $this->assertEquals(true, $role->getIsDefault()); + $this->assertEquals(false, $role->getIsHidden()); + $this->assertEquals(false, $role->getIsLeader()); + $this->assertEquals(0, $role->getSortKey()); + } + +} diff --git a/tests/Unit/HttpMock/data/api_group_roles.json b/tests/Unit/HttpMock/data/api_group_roles.json new file mode 100644 index 00000000..65e3eef9 --- /dev/null +++ b/tests/Unit/HttpMock/data/api_group_roles.json @@ -0,0 +1,228 @@ +{ + "data": [ + { + "id": 15, + "groupTypeId": 2, + "name": "Mitarbeiter", + "nameTranslated": "Mitarbeiter", + "shorty": "MA", + "sortKey": 0, + "type": "participant", + "isDefault": true, + "isHidden": false, + "growPathId": null, + "isLeader": false + }, + { + "id": 8, + "groupTypeId": 1, + "name": "Teilnehmer", + "nameTranslated": "Teilnehmer", + "shorty": "T", + "sortKey": 0, + "type": "participant", + "isDefault": true, + "isHidden": false, + "growPathId": null, + "isLeader": false + }, + { + "id": 22, + "groupTypeId": 3, + "name": "Teilnehmer", + "nameTranslated": "Teilnehmer", + "shorty": "T", + "sortKey": 0, + "type": "participant", + "isDefault": true, + "isHidden": false, + "growPathId": null, + "isLeader": false + }, + { + "id": 29, + "groupTypeId": 4, + "name": "Teilnehmer", + "nameTranslated": "Teilnehmer", + "shorty": "T", + "sortKey": 0, + "type": "participant", + "isDefault": true, + "isHidden": false, + "growPathId": null, + "isLeader": false + }, + { + "id": 9, + "groupTypeId": 1, + "name": "Leiter", + "nameTranslated": "Leiter", + "shorty": "L", + "sortKey": 1, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 16, + "groupTypeId": 2, + "name": "Leiter", + "nameTranslated": "Leiter", + "shorty": "L", + "sortKey": 1, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 23, + "groupTypeId": 3, + "name": "Leiter", + "nameTranslated": "Leiter", + "shorty": "L", + "sortKey": 1, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 30, + "groupTypeId": 4, + "name": "Leiter", + "nameTranslated": "Leiter", + "shorty": "L", + "sortKey": 1, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 10, + "groupTypeId": 1, + "name": "Co-Leiter", + "nameTranslated": "Co-Leiter", + "shorty": "CoL", + "sortKey": 2, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 17, + "groupTypeId": 2, + "name": "Co-Leiter", + "nameTranslated": "Co-Leiter", + "shorty": "CoL", + "sortKey": 2, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 24, + "groupTypeId": 3, + "name": "Co-Leiter", + "nameTranslated": "Co-Leiter", + "shorty": "CoL", + "sortKey": 2, + "type": "leader", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": true + }, + { + "id": 11, + "groupTypeId": 1, + "name": "Coach", + "nameTranslated": "Coach", + "shorty": "Coa", + "sortKey": 3, + "type": "participant", + "isDefault": false, + "isHidden": true, + "growPathId": null, + "isLeader": false + }, + { + "id": 18, + "groupTypeId": 2, + "name": "Coach", + "nameTranslated": "Coach", + "shorty": "Coa", + "sortKey": 3, + "type": "participant", + "isDefault": false, + "isHidden": true, + "growPathId": null, + "isLeader": false + }, + { + "id": 25, + "groupTypeId": 3, + "name": "Coach", + "nameTranslated": "Coach", + "shorty": "Coa", + "sortKey": 3, + "type": "participant", + "isDefault": false, + "isHidden": true, + "growPathId": null, + "isLeader": false + }, + { + "id": 12, + "groupTypeId": 1, + "name": "Organisator", + "nameTranslated": "Organisator", + "shorty": "O", + "sortKey": 4, + "type": "participant", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": false + }, + { + "id": 19, + "groupTypeId": 2, + "name": "Organisator", + "nameTranslated": "Organisator", + "shorty": "O", + "sortKey": 4, + "type": "participant", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": false + }, + { + "id": 26, + "groupTypeId": 3, + "name": "Organisator", + "nameTranslated": "Organisator", + "shorty": "O", + "sortKey": 4, + "type": "participant", + "isDefault": false, + "isHidden": false, + "growPathId": null, + "isLeader": false + } + ], + "meta": { + "count": 17 + } +} \ No newline at end of file