|
@@ -13,6 +13,7 @@ use App\Models\Section;
|
|
|
use App\Models\SectionTemplate;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
+use Illuminate\Support\Facades\Http;
|
|
|
use Illuminate\Support\Facades\Response;
|
|
|
|
|
|
class GuestController extends Controller
|
|
@@ -63,4 +64,48 @@ class GuestController extends Controller
|
|
|
return view('app.guest.appointment-confirmation', compact('appointment'));
|
|
|
}
|
|
|
|
|
|
+ public function processAppointmentConfirmation(Request $request){
|
|
|
+ $appointmentUid = $request->get('appointment_uid');
|
|
|
+ $appointment = Appointment::where('uid', $appointmentUid)->first();
|
|
|
+ abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
|
|
|
+ abort_if(!$appointment, 404, 'Invalid url');
|
|
|
+ abort_if($appointment->status == 'CANCELLED', 404, 'Appointment has been cancelled');
|
|
|
+ abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
|
|
|
+ abort_if($appointment->status == 'ABANDONED', 404, 'Appointment has been abandoned');
|
|
|
+
|
|
|
+ $decision = $request->get('decision');
|
|
|
+ $memo = $request->get('memo');
|
|
|
+ $response = null;
|
|
|
+ $data = [
|
|
|
+ 'uid' => $appointment->uid,
|
|
|
+ 'memo' => $memo
|
|
|
+ ];
|
|
|
+
|
|
|
+ $url = '/appointment/confirmationDecisionAccept';
|
|
|
+ if($decision == 'REJECT'){
|
|
|
+ $url = '/appointment/confirmationDecisionReject';
|
|
|
+ }
|
|
|
+
|
|
|
+ $response = $this->calljava($request, $url, $data);
|
|
|
+
|
|
|
+ if($response['success']){
|
|
|
+ return redirect()->back()->with('success', true);
|
|
|
+ }
|
|
|
+ return redirect()->back()->with('error', true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO move to utility
|
|
|
+ private function callJava($request, $endPoint, $data)
|
|
|
+ {
|
|
|
+ $url = config('stag.backendUrl') . $endPoint;
|
|
|
+
|
|
|
+ $response = Http::asForm()
|
|
|
+ ->withHeaders([
|
|
|
+ 'secret' => 'superman'
|
|
|
+ ])
|
|
|
+ ->post($url, $data)
|
|
|
+ ->json();
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
}
|