Update BaseApiController, add drafts method for Camera Roll

This commit is contained in:
Daniel Supernault 2019-10-14 21:33:42 -06:00
parent 5773434a13
commit bad2ecde56
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -20,6 +20,7 @@ use App\Transformer\Api\{
AccountTransformer,
NotificationTransformer,
MediaTransformer,
MediaDraftTransformer,
StatusTransformer
};
use League\Fractal;
@ -307,8 +308,9 @@ class BaseApiController extends Controller
public function verifyCredentials(Request $request)
{
abort_if(!$request->user(), 403);
$id = Auth::id();
$user = $request->user();
abort_if(!$user, 403);
$id = $user->id;
$res = Cache::remember('user:account:id:'.$id, now()->addHours(6), function() use($id) {
$profile = Profile::whereNull('status')->whereUserId($id)->firstOrFail();
@ -319,4 +321,19 @@ class BaseApiController extends Controller
return response()->json($res);
}
public function drafts(Request $request)
{
$user = $request->user();
abort_if(!$request->user(), 403);
$medias = Media::whereUserId($user->id)
->whereNull('status_id')
->latest()
->take(13)
->get();
$resource = new Fractal\Resource\Collection($medias, new MediaDraftTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
}
}