summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorPaul Tirk <paultirk@paultirk.com>2021-01-09 18:34:02 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 10:23:11 +0200
commit323f215e3a09799685fdcbbe6502d45bab2d43f2 (patch)
tree94a3904cd3b1c5bc701c26387641246f67798e80 /lib/Controller
parentf22eddb91d374b26f378067e0bd33154d0dab2c0 (diff)
separate serialization functions
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/ApiV2ResponseTrait.php29
-rw-r--r--lib/Controller/FolderApiV2Controller.php4
2 files changed, 17 insertions, 16 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([