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