Skip to content

Commit

Permalink
feat(note): add note request and add docs #215
Browse files Browse the repository at this point in the history
  • Loading branch information
DumbergerL committed Jul 31, 2024
1 parent 6cf0194 commit b528265
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 226 deletions.
20 changes: 19 additions & 1 deletion docs/out/GroupAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,22 @@
// Output: 0


```
```

## 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)
59 changes: 2 additions & 57 deletions docs/out/SongAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 19 additions & 1 deletion docs/src/ressources/GroupAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,22 @@

## Group Roles

{{ \CTApi\Test\Unit\Docs\GroupTypeRoleRequestTest.testGetGroupTypeRoleRequest }}
{{ \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 }}
15 changes: 2 additions & 13 deletions docs/src/ressources/SongAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/CTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +89,7 @@ private function handleResponse(ResponseInterface $response): ResponseInterface
return $response;
}

print_r(CTResponseUtil::jsonToArray($response));
throw CTRequestException::ofErrorResponse($response);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Common/Note/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ public function setText(?string $text): Note
$this->text = $text;
return $this;
}
}
}
48 changes: 1 addition & 47 deletions src/Models/Common/Note/NoteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
19 changes: 11 additions & 8 deletions src/Models/Common/Note/NoteRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class NoteRequestBuilder
{

public function __construct(protected string $domainType, protected int $domainIdentifier)
{
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -72,4 +75,4 @@ public function update(int $noteId, string $text, ?int $securityLevelId = null):
return Note::createModelFromData($data);
}
}
}
}
3 changes: 2 additions & 1 deletion src/Models/Events/Song/SongCommentRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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 [];
Expand Down
Loading

0 comments on commit b528265

Please sign in to comment.