瀏覽代碼

Add hashtag timeline to v1 api

Daniel Supernault 4 年之前
父節點
當前提交
241ae0368f
共有 1 個文件被更改,包括 42 次插入3 次删除
  1. 42 3
      app/Http/Controllers/Api/ApiV1Controller.php

+ 42 - 3
app/Http/Controllers/Api/ApiV1Controller.php

@@ -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
-        $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);
     }
     }
 
 
     /**
     /**