forked from mirror/pixelfed
Add API StoryTransformer
This commit is contained in:
parent
e764b6e8b3
commit
fcabd961ce
1 changed files with 34 additions and 0 deletions
34
app/Transformer/Api/StoryTransformer.php
Normal file
34
app/Transformer/Api/StoryTransformer.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Transformer\Api;
|
||||
|
||||
use App\Story;
|
||||
use League\Fractal;
|
||||
|
||||
class StoryTransformer extends Fractal\TransformerAbstract
|
||||
{
|
||||
protected $defaultIncludes = [
|
||||
'items',
|
||||
];
|
||||
|
||||
public function transform(Story $story)
|
||||
{
|
||||
return [
|
||||
'id' => $story->id,
|
||||
'photo' => $story->profile->avatarUrl(),
|
||||
'name' => '',
|
||||
'link' => '',
|
||||
'lastUpdated' => $story->updated_at->format('U'),
|
||||
'seen' => $story->seen(),
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function includeItems(Story $story)
|
||||
{
|
||||
$items = $story->items;
|
||||
|
||||
return $this->collection($items, new StoryItemTransformer());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue