diff options
author | Paul Tirk <paultirk@paultirk.com> | 2021-01-09 19:05:40 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-08 10:23:11 +0200 |
commit | 0d7d3cdfb4af9e5f369e229a0eb05d506f801da2 (patch) | |
tree | eddb5f6e2c73598d64701aafab85b75edf54a857 /lib/Controller/ApiPayloadTrait.php | |
parent | dff855fba5ce7e43d0ae4b68fd53eeab43dc7b5e (diff) |
move v2 api responses into existing php traits
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
Diffstat (limited to 'lib/Controller/ApiPayloadTrait.php')
-rw-r--r-- | lib/Controller/ApiPayloadTrait.php | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/Controller/ApiPayloadTrait.php b/lib/Controller/ApiPayloadTrait.php index 2bb31784e..c40ec9c25 100644 --- a/lib/Controller/ApiPayloadTrait.php +++ b/lib/Controller/ApiPayloadTrait.php @@ -1,8 +1,10 @@ <?php - namespace OCA\News\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; + use OCA\News\Db\IAPI; trait ApiPayloadTrait @@ -33,4 +35,37 @@ trait ApiPayloadTrait } return $return; } + + /** + * Serialize an entity + * + * @param IAPI $data + * + * @return array + */ + public function serializeEntityV2($data, bool $reduced = false): array + { + return $data->toAPI2($reduced); + } + + /** + * Serialize array of entities + * + * @param array $data + * + * @return array + */ + public function serializeEntitiesV2($data, bool $reduced = false): array + { + $return = []; + foreach ($data as $entity) { + $return[] = $entity->toAPI2($reduced); + } + return $return; + } + + public function responseV2($data, $code = Http::STATUS_OK) + { + return new JSONResponse($data, $code); + } } |