|
@@ -3,10 +3,14 @@
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Http\Controllers\Api\BaseApiController;
|
|
use App\Http\Controllers\Api\BaseApiController;
|
|
-use App\Like;
|
|
|
|
|
|
+use App\{
|
|
|
|
+ Like,
|
|
|
|
+ Profile
|
|
|
|
+};
|
|
use Auth;
|
|
use Auth;
|
|
use Cache;
|
|
use Cache;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
|
+use App\Services\SuggestionService;
|
|
|
|
|
|
class ApiController extends BaseApiController
|
|
class ApiController extends BaseApiController
|
|
{
|
|
{
|
|
@@ -47,4 +51,43 @@ class ApiController extends BaseApiController
|
|
return response()->json($res);
|
|
return response()->json($res);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function userRecommendations(Request $request)
|
|
|
|
+ {
|
|
|
|
+ abort_if(!Auth::check(), 403);
|
|
|
|
+ abort_if(!config('exp.rec'), 400);
|
|
|
|
+
|
|
|
|
+ $id = Auth::user()->profile->id;
|
|
|
|
+
|
|
|
|
+ $following = Cache::get('profile:following:'.$id, []);
|
|
|
|
+ $ids = SuggestionService::get();
|
|
|
|
+
|
|
|
|
+ $res = Cache::remember('api:local:exp:rec:'.$id, now()->addMinutes(5), function() use($id, $following, $ids) {
|
|
|
|
+
|
|
|
|
+ array_push($following, $id);
|
|
|
|
+
|
|
|
|
+ return Profile::select(
|
|
|
|
+ 'id',
|
|
|
|
+ 'username'
|
|
|
|
+ )
|
|
|
|
+ ->whereNotIn('id', $following)
|
|
|
|
+ ->whereIn('id', $ids)
|
|
|
|
+ ->whereIsPrivate(0)
|
|
|
|
+ ->whereNull('status')
|
|
|
|
+ ->whereNull('domain')
|
|
|
|
+ ->inRandomOrder()
|
|
|
|
+ ->take(4)
|
|
|
|
+ ->get()
|
|
|
|
+ ->map(function($item, $key) {
|
|
|
|
+ return [
|
|
|
|
+ 'id' => $item->id,
|
|
|
|
+ 'avatar' => $item->avatarUrl(),
|
|
|
|
+ 'username' => $item->username,
|
|
|
|
+ 'message' => 'Recommended for You'
|
|
|
|
+ ];
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return response()->json($res->all());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|