repository = $facebook_account; parent::__construct(); } /** * Display a list of facebook_account. * * @return json */ public function index(FacebookAccountUserApiRequest $request) { $facebook_accounts = $this->repository ->pushCriteria(new \Lavalite\Fbaccount\Repositories\Criteria\FacebookAccountUserCriteria()) ->setPresenter('\\Fbaccount\\Fbaccount\\Repositories\\Presenter\\FacebookAccountListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $facebook_accounts['code'] = 2000; return response()->json($facebook_accounts) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display facebook_account. * * @param Request $request * @param Model FacebookAccount * * @return Json */ public function show(FacebookAccountUserApiRequest $request, FacebookAccount $facebook_account) { if ($facebook_account->exists) { $facebook_account = $facebook_account->presenter(); $facebook_account['code'] = 2001; return response()->json($facebook_account) ->setStatusCode(200, 'SHOW_SUCCESS');; } else { return response()->json([]) ->setStatusCode(400, 'SHOW_ERROR'); } } /** * Show the form for creating a new facebook_account. * * @param Request $request * * @return json */ public function create(FacebookAccountUserApiRequest $request, FacebookAccount $facebook_account) { $facebook_account = $facebook_account->presenter(); $facebook_account['code'] = 2002; return response()->json($facebook_account) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new facebook_account. * * @param Request $request * * @return json */ public function store(FacebookAccountUserApiRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $facebook_account = $this->repository->create($attributes); $facebook_account = $facebook_account->presenter(); $facebook_account['code'] = 2004; return response()->json($facebook_account) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show facebook_account for editing. * * @param Request $request * @param Model $facebook_account * * @return json */ public function edit(FacebookAccountUserApiRequest $request, FacebookAccount $facebook_account) { if ($facebook_account->exists) { $facebook_account = $facebook_account->presenter(); $facebook_account['code'] = 2003; return response()-> json($facebook_account) ->setStatusCode(200, 'EDIT_SUCCESS');; } else { return response()->json([]) ->setStatusCode(400, 'SHOW_ERROR'); } } /** * Update the facebook_account. * * @param Request $request * @param Model $facebook_account * * @return json */ public function update(FacebookAccountUserApiRequest $request, FacebookAccount $facebook_account) { try { $attributes = $request->all(); $facebook_account->update($attributes); $facebook_account = $facebook_account->presenter(); $facebook_account['code'] = 2005; return response()->json($facebook_account) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the facebook_account. * * @param Request $request * @param Model $facebook_account * * @return json */ public function destroy(FacebookAccountUserApiRequest $request, FacebookAccount $facebook_account) { try { $t = $facebook_account->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('fbaccount::facebook_account.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }