user()->account->reminders() ->orderBy($this->sort, $this->sortDirection) ->paginate($this->getLimitPerPage()); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return ReminderResource::collection($reminders); } /** * Get the detail of a given reminder. * @param Request $request * @return \Illuminate\Http\Response */ public function show(Request $request, $reminderId) { try { $reminder = Reminder::where('account_id', auth()->user()->account_id) ->where('id', $reminderId) ->firstOrFail(); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } return new ReminderResource($reminder); } /** * Store the reminder. * @param Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { try { $reminder = (new CreateReminder)->execute( $request->all() + [ 'account_id' => auth()->user()->account->id, ] ); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } catch (ValidationException $e) { return $this->respondValidatorFailed($e->validator); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return new ReminderResource($reminder); } /** * Update the reminder. * @param Request $request * @param int $reminderId * @return \Illuminate\Http\Response */ public function update(Request $request, $reminderId) { try { $reminder = (new UpdateReminder)->execute( $request->all() + [ 'account_id' => auth()->user()->account->id, 'reminder_id' => $reminderId, ] ); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } catch (ValidationException $e) { return $this->respondValidatorFailed($e->validator); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return new ReminderResource($reminder); } /** * Delete a reminder. * @param Request $request * @return \Illuminate\Http\Response */ public function destroy(Request $request, $reminderId) { try { (new DestroyReminder)->execute([ 'account_id' => auth()->user()->account->id, 'reminder_id' => $reminderId, ]); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } catch (ValidationException $e) { return $this->respondValidatorFailed($e->validator); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return $this->respondObjectDeleted((int) $reminderId); } /** * Get the list of reminders for the given contact. * * @return \Illuminate\Http\Response */ public function reminders(Request $request, $contactId) { try { $contact = Contact::where('account_id', auth()->user()->account_id) ->where('id', $contactId) ->firstOrFail(); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } $reminders = $contact->reminders() ->orderBy($this->sort, $this->sortDirection) ->paginate($this->getLimitPerPage()); return ReminderResource::collection($reminders); } }