. */ namespace App\Http\Controllers; use App\Application; use App\Appointment; use App\Exceptions\InvalidAppointmentException; use App\Exceptions\InvalidAppointmentStatusException; use App\Http\Requests\SaveNotesRequest; use App\Services\AppointmentService; use App\Services\MeetingNoteService; use Carbon\Carbon; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; class AppointmentController extends Controller { private $appointmentService; private $meetingNoteService; public function __construct(AppointmentService $appointmentService, MeetingNoteService $meetingNoteService) { $this->appointmentService = $appointmentService; $this->meetingNoteService = $meetingNoteService; } public function saveAppointment(Request $request, Application $application): RedirectResponse { $this->authorize('create', Appointment::class); $appointmentDate = Carbon::parse($request->appointmentDateTime); $this->appointmentService->createAppointment($application, $appointmentDate, $request->appointmentDescription, $request->appointmentLocation); return redirect() ->back() ->with('success',__('Appointment successfully scheduled @ :appointmentTime', ['appointmentTime', $appointmentDate->toDateTimeString()])); } /** * @throws AuthorizationException */ public function updateAppointment(Application $application, $status): RedirectResponse { $this->authorize('update', $application->appointment); try { $this->appointmentService->updateAppointment($application, $status); return redirect() ->back() ->with('success', __("Interview finished! Staff members can now vote on it.")); } catch (InvalidAppointmentStatusException $ex) { return redirect() ->back() ->with('error', $ex->getMessage()); } } public function saveNotes(SaveNotesRequest $request, Application $application) { try { $this->meetingNoteService->addToApplication($application, $request->noteText); return redirect() ->back() ->with('success', 'Saved notes.'); } catch (InvalidAppointmentException $ex) { return redirect() ->back() ->with('error', $ex->getMessage()); } } }