diff --git a/docs/out/GroupAPI.md b/docs/out/GroupAPI.md index 2394568b..a31076e9 100644 --- a/docs/out/GroupAPI.md +++ b/docs/out/GroupAPI.md @@ -612,4 +612,22 @@ // Output: 0 -``` \ No newline at end of file +``` + +## Group Notes / Comments + +Retrieve all notes: + +(EXAMPLE CODE IS MISSING) + +Create new note: + +(EXAMPLE CODE IS MISSING) + +Update note: + +(EXAMPLE CODE IS MISSING) + +Delete note: + +(EXAMPLE CODE IS MISSING) \ No newline at end of file diff --git a/docs/out/SongAPI.md b/docs/out/SongAPI.md index 572f324d..2425f63f 100644 --- a/docs/out/SongAPI.md +++ b/docs/out/SongAPI.md @@ -201,64 +201,9 @@ ``` -## Retrieve, create and delete comments: - -**Retrieve comments:** - -```php - use CTApi\Models\Events\Song\SongCommentRequest; - - $comments = SongCommentRequest::getForSongArrangement(2); - $comment = $comments[0]; - - var_dump( $comment->getId()); - // Output: 2 - - var_dump( $comment->getDomainId()); - // Output: 3 - - var_dump( $comment->getDomainType()); - // Output: "arrangement" - - var_dump( $comment->getText()); - // Output: "Ich finde den Song super!" - - var_dump( $comment->getMeta()?->getModifiedDate()); - // Output: "2023-12-11 13:06:35" - - var_dump( $comment->getMeta()?->getModifiedPerson()?->getId()); - // Output: 12 - - - $person = $comment->getMeta()?->requestModifiedPerson(); - - var_dump( $person->getFirstName()); - // Output: "David" - - -``` - -**Create comment:** - -```php - use CTApi\Models\Events\Song\SongCommentRequest; - - SongCommentRequest::create(2, "Die Tonart ist super für Sopran."); - -``` - -**Delete comments:** - -```php - use CTApi\Models\Events\Song\SongCommentRequest; - - $comments = SongCommentRequest::getForSongArrangement(2); - $comment = $comments[0]; - - SongCommentRequest::delete($comment->getIdAsInteger()); - -``` +## Create Song-Arrangement Notes +(EXAMPLE CODE IS MISSING) ## Retrieve Data from CCLI diff --git a/docs/src/ressources/GroupAPI.md b/docs/src/ressources/GroupAPI.md index 5b77bd06..ac7019cd 100644 --- a/docs/src/ressources/GroupAPI.md +++ b/docs/src/ressources/GroupAPI.md @@ -26,4 +26,22 @@ ## Group Roles -{{ \CTApi\Test\Unit\Docs\GroupTypeRoleRequestTest.testGetGroupTypeRoleRequest }} \ No newline at end of file +{{ \CTApi\Test\Unit\Docs\GroupTypeRoleRequestTest.testGetGroupTypeRoleRequest }} + +## Group Notes / Comments + +Retrieve all notes: + +{{ \CTApi\Test\Unit\Docs\NoteRequest.testRequestNotes }} + +Create new note: + +{{ \CTApi\Test\Unit\Docs\NoteRequest.testCreateNote }} + +Update note: + +{{ \CTApi\Test\Unit\Docs\NoteRequest.testUpdateNote }} + +Delete note: + +{{ \CTApi\Test\Unit\Docs\NoteRequest.testDeleteNote }} \ No newline at end of file diff --git a/docs/src/ressources/SongAPI.md b/docs/src/ressources/SongAPI.md index b1042cde..b3f7b42f 100644 --- a/docs/src/ressources/SongAPI.md +++ b/docs/src/ressources/SongAPI.md @@ -16,20 +16,9 @@ {{ \CTApi\Test\Unit\Docs\SongRequestTest.testUpdateArrangement }} -## Retrieve, create and delete comments: - -**Retrieve comments:** - -{{ \CTApi\Test\Unit\Docs\SongCommentRequestTest.testGetAllComments }} - -**Create comment:** - -{{ \CTApi\Test\Unit\Docs\SongCommentRequestTest.testCreateComments }} - -**Delete comments:** - -{{ \CTApi\Test\Unit\Docs\SongCommentRequestTest.testDeleteComments }} +## Create Song-Arrangement Notes +{{ \CTApi\Test\Unit\Docs\NoteRequest.testUpdateSongArrangementNotes }} ## Retrieve Data from CCLI diff --git a/src/CTClient.php b/src/CTClient.php index fcbfb7a4..2142d84a 100644 --- a/src/CTClient.php +++ b/src/CTClient.php @@ -5,6 +5,7 @@ use CTApi\Exceptions\CTConnectException; use CTApi\Exceptions\CTPermissionException; use CTApi\Exceptions\CTRequestException; +use CTApi\Utils\CTResponseUtil; use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; @@ -88,6 +89,7 @@ private function handleResponse(ResponseInterface $response): ResponseInterface return $response; } + print_r(CTResponseUtil::jsonToArray($response)); throw CTRequestException::ofErrorResponse($response); } diff --git a/src/Models/Common/Note/Note.php b/src/Models/Common/Note/Note.php index 73b1e6a8..bc15fe67 100644 --- a/src/Models/Common/Note/Note.php +++ b/src/Models/Common/Note/Note.php @@ -63,4 +63,4 @@ public function setText(?string $text): Note $this->text = $text; return $this; } -} \ No newline at end of file +} diff --git a/src/Models/Common/Note/NoteRequest.php b/src/Models/Common/Note/NoteRequest.php index 0709dd95..a833e596 100644 --- a/src/Models/Common/Note/NoteRequest.php +++ b/src/Models/Common/Note/NoteRequest.php @@ -4,59 +4,13 @@ class NoteRequest { - public static function forAvatar(int $avatarId): NoteRequestBuilder - { - return new NoteRequestBuilder("avatar", $avatarId); - } - public static function forGroup(int $groupId): NoteRequestBuilder { return new NoteRequestBuilder("group", $groupId); } - public static function forLogo(int $logoId): NoteRequestBuilder - { - return new NoteRequestBuilder("logo", $logoId); - } - - public static function forAttachments(int $attachmentId): NoteRequestBuilder - { - return new NoteRequestBuilder("attachments", $attachmentId); - } - - public static function forBulkletterTemplate(int $bulkletterTemplateId): NoteRequestBuilder - { - return new NoteRequestBuilder("bulkletter_template", $bulkletterTemplateId); - } - - public static function forService(int $serviceId): NoteRequestBuilder - { - return new NoteRequestBuilder("service", $serviceId); - } - public static function forSongArrangement(int $songArrangementId): NoteRequestBuilder { return new NoteRequestBuilder("song_arrangement", $songArrangementId); } - - public static function forImportTable(int $importTableId): NoteRequestBuilder - { - return new NoteRequestBuilder("importtable", $importTableId); - } - - public static function forPerson(int $personId): NoteRequestBuilder - { - return new NoteRequestBuilder("person", $personId); - } - - public static function forFamilyAvatar(int $familyAvatarId): NoteRequestBuilder - { - return new NoteRequestBuilder("familyavatar", $familyAvatarId); - } - - public static function forWiki(int $wikiId): NoteRequestBuilder - { - // TODO: Muss unbedingt testen. Hier kann es glaub zu unterschiedlichen Implementierung führen: wiki_?? - return new NoteRequestBuilder("wiki", $wikiId); - } -} \ No newline at end of file +} diff --git a/src/Models/Common/Note/NoteRequestBuilder.php b/src/Models/Common/Note/NoteRequestBuilder.php index 3e722a4c..74661b33 100644 --- a/src/Models/Common/Note/NoteRequestBuilder.php +++ b/src/Models/Common/Note/NoteRequestBuilder.php @@ -7,7 +7,6 @@ class NoteRequestBuilder { - public function __construct(protected string $domainType, protected int $domainIdentifier) { } @@ -43,10 +42,12 @@ public function create(string $text, ?int $securityLevelId = null): ?Note { $ctClient = CTClient::getClient(); $response = $ctClient->post($this->getApiEndpoint(), [ - "domainId" => "" . $this->domainIdentifier, - "domainType" => $this->domainType, - "securityLevelId" => $securityLevelId, - "text" => $text, + "json" => [ + "domainId" => "" . $this->domainIdentifier, + "domainType" => $this->domainType, + "securityLevelId" => $securityLevelId, + "text" => $text, + ] ]); $data = CTResponseUtil::dataAsArray($response); @@ -61,8 +62,10 @@ public function update(int $noteId, string $text, ?int $securityLevelId = null): { $ctClient = CTClient::getClient(); $response = $ctClient->put($this->getApiEndpoint() . '/' . $noteId, [ - "text" => $text, - "securityLevelId" => $securityLevelId, + "json" => [ + "text" => $text, + "securityLevelId" => $securityLevelId, + ] ]); $data = CTResponseUtil::dataAsArray($response); @@ -72,4 +75,4 @@ public function update(int $noteId, string $text, ?int $securityLevelId = null): return Note::createModelFromData($data); } } -} \ No newline at end of file +} diff --git a/src/Models/Events/Song/SongCommentRequestBuilder.php b/src/Models/Events/Song/SongCommentRequestBuilder.php index c404a60a..08081585 100644 --- a/src/Models/Events/Song/SongCommentRequestBuilder.php +++ b/src/Models/Events/Song/SongCommentRequestBuilder.php @@ -6,6 +6,7 @@ use CTApi\Models\Common\Note\NoteRequest; use CTApi\Traits\Request\AjaxApi; use CTApi\Utils\CTResponseUtil; + /** * @deprecated Use NoteRequest::forSongArrangement() instead. This class will be removed in the next major-release v3. */ @@ -21,7 +22,7 @@ public function __construct( public function getComments() { $ctClient = CTClient::getClient(); - $response = $ctClient->get( "/api/notes/song_arrangement/" . $this->arrangementId ); + $response = $ctClient->get("/api/notes/song_arrangement/" . $this->arrangementId); $data = CTResponseUtil::dataAsArray($response); if (empty($data)) { return []; diff --git a/tests/Integration/Requests/NoteRequestTest.php b/tests/Integration/Requests/NoteRequestTest.php index b125dc93..ef5b1d44 100644 --- a/tests/Integration/Requests/NoteRequestTest.php +++ b/tests/Integration/Requests/NoteRequestTest.php @@ -2,70 +2,65 @@ namespace CTApi\Test\Integration\Requests; -use CTApi\CTConfig; -use CTApi\Models\Common\Auth\CSRFTokenRequest; +use CTApi\CTLog; use CTApi\Models\Common\Note\NoteRequest; +use CTApi\Test\Integration\IntegrationTestData; use CTApi\Test\Integration\TestCaseAuthenticated; class NoteRequestTest extends TestCaseAuthenticated { - - public function testNoteForGroup() + public function testNotForGroup() { - $data = NoteRequest::forGroup(17)->get(); - - CTConfig::enableDebugging(); + CTLog::enableHttpLog(); + // Remove all notes from group + $groupId = IntegrationTestData::getFilterAsInt("group_note", "group_id"); - foreach($data as $note) - { - echo "=> " . $note->getText() . "\n"; - NoteRequest::forGroup(17)->delete($note->getIdAsInteger()); + $notes = NoteRequest::forGroup($groupId)->get(); + foreach($notes as $note) { + NoteRequest::forGroup($groupId)->delete($note->getIdAsInteger()); } - } - public function testCreateNoteOnGroup() - { - CTConfig::enableDebugging(); + $notes = NoteRequest::forGroup($groupId)->get(); + $this->assertEmpty($notes); + + // Add one note + $note = NoteRequest::forGroup($groupId)->create("Hello new comment!"); + $this->assertEquals("Hello new comment!", $note->getText()); - $data = NoteRequest::forGroup(17)->create("Test String", 1); - print_r($data); + $noteUpdate = NoteRequest::forGroup($groupId)->update($note->getIdAsInteger(), "Hello comment!"); + $this->assertEquals("Hello comment!", $noteUpdate->getText()); + // Check if note is present + $notes = NoteRequest::forGroup($groupId)->get(); + $this->assertEquals(1, sizeof($notes)); + $firstNote = end($notes); + + $this->assertEquals("Hello comment!", $firstNote->getText()); } - public function testCreateNotOnGroup_DirectWithCURL() + + public function testForSongArrangement() { - $csrfToken = CSRFTokenRequest::getOrFail(); - - $ch = curl_init(); - - $options = [ - CURLOPT_URL => CTConfig::getApiUrl() . '/api/notes/group/17', - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => [ - "domainId" => "" . 17, - "domainType" => "group", - "securityLevelId" => 1, - "text" => "AawdionAWd", - ], - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER=>array('Content-Type:application/json', - "csrf-token:" . $csrfToken - ) - ]; - - curl_setopt_array($ch, $options); - - $cookie = CTConfig::getSessionCookie(); - print_r([$cookie["Name"], $cookie["Value"]]); - if ($cookie != null) { - curl_setopt($ch, CURLOPT_COOKIE, $cookie["Name"] . '=' . $cookie["Value"]); + // Remove all notes from group + $songArrangementId = IntegrationTestData::getFilterAsInt("create_and_delete_song_comments", "song_arrangement_id"); + + $notes = NoteRequest::forSongArrangement($songArrangementId)->get(); + foreach($notes as $note) { + NoteRequest::forSongArrangement($songArrangementId)->delete($note->getIdAsInteger()); } - $resp = curl_exec($ch); + $notes = NoteRequest::forSongArrangement($songArrangementId)->get(); + $this->assertEmpty($notes); + + // Add one note + $note = NoteRequest::forSongArrangement($songArrangementId)->create("Hello new comment!"); + $this->assertEquals("Hello new comment!", $note->getText()); - $curlInfo = curl_getinfo($ch); - var_dump($curlInfo); + // Check if note is present + $notes = NoteRequest::forSongArrangement($songArrangementId)->get(); + $this->assertEquals(1, sizeof($notes)); + $firstNote = end($notes); - var_dump($resp); + $this->assertEquals("Hello new comment!", $firstNote->getText()); } -} \ No newline at end of file +} diff --git a/tests/Integration/Requests/SongCommentRequestTest.php b/tests/Integration/Requests/SongCommentRequestTest.php index d0ab6fd2..a6dfde41 100644 --- a/tests/Integration/Requests/SongCommentRequestTest.php +++ b/tests/Integration/Requests/SongCommentRequestTest.php @@ -2,7 +2,6 @@ namespace CTApi\Test\Integration\Requests; -use CTApi\Models\Events\Song\SongArrangementRequest; use CTApi\Models\Events\Song\SongCommentRequest; use CTApi\Test\Integration\IntegrationTestData; use CTApi\Test\Integration\TestCaseAuthenticated; diff --git a/tests/Integration/integration-test-data.json b/tests/Integration/integration-test-data.json index 89688cea..9923a323 100644 --- a/tests/Integration/integration-test-data.json +++ b/tests/Integration/integration-test-data.json @@ -202,6 +202,12 @@ } } }, + "group_note": { + "description": "Add and remove note from group. All notes from group are removed.", + "filter": { + "group_id": 17 + } + }, "load_public_group": { "description": "PublicGroup to register on homepage", "filter": { diff --git a/tests/Unit/Docs/NoteRequestTest.php b/tests/Unit/Docs/NoteRequestTest.php new file mode 100644 index 00000000..28e59bf1 --- /dev/null +++ b/tests/Unit/Docs/NoteRequestTest.php @@ -0,0 +1,54 @@ +get(); + $this->assertEquals("Hello new comment!", $notes[0]->getText()); + $this->assertEquals("17", $notes[0]->getDomainId()); + $this->assertEquals("group", $notes[0]->getDomainType()); + $this->assertEquals("212", $notes[0]->getId()); + } + + public function testCreateNote() + { + $note = NoteRequest::forGroup(52)->create("Add new comment."); + $this->assertEquals("Add new comment.", $note->getText()); + } + + public function testUpdateNote() + { + $note = NoteRequest::forGroup(52)->update(25, "Updated comment."); + $this->assertEquals("Updated comment.", $note->getText()); + } + + /** + * @doesNotPerformAssertions + */ + public function testDeleteNote() + { + NoteRequest::forGroup(52)->delete(25); + } + + public function testUpdateSongArrangementNotes() + { + $notes = NoteRequest::forSongArrangement(21)->get(); + + $this->assertEquals("Hello new comment!", $notes[0]->getText()); + $this->assertEquals("17", $notes[0]->getDomainId()); + $this->assertEquals("group", $notes[0]->getDomainType()); + $this->assertEquals("212", $notes[0]->getId()); + + $securityLevelId = 2; + $note = NoteRequest::forSongArrangement(21)->create("New comment", $securityLevelId); + $note = NoteRequest::forSongArrangement(21)->update(2, "New comment"); + + NoteRequest::forSongArrangement(21)->delete(2); + } +} diff --git a/tests/Unit/Docs/SongCommentRequestTest.php b/tests/Unit/Docs/SongCommentRequestTest.php deleted file mode 100644 index cb3a4c78..00000000 --- a/tests/Unit/Docs/SongCommentRequestTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertEquals(2, $comment->getId()); - $this->assertEquals(3, $comment->getDomainId()); - $this->assertEquals("song_arrangement", $comment->getDomainType()); - $this->assertEquals("Ich finde den Song super!", $comment->getText()); - $this->assertEquals("2023-12-11 13:06:35", $comment->getMeta()?->getModifiedDate()); - $this->assertEquals(12, $comment->getMeta()?->getModifiedPerson()?->getId()); - - $person = $comment->getMeta()?->requestModifiedPerson(); - - $this->assertEquals("David", $person->getFirstName()); - } - - /** - * @return void - * @doesNotPerformAssertions - */ - public function testCreateComments() - { - SongCommentRequest::create(2, "Die Tonart ist super für Sopran."); - } - - /** - * @return void - * @doesNotPerformAssertions - */ - public function testDeleteComments() - { - $comments = SongCommentRequest::getForSongArrangement(2); - $comment = $comments[0]; - - SongCommentRequest::delete($comment->getIdAsInteger()); - } - -} diff --git a/tests/Unit/HttpMock/data/POST_api_notes_group_52.json b/tests/Unit/HttpMock/data/POST_api_notes_group_52.json new file mode 100644 index 00000000..223f9e09 --- /dev/null +++ b/tests/Unit/HttpMock/data/POST_api_notes_group_52.json @@ -0,0 +1,24 @@ +{ + "data": + { + "id": 212, + "domainType": "group", + "domainId": 17, + "securityLevelId": null, + "text": "Add new comment.", + "meta": { + "createdDate": "2024-07-31T13:44:52Z", + "createdPerson": { + "id": 12 + }, + "modifiedDate": "2024-07-31T13:44:52Z", + "modifiedPerson": { + "id": 12 + } + } + } + , + "meta": { + "count": 1 + } +} \ No newline at end of file diff --git a/tests/Unit/HttpMock/data/PUT_api_notes_group_52_25.json b/tests/Unit/HttpMock/data/PUT_api_notes_group_52_25.json new file mode 100644 index 00000000..35965e0e --- /dev/null +++ b/tests/Unit/HttpMock/data/PUT_api_notes_group_52_25.json @@ -0,0 +1,24 @@ +{ + "data": + { + "id": 212, + "domainType": "group", + "domainId": 17, + "securityLevelId": null, + "text": "Updated comment.", + "meta": { + "createdDate": "2024-07-31T13:44:52Z", + "createdPerson": { + "id": 12 + }, + "modifiedDate": "2024-07-31T13:44:52Z", + "modifiedPerson": { + "id": 12 + } + } + } + , + "meta": { + "count": 1 + } +} \ No newline at end of file diff --git a/tests/Unit/HttpMock/data/api_notes_group_212.json b/tests/Unit/HttpMock/data/api_notes_group_212.json new file mode 100644 index 00000000..63ff1129 --- /dev/null +++ b/tests/Unit/HttpMock/data/api_notes_group_212.json @@ -0,0 +1,24 @@ +{ + "data": [ + { + "id": 212, + "domainType": "group", + "domainId": 17, + "securityLevelId": null, + "text": "Hello new comment!", + "meta": { + "createdDate": "2024-07-31T13:44:52Z", + "createdPerson": { + "id": 12 + }, + "modifiedDate": "2024-07-31T13:44:52Z", + "modifiedPerson": { + "id": 12 + } + } + } + ], + "meta": { + "count": 1 + } +} \ No newline at end of file diff --git a/tests/Unit/HttpMock/data/api_notes_song_arrangement_21.json b/tests/Unit/HttpMock/data/api_notes_song_arrangement_21.json new file mode 100644 index 00000000..63ff1129 --- /dev/null +++ b/tests/Unit/HttpMock/data/api_notes_song_arrangement_21.json @@ -0,0 +1,24 @@ +{ + "data": [ + { + "id": 212, + "domainType": "group", + "domainId": 17, + "securityLevelId": null, + "text": "Hello new comment!", + "meta": { + "createdDate": "2024-07-31T13:44:52Z", + "createdPerson": { + "id": 12 + }, + "modifiedDate": "2024-07-31T13:44:52Z", + "modifiedPerson": { + "id": 12 + } + } + } + ], + "meta": { + "count": 1 + } +} \ No newline at end of file