-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from 5pm-HDH/feat/182/comment-for-song-arrang…
…ement feat(song-arrangement-comment): retrieve, update and delete song-arrangement comments #182
- Loading branch information
Showing
11 changed files
with
388 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Events\Song; | ||
|
||
use CTApi\Models\AbstractModel; | ||
use CTApi\Models\Common\Domain\Meta; | ||
use CTApi\Models\Groups\Person\Person; | ||
use CTApi\Traits\Model\FillWithData; | ||
|
||
class SongComment extends AbstractModel | ||
{ | ||
use FillWithData; | ||
|
||
private ?string $domainId = null; | ||
private ?string $domainType = null; | ||
private ?string $text = null; | ||
private ?Meta $meta = null; | ||
|
||
protected function fillNonArrayType(string $key, $value): void | ||
{ | ||
switch ($key) { | ||
case "domain_type": | ||
$this->domainType = $value; | ||
break; | ||
case "domain_id": | ||
$this->domainId = $value; | ||
break; | ||
case "modified_date": | ||
if ($this->meta === null) { | ||
$this->meta = new Meta(); | ||
} | ||
$this->meta->setModifiedDate($value); | ||
break; | ||
case "modified_pid": | ||
if ($this->meta === null) { | ||
$this->meta = new Meta(); | ||
} | ||
$this->meta->setModifiedPerson(Person::createModelFromData(["id" => $value])); | ||
break; | ||
default: | ||
$this->fillDefault($key, $value); | ||
} | ||
} | ||
|
||
public function getDomainId(): ?string | ||
{ | ||
return $this->domainId; | ||
} | ||
|
||
public function setDomainId(?string $domainId): SongComment | ||
{ | ||
$this->domainId = $domainId; | ||
return $this; | ||
} | ||
|
||
public function getDomainType(): ?string | ||
{ | ||
return $this->domainType; | ||
} | ||
|
||
public function setDomainType(?string $domainType): SongComment | ||
{ | ||
$this->domainType = $domainType; | ||
return $this; | ||
} | ||
|
||
public function getText(): ?string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function setText(?string $text): SongComment | ||
{ | ||
$this->text = $text; | ||
return $this; | ||
} | ||
|
||
public function setId(?string $id) | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
public function getMeta(): ?Meta | ||
{ | ||
return $this->meta; | ||
} | ||
|
||
public function setMeta(?Meta $meta): SongComment | ||
{ | ||
$this->meta = $meta; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Events\Song; | ||
|
||
class SongCommentRequest | ||
{ | ||
|
||
public static function getForSongArrangement(int $arrangementId): array | ||
{ | ||
$builder = new SongCommentRequestBuilder($arrangementId); | ||
return $builder->getComments(); | ||
} | ||
|
||
public static function create(int $arrangementId, string $text): void | ||
{ | ||
$builder = new SongCommentRequestBuilder($arrangementId); | ||
$builder->createComment($text); | ||
} | ||
|
||
public static function delete(int $commentId): void | ||
{ | ||
$builder = new SongCommentRequestBuilder(0); | ||
$builder->deleteComment($commentId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Events\Song; | ||
|
||
use CTApi\Traits\Request\AjaxApi; | ||
use CTApi\Utils\CTResponseUtil; | ||
|
||
class SongCommentRequestBuilder | ||
{ | ||
|
||
use AjaxApi; | ||
|
||
public function __construct( | ||
private int $arrangementId | ||
) | ||
{ | ||
} | ||
|
||
public function getComments() | ||
{ | ||
$response = $this->requestAjax("churchservice/ajax", "getComments", [ | ||
"domain_type" => "arrangement", | ||
"domain_id" => $this->arrangementId | ||
]); | ||
|
||
$data = CTResponseUtil::dataAsArray($response); | ||
return SongComment::createModelsFromArray(array_values($data)); | ||
} | ||
|
||
public function createComment(string $text): void | ||
{ | ||
$this->requestAjax("churchservice/ajax", "addComment", [ | ||
"domain_type" => "arrangement", | ||
"domain_id" => $this->arrangementId, | ||
"text" => $text | ||
]); | ||
} | ||
|
||
public function deleteComment(int $commentId): void | ||
{ | ||
$this->requestAjax("churchservice/ajax", "delComment", [ | ||
"id" => $commentId, | ||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace CTApi\Test\Integration\Requests; | ||
|
||
use CTApi\Models\Events\Song\SongCommentRequest; | ||
use CTApi\Test\Integration\IntegrationTestData; | ||
use CTApi\Test\Integration\TestCaseAuthenticated; | ||
|
||
class SongCommentRequestTest extends TestCaseAuthenticated | ||
{ | ||
|
||
private int $arrangementId; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->arrangementId = IntegrationTestData::getFilterAsInt("get_song_comments", "song_arrangement_id"); | ||
} | ||
|
||
public function testGetSongArrangement() | ||
{ | ||
$comments = SongCommentRequest::getForSongArrangement($this->arrangementId); | ||
|
||
$commentId = IntegrationTestData::getResultAsInt("get_song_comments", "any_comment.id"); | ||
$foundComment = null; | ||
foreach ($comments as $comment) { | ||
if ($comment->getId() == $commentId) { | ||
$foundComment = $comment; | ||
} | ||
} | ||
$this->assertNotNull($foundComment); | ||
$this->assertEqualsTestData("get_song_comments", "any_comment.text", $foundComment->getText()); | ||
$this->assertEqualsTestData("get_song_comments", "any_comment.modified_date", $foundComment->getMeta()?->getModifiedDate()); | ||
$this->assertEqualsTestData("get_song_comments", "any_comment.modified_person_id", $foundComment->getMeta()?->getModifiedPerson()?->getIdAsInteger()); | ||
} | ||
|
||
public function testCreateAndDeleteSongArrangement() | ||
{ | ||
$arrangementId = IntegrationTestData::getFilterAsInt("create_and_delete_song_comments", "song_arrangement_id"); | ||
SongCommentRequest::create($arrangementId, "Hello world!"); | ||
|
||
$anyComment = null; | ||
$allComments = SongCommentRequest::getForSongArrangement($arrangementId); | ||
foreach ($allComments as $comment) { | ||
if ($comment->getText() === "Hello world!") { | ||
$anyComment = $comment; | ||
} | ||
} | ||
$this->assertNotNull($anyComment); | ||
|
||
// DELETE ALL COMMENTS | ||
foreach ($allComments as $comment) { | ||
SongCommentRequest::delete($comment->getIdAsInteger()); | ||
} | ||
$allComments = SongCommentRequest::getForSongArrangement($arrangementId); | ||
$this->assertEquals(0, sizeof($allComments)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.