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