Update StatusTransformers

This commit is contained in:
Daniel Supernault 2019-10-01 21:06:42 -06:00
parent 21f262315d
commit a79d23d152
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 9 additions and 5 deletions

View file

@ -267,7 +267,7 @@ class ApiV1Controller extends Controller
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, 'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|min:1|max:40' 'limit' => 'nullable|integer|min:1|max:80'
]); ]);
$profile = Profile::whereNull('status')->findOrFail($id); $profile = Profile::whereNull('status')->findOrFail($id);
@ -748,6 +748,8 @@ class ApiV1Controller extends Controller
]); ]);
if($like->wasRecentlyCreated == true) { if($like->wasRecentlyCreated == true) {
$status->likes_count = $status->likes()->count();
$status->save();
LikePipeline::dispatch($like); LikePipeline::dispatch($like);
} }
@ -777,6 +779,8 @@ class ApiV1Controller extends Controller
if($like) { if($like) {
$like->delete(); $like->delete();
$status->likes_count = $status->likes()->count();
$status->save();
} }
$resource = new Fractal\Resource\Item($status, new StatusTransformer()); $resource = new Fractal\Resource\Item($status, new StatusTransformer());

View file

@ -28,8 +28,8 @@ class StatusTransformer extends Fractal\TransformerAbstract
'created_at' => $status->created_at->toJSON(), 'created_at' => $status->created_at->toJSON(),
'emojis' => [], 'emojis' => [],
'replies_count' => 0, 'replies_count' => 0,
'reblogs_count' => $status->reblogs_count, 'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count, 'favourites_count' => $status->likes_count ?? 0,
'reblogged' => null, 'reblogged' => null,
'favourited' => null, 'favourited' => null,
'muted' => null, 'muted' => null,

View file

@ -25,8 +25,8 @@ class StatusTransformer extends Fractal\TransformerAbstract
'content' => $status->rendered ?? $status->caption, 'content' => $status->rendered ?? $status->caption,
'created_at' => $status->created_at->format('c'), 'created_at' => $status->created_at->format('c'),
'emojis' => [], 'emojis' => [],
'reblogs_count' => $status->reblogs_count, 'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count, 'favourites_count' => $status->likes_count ?? 0,
'reblogged' => $status->shared(), 'reblogged' => $status->shared(),
'favourited' => $status->liked(), 'favourited' => $status->liked(),
'muted' => null, 'muted' => null,