-
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 #216 from 5pm-HDH/fix-song-comments-#215
feat(note): add note request and replace song-comment #215
- Loading branch information
Showing
20 changed files
with
462 additions
and
140 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
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,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; | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.