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