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