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