1
0
Fork 0
forked from mirror/pixelfed

Update ApiV1Dot1Controller

This commit is contained in:
Daniel Supernault 2022-09-19 03:49:45 -06:00
parent 3218719e4c
commit 842f40a1b5
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -12,6 +12,8 @@ use App\Status;
use App\Report;
use App\Profile;
use App\Services\AccountService;
use App\Services\StatusService;
use App\Services\ProfileStatusService;
class ApiV1Dot1Controller extends Controller
{
@ -166,4 +168,40 @@ class ApiV1Dot1Controller extends Controller
return AccountService::get($user->profile_id);
}
/**
* GET /api/v1.1/accounts/{id}/posts
*
* @return \App\Transformer\Api\StatusTransformer
*/
public function accountPosts(Request $request, $id)
{
$user = $request->user();
abort_if(!$user, 403);
abort_if($user->status != null, 403);
$account = AccountService::get($id);
if(!$account || $account['username'] !== $request->input('username')) {
return $this->json([]);
}
$posts = ProfileStatusService::get($id);
if(!$posts) {
return $this->json([]);
}
$res = collect($posts)
->map(function($id) {
return StatusService::get($id);
})
->filter(function($post) {
return $post && isset($post['account']);
})
->toArray();
return $this->json($res);
}
}