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