Add API
This commit is contained in:
79
Modules/Linksehat/Http/Controllers/Api/ArticleController.php
Normal file
79
Modules/Linksehat/Http/Controllers/Api/ArticleController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('linksehat::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('linksehat::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('linksehat::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('linksehat::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -14,22 +14,44 @@ class AuthController extends Controller
|
||||
public function otpRequest(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'phone' => 'required'
|
||||
// 'phone' => 'required'
|
||||
'phone_or_email' => 'required'
|
||||
]);
|
||||
|
||||
if(filter_var($request->phone_or_email, FILTER_VALIDATE_EMAIL)) {
|
||||
$user = User::updateOrCreate([
|
||||
'email' => $request->phone_or_email
|
||||
], [
|
||||
'email' => $request->phone_or_email,
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$user = User::updateOrCreate([
|
||||
'phone' => $request->phone
|
||||
], [
|
||||
'phone' => $request->phone,
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
}
|
||||
|
||||
$user = User::updateOrCreate([
|
||||
'phone' => $request->phone
|
||||
], [
|
||||
'phone' => $request->phone,
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'message' => "User dengan nomor telepon ".$request->phone." tidak ditemukan"
|
||||
'message' => filter_var($request->phone_or_email, FILTER_VALIDATE_EMAIL) ?
|
||||
"User dengan alamat email ".$request->phone_or_email." tidak ditemukan" :
|
||||
"User dengan nomor telepon ".$request->phone_or_email." tidak ditemukan"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// TODO Send the OTP
|
||||
if (filter_var($request->phone_or_email, FILTER_VALIDATE_EMAIL)) {
|
||||
// Send Email
|
||||
} else {
|
||||
// Send Whatsapp
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'OTP Terkirim',
|
||||
'data' => [
|
||||
@@ -41,10 +63,12 @@ class AuthController extends Controller
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'email',
|
||||
'password' => 'required_with:email',
|
||||
'phone' => '',
|
||||
'otp' => 'required_with:phone',
|
||||
// 'email' => 'email',
|
||||
// 'password' => 'required_with:email',
|
||||
// 'phone' => '',
|
||||
// 'otp' => 'required_with:phone',
|
||||
'phone_or_email' => 'required',
|
||||
'otp' => 'required'
|
||||
]);
|
||||
|
||||
$loginType = null;
|
||||
|
||||
102
Modules/Linksehat/Http/Controllers/Api/DoctorController.php
Normal file
102
Modules/Linksehat/Http/Controllers/Api/DoctorController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorDetailResource;
|
||||
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorResource;
|
||||
|
||||
class DoctorController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hospitals = PractitionerRole::query()
|
||||
->with(['practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
||||
->when($request->search ?? null, function($query, $search) {
|
||||
$query->whereHas('practitioner.person', function($person) use ($search) {
|
||||
$person->where('name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
})
|
||||
->paginate(6);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Sukses mengambil data Dokter',
|
||||
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($hospitals))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('linksehat::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$doctor = PractitionerRole::query()
|
||||
->with(['practitioner', 'practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
||||
->where('id', $id)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json(PractitionerRoleToDoctorDetailResource::make($doctor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('linksehat::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\HospitalResource;
|
||||
|
||||
class HospitalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hospitals = Organization::query()
|
||||
->with(['currentAddress'])
|
||||
->where('type', 'hospital')
|
||||
->when($request->search ?? null, function($query, $search) {
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
})
|
||||
->paginate(6);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Sukses mengambil data Rumah Sakit',
|
||||
'hospitals' => Helper::paginateResources(HospitalResource::collection($hospitals))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('linksehat::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$hospital = Organization::query()->findOrFail($id);
|
||||
|
||||
return response()->json(HospitalResource::make($hospital));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('linksehat::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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