repository = $catalogo; parent::__construct(); } /** * Display a list of catalogo. * * @return json */ public function index(CatalogoAdminApiRequest $request) { $catalogos = $this->repository ->setPresenter('\\Catalogo\\Catalogo\\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(CatalogoAdminApiRequest $request, Catalogo $catalogo) { $catalogo = $catalogo->presenter(); $catalogo['code'] = 2001; return response()->json($catalogo) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new catalogo. * * @param Request $request * * @return json */ public function create(CatalogoAdminApiRequest $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(CatalogoAdminApiRequest $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(CatalogoAdminApiRequest $request, Catalogo $catalogo) { $catalogo = $catalogo->presenter(); $catalogo['code'] = 2003; return response()-> json($catalogo) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the catalogo. * * @param Request $request * @param Model $catalogo * * @return json */ public function update(CatalogoAdminApiRequest $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(CatalogoAdminApiRequest $request, Catalogo $catalogo) { try { $t = $catalogo->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('catalogo::catalogo.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }