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

View file

@ -13,11 +13,13 @@ use App\{
Bookmark, Bookmark,
Follower, Follower,
FollowRequest, FollowRequest,
Hashtag,
Like, Like,
Media, Media,
Notification, Notification,
Profile, Profile,
Status, Status,
StatusHashtag,
User, User,
UserFilter, UserFilter,
}; };
@ -1988,9 +1990,46 @@ class ApiV1Controller extends Controller
{ {
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
// todo $this->validate($request,[
$res = []; 'page' => 'nullable|integer|max:40',
return response()->json($res); '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);
} }
/** /**