summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Controller/ApiV2ResponseTrait.php29
-rw-r--r--lib/Controller/FolderApiV2Controller.php4
-rw-r--r--lib/Db/Folder.php2
3 files changed, 18 insertions, 17 deletions
diff --git a/lib/Controller/ApiV2ResponseTrait.php b/lib/Controller/ApiV2ResponseTrait.php
index 3538f1948..3d803b28f 100644
--- a/lib/Controller/ApiV2ResponseTrait.php
+++ b/lib/Controller/ApiV2ResponseTrait.php
@@ -20,28 +20,29 @@ use \OCA\News\Db\IAPI;
trait ApiV2ResponseTrait
{
/**
- * Serialize all data
+ * Serialize an entity
*
- * @param mixed $data IAPI or array,
- * anything else will return an empty array
+ * @param IAPI $data
*
* @return array
*/
- public function serialize($data, bool $reduced = false): array
+ public function serializeEntity($data, bool $reduced = false): array
{
- if ($data instanceof IAPI) {
- return $data->toAPI2($reduced);
- }
+ return $data->toAPI2($reduced);
+ }
+ /**
+ * Serialize array of entities
+ *
+ * @param array $data
+ *
+ * @return array
+ */
+ public function serializeEntities($data, bool $reduced = false): array
+ {
$return = [];
- if (!is_array($data)) {
- return $return;
- }
-
foreach ($data as $entity) {
- if ($entity instanceof IAPI) {
- $return[] = $entity->toAPI2($reduced);
- }
+ $return[] = $entity->toAPI2($reduced);
}
return $return;
}
diff --git a/lib/Controller/FolderApiV2Controller.php b/lib/Controller/FolderApiV2Controller.php
index ecc775d3c..049be579e 100644
--- a/lib/Controller/FolderApiV2Controller.php
+++ b/lib/Controller/FolderApiV2Controller.php
@@ -52,7 +52,7 @@ class FolderApiV2Controller extends ApiController
{
try {
$this->folderService->purgeDeleted($this->getUserId(), false);
- $responseData = $this->serialize(
+ $responseData = $this->serializeEntity(
$this->folderService->create($this->getUserId(), $name)
);
return $this->response([
@@ -103,7 +103,7 @@ class FolderApiV2Controller extends ApiController
public function deleteFolder($folderId)
{
try {
- $responseData = $this->serialize(
+ $responseData = $this->serializeEntity(
$this->folderService->delete($this->getUserId(), $folderId)
);
return $this->response([
diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php
index 4e3cdeaf1..7bd30975f 100644
--- a/lib/Db/Folder.php
+++ b/lib/Db/Folder.php
@@ -175,7 +175,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable
);
}
- public function toAPI2(): array
+ public function toAPI2(bool $reduced = false): array
{
return $this->toAPI();
}