1
0
Fork 0

Update DiscoverController

This commit is contained in:
Daniel Supernault 2019-06-03 13:13:01 -06:00
parent 7869ee9a92
commit a39f0e9d52
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 46 additions and 1 deletions

View File

@ -13,21 +13,31 @@ use App\{
}; };
use Auth, DB, Cache; use Auth, DB, Cache;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Transformer\Api\StatusStatelessTransformer;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
class DiscoverController extends Controller class DiscoverController extends Controller
{ {
protected $fractal;
public function __construct() public function __construct()
{ {
$this->middleware('auth'); $this->fractal = new Fractal\Manager();
$this->fractal->setSerializer(new ArraySerializer());
} }
public function home(Request $request) public function home(Request $request)
{ {
abort_if(!Auth::check(), 403);
return view('discover.home'); return view('discover.home');
} }
public function showTags(Request $request, $hashtag) public function showTags(Request $request, $hashtag)
{ {
abort_if(!Auth::check(), 403);
$tag = Hashtag::whereSlug($hashtag) $tag = Hashtag::whereSlug($hashtag)
->firstOrFail(); ->firstOrFail();
@ -81,6 +91,8 @@ class DiscoverController extends Controller
public function showCategory(Request $request, $slug) public function showCategory(Request $request, $slug)
{ {
abort_if(!Auth::check(), 403);
$tag = DiscoverCategory::whereActive(true) $tag = DiscoverCategory::whereActive(true)
->whereSlug($slug) ->whereSlug($slug)
->firstOrFail(); ->firstOrFail();
@ -99,6 +111,8 @@ class DiscoverController extends Controller
public function showPersonal(Request $request) public function showPersonal(Request $request)
{ {
abort_if(!Auth::check(), 403);
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$tags = Cache::remember('profile-'.$profile->id.':hashtags', now()->addMinutes(15), function() use ($profile){ $tags = Cache::remember('profile-'.$profile->id.':hashtags', now()->addMinutes(15), function() use ($profile){
@ -123,4 +137,35 @@ class DiscoverController extends Controller
} }
return view('discover.loops.home'); return view('discover.loops.home');
} }
public function loopsApi(Request $request)
{
abort_if(!config('exp.loops'), 403);
// todo proper pagination, maybe LoopService
$loops = Status::whereType('video')
->whereScope('public')
->latest()
->take(18)
->get();
$resource = new Fractal\Resource\Collection($loops, new StatusStatelessTransformer());
return $this->fractal->createData($resource)->toArray();
}
public function loopWatch(Request $request)
{
abort_if(!Auth::check(), 403);
abort_if(!config('exp.loops'), 403);
$this->validate($request, [
'id' => 'integer|min:1'
]);
$id = $request->input('id');
// todo log loops
return response()->json(200);
}
} }