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