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