-
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.
feat(note): add note request and replace song-comment #215
- Loading branch information
1 parent
9a8088f
commit 6cf0194
Showing
11 changed files
with
313 additions
and
22 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
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,62 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Common\Note; | ||
|
||
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); | ||
} | ||
} |
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,75 @@ | ||
<?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(), [ | ||
"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, [ | ||
"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
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,71 @@ | ||
<?php | ||
|
||
namespace CTApi\Test\Integration\Requests; | ||
|
||
use CTApi\CTConfig; | ||
use CTApi\Models\Common\Auth\CSRFTokenRequest; | ||
use CTApi\Models\Common\Note\NoteRequest; | ||
use CTApi\Test\Integration\TestCaseAuthenticated; | ||
|
||
class NoteRequestTest extends TestCaseAuthenticated | ||
{ | ||
|
||
public function testNoteForGroup() | ||
{ | ||
$data = NoteRequest::forGroup(17)->get(); | ||
|
||
CTConfig::enableDebugging(); | ||
|
||
foreach($data as $note) | ||
{ | ||
echo "=> " . $note->getText() . "\n"; | ||
NoteRequest::forGroup(17)->delete($note->getIdAsInteger()); | ||
} | ||
} | ||
|
||
public function testCreateNoteOnGroup() | ||
{ | ||
CTConfig::enableDebugging(); | ||
|
||
$data = NoteRequest::forGroup(17)->create("Test String", 1); | ||
print_r($data); | ||
|
||
} | ||
public function testCreateNotOnGroup_DirectWithCURL() | ||
{ | ||
$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"]); | ||
} | ||
|
||
$resp = curl_exec($ch); | ||
|
||
$curlInfo = curl_getinfo($ch); | ||
var_dump($curlInfo); | ||
|
||
var_dump($resp); | ||
} | ||
|
||
} |
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.