api appointment store and show
This commit is contained in:
98
Modules/Linksehat/Http/Controllers/Api/AppointmentController.php
Executable file
98
Modules/Linksehat/Http/Controllers/Api/AppointmentController.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Person;
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\Appointment\AppointmentDetailResource;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AppointmentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('linksehat::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$appointmentData = $request->only([
|
||||
'appointment_type',
|
||||
'organization_id',
|
||||
'speciality_id',
|
||||
]);
|
||||
|
||||
$appointmentData = array_merge($appointmentData, [
|
||||
'start_time' => $request->date . ' ' . $request->time
|
||||
]);
|
||||
|
||||
$appointment = Appointment::query()->create($appointmentData);
|
||||
|
||||
if ($request->has('doctor_id')) {
|
||||
$practitionerRole = PractitionerRole::query()->find($request->doctor_id);
|
||||
$practitionerRole->appointmentParticipantables()->create([
|
||||
'appointment_id' => $appointment->id,
|
||||
'type' => 'doctor',
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->has('patient_id')) {
|
||||
$person = Person::query()->find($request->patient_id);
|
||||
$person->appointmentParticipantables()->create([
|
||||
'appointment_id' => $appointment->id,
|
||||
'type' => 'patient',
|
||||
]);
|
||||
}
|
||||
|
||||
return Helper::responseJson($appointment, Response::HTTP_CREATED, 'Data appointment berhasil di buat');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$appointment = Appointment::query()->with(['appointmentParticipants', 'organization'])->find($id);
|
||||
|
||||
return new AppointmentDetailResource($appointment);
|
||||
|
||||
return response()->json($appointment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user