Add hashtag timeline to v1 api

This commit is contained in:
Daniel Supernault 2021-05-18 19:46:26 -06:00
parent dac326e949
commit 241ae0368f
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 42 additions and 3 deletions

View File

@ -13,11 +13,13 @@ use App\{
Bookmark,
Follower,
FollowRequest,
Hashtag,
Like,
Media,
Notification,
Profile,
Status,
StatusHashtag,
User,
UserFilter,
};
@ -1988,9 +1990,46 @@ class ApiV1Controller extends Controller
{
abort_if(!$request->user(), 403);
// todo
$res = [];
return response()->json($res);
$this->validate($request,[
'page' => 'nullable|integer|max:40',
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|max:40'
]);
$tag = Hashtag::whereName($hashtag)
->orWhere('slug', $hashtag)
->first();
if(!$tag) {
return response()->json([]);
}
$min = $request->input('min_id');
$max = $request->input('max_id');
$limit = $request->input('limit', 20);
if(!$min && !$max) {
$id = 1;
$dir = '>';
} else {
$dir = $min ? '>' : '<';
$id = $min ?? $max;
}
$res = StatusHashtag::whereHashtagId($tag->id)
->whereStatusVisibility('public')
->whereHas('media')
->where('status_id', $dir, $id)
->latest()
->limit($limit)
->pluck('status_id')
->map(function ($i) {
return StatusService::get($i);
})
->all();
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
}
/**