Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(note): add note request and replace song-comment #215 #216

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 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))
- Added new property 'postsEnabled' to the group type model ([PR204](https://github.com/5pm-HDH/churchtools-api/pull/204))
- Add Note for Group and SongArrangement ([PR216](https://github.com/5pm-HDH/churchtools-api/pull/216))
- Login with Session Cookie ([PR207](https://github.com/5pm-HDH/churchtools-api/pull/207))

### Changed
Expand Down
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
66 changes: 66 additions & 0 deletions src/Models/Common/Note/Note.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace CTApi\Models\Common\Note;

use CTApi\Models\AbstractModel;
use CTApi\Models\Common\Domain\Meta;
use CTApi\Traits\Model\FillWithData;
use CTApi\Traits\Model\MetaAttribute;

class Note extends AbstractModel
{
use FillWithData;
use MetaAttribute;

protected ?string $domainId = null;
protected ?string $domainType = null;
protected ?string $text = null;

protected function fillArrayType(string $key, array $data): void
{
switch ($key) {
case "meta":
$this->setMeta(Meta::createModelFromData($data));
break;
}
}

public function setId(?string $id): Note
{
$this->id = $id;
return $this;
}

public function getDomainId(): ?string
{
return $this->domainId;
}

public function setDomainId(?string $domainId): Note
{
$this->domainId = $domainId;
return $this;
}

public function getDomainType(): ?string
{
return $this->domainType;
}

public function setDomainType(?string $domainType): Note
{
$this->domainType = $domainType;
return $this;
}

public function getText(): ?string
{
return $this->text;
}

public function setText(?string $text): Note
{
$this->text = $text;
return $this;
}
}
16 changes: 16 additions & 0 deletions src/Models/Common/Note/NoteRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace CTApi\Models\Common\Note;

class NoteRequest
{
public static function forGroup(int $groupId): NoteRequestBuilder
{
return new NoteRequestBuilder("group", $groupId);
}

public static function forSongArrangement(int $songArrangementId): NoteRequestBuilder
{
return new NoteRequestBuilder("song_arrangement", $songArrangementId);
}
}
78 changes: 78 additions & 0 deletions src/Models/Common/Note/NoteRequestBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace CTApi\Models\Common\Note;

use CTApi\CTClient;
use CTApi\Utils\CTResponseUtil;

class NoteRequestBuilder
{
public function __construct(protected string $domainType, protected int $domainIdentifier)
{
}

protected function getApiEndpoint(): string
{
return "/api/notes/" . $this->domainType . "/" . $this->domainIdentifier;
}


/**
* @return Note[]
*/
public function get(): array
{
$ctClient = CTClient::getClient();
$response = $ctClient->get($this->getApiEndpoint());
$data = CTResponseUtil::dataAsArray($response);
if (empty($data)) {
return [];
} else {
return Note::createModelsFromArray($data);
}
}

public function delete(int $noteId): void
{
$ctClient = CTClient::getClient();
$ctClient->delete($this->getApiEndpoint() . "/" . $noteId);
}

public function create(string $text, ?int $securityLevelId = null): ?Note
{
$ctClient = CTClient::getClient();
$response = $ctClient->post($this->getApiEndpoint(), [
"json" => [
"domainId" => "" . $this->domainIdentifier,
"domainType" => $this->domainType,
"securityLevelId" => $securityLevelId,
"text" => $text,
]
]);

$data = CTResponseUtil::dataAsArray($response);
if (empty($data)) {
return null;
} else {
return Note::createModelFromData($data);
}
}

public function update(int $noteId, string $text, ?int $securityLevelId = null): ?Note
{
$ctClient = CTClient::getClient();
$response = $ctClient->put($this->getApiEndpoint() . '/' . $noteId, [
"json" => [
"text" => $text,
"securityLevelId" => $securityLevelId,
]
]);

$data = CTResponseUtil::dataAsArray($response);
if (empty($data)) {
return null;
} else {
return Note::createModelFromData($data);
}
}
}
17 changes: 16 additions & 1 deletion src/Models/Events/Song/SongComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
use CTApi\Models\Common\Domain\Meta;
use CTApi\Models\Groups\Person\Person;
use CTApi\Traits\Model\FillWithData;
use CTApi\Traits\Model\MetaAttribute;

/**
* @deprecated Use Note instead. This class will be removed in the next major-release v3.
*/
class SongComment extends AbstractModel
{
use FillWithData;
use MetaAttribute;

private ?string $domainId = null;
private ?string $domainType = null;
private ?string $text = null;
private ?Meta $meta = null;

protected function fillNonArrayType(string $key, $value): void
{
Expand Down Expand Up @@ -42,6 +46,17 @@ protected function fillNonArrayType(string $key, $value): void
}
}

protected function fillArrayType(string $key, array $data): void
{
switch ($key) {
case "meta":
$this->meta = Meta::createModelFromData($data);
break;
default:
$this->fillDefault($key, $data);
}
}

public function getDomainId(): ?string
{
return $this->domainId;
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Events/Song/SongCommentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace CTApi\Models\Events\Song;

/**
* @deprecated Use NoteRequest::forSongArrangement() instead. This class will be removed in the next major-release v3.
*/
class SongCommentRequest
{
public static function getForSongArrangement(int $arrangementId): array
Expand Down
Loading
Loading