api person create & update & add family
This commit is contained in:
@@ -29,6 +29,16 @@ class AuthController extends Controller
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
|
||||
$person = Person::query()->create([
|
||||
'owner_user_id' => $user->id,
|
||||
'email' => $request->phone_or_email,
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
|
||||
User::query()->find($user->id)->update([
|
||||
'person_id' => $person->id
|
||||
]);
|
||||
} else {
|
||||
$user = User::updateOrCreate([
|
||||
'phone' => $request->phone_or_email
|
||||
@@ -37,6 +47,16 @@ class AuthController extends Controller
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
|
||||
$person = Person::query()->create([
|
||||
'owner_user_id' => $user->id,
|
||||
'phone' => $request->phone_or_email,
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
|
||||
User::query()->find($user->id)->update([
|
||||
'person_id' => $person->id
|
||||
]);
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
@@ -57,6 +77,7 @@ class AuthController extends Controller
|
||||
return response()->json([
|
||||
'message' => 'OTP Terkirim',
|
||||
'data' => [
|
||||
'otp' => $user->otp,
|
||||
'otp_valid_until' => $user->otp_created_at->addMinutes(config('linksehat.otp_valid_minutes'))
|
||||
]
|
||||
]);
|
||||
@@ -181,16 +202,11 @@ class AuthController extends Controller
|
||||
return Socialite::driver($provider)->redirect();
|
||||
}
|
||||
|
||||
public function handleSocialLoginCallback(Request $request, $provider)
|
||||
public function handleSocialLoginCallback($provider)
|
||||
{
|
||||
// get the provider's user. (In the provider server)
|
||||
$providerUser = Socialite::driver($provider)->user();
|
||||
$providerUser = Socialite::driver($provider)->stateless()->user();
|
||||
$user = User::query()->firstWhere('email', $providerUser->email);
|
||||
|
||||
// check if access token exists etc..
|
||||
// search for a user in our server with the specified provider id and provider name
|
||||
$user = User::where('email', $providerUser->email)->first();
|
||||
|
||||
// // if there is no record with these data, create a new user
|
||||
if (!$user) {
|
||||
$user = User::query()->create([
|
||||
'email' => $providerUser->email,
|
||||
@@ -200,6 +216,7 @@ class AuthController extends Controller
|
||||
'owner_user_id' => $user->id,
|
||||
'name' => $providerUser->name,
|
||||
'email' => $providerUser->email,
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
|
||||
User::query()->find($user->id)->update([
|
||||
@@ -207,7 +224,6 @@ class AuthController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// // return the token for usage
|
||||
return response([
|
||||
'message' => 'Selamat Datang',
|
||||
'user' => UserProfileResource::make($user),
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\File;
|
||||
use App\Models\Person;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\Speciality\SpecialityResource;
|
||||
use Modules\Linksehat\Http\Requests\PersonRequest;
|
||||
use Modules\Linksehat\Transformers\Person\PersonResource;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PersonController extends Controller
|
||||
{
|
||||
@@ -14,69 +17,11 @@ class PersonController extends Controller
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index()
|
||||
{
|
||||
$organizationId = $request->organization_id;
|
||||
$specialityId = $request->speciality_id;
|
||||
$personModel = Person::query()->with('avatar')->where('owner_user_id', auth()->user()->id)->get();
|
||||
|
||||
if (empty($organizationId) || empty($specialityId)) {
|
||||
$messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
|
||||
$messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
|
||||
|
||||
abort(400, 'missing parameter' . $messageorganizationId . $messageSpecialityId);
|
||||
}
|
||||
|
||||
$doctors = PractitionerRole::query()->with(['practitioner.person', 'speciality'])->where('organization_id', $organizationId)->where('speciality_id', $specialityId)->get();
|
||||
|
||||
foreach ($doctors as $key => $doctor) {
|
||||
$specialisName = $doctor->speciality->name;
|
||||
}
|
||||
|
||||
// Price belum ke ambil
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'statusCode' => 200,
|
||||
'message' => 'Data Berhasil di ambil',
|
||||
'data' => [
|
||||
'title' => 'Spesialis ' . $specialisName,
|
||||
'doctors' => SpecialityResource::collection($doctors)
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function searchSpecialityOrPerson(Request $request)
|
||||
{
|
||||
$doctors = PractitionerRole::query()
|
||||
->with(['practitioner.person', 'speciality'])
|
||||
->whereHas('practitioner.person', function ($query) use ($request) {
|
||||
$query->where('name', 'LIKE', "%{$request->value}%");
|
||||
})
|
||||
// ->whereHas('speciality', function ($query) use ($request) {
|
||||
// $query->where('name', 'LIKE', "%{$request->value}%");
|
||||
// })
|
||||
->get();
|
||||
|
||||
return $doctors;
|
||||
|
||||
// Price belum ke ambil
|
||||
// return response()->json([
|
||||
// 'status' => true,
|
||||
// 'statusCode' => 200,
|
||||
// 'message' => 'Data Berhasil di ambil',
|
||||
// 'data' => [
|
||||
// 'title' => 'Spesialis ' . $specialisName,
|
||||
// 'doctors' => SpecialityResource::collection($doctors)
|
||||
// ]
|
||||
// ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return $personModel;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,9 +29,21 @@ class PersonController extends Controller
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store()
|
||||
{
|
||||
//
|
||||
$personModel = Person::query()->create([
|
||||
'owner_user_id' => auth()->user()->id,
|
||||
'created_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'statusCode' => Response::HTTP_CREATED,
|
||||
'message' => 'Data Berhasil di buat',
|
||||
'data' => [
|
||||
'person' => $personModel,
|
||||
],
|
||||
], Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,19 +51,16 @@ class PersonController extends Controller
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
public function show(Person $person)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'statusCode' => Response::HTTP_OK,
|
||||
'message' => 'Data Person dengan nama ' . $person->name . ' berhasil di ambil',
|
||||
'data' => [
|
||||
'person' => new PersonResource($person),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,9 +69,55 @@ class PersonController extends Controller
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(PersonRequest $request, Person $person)
|
||||
{
|
||||
//
|
||||
$person->update($request->validated());
|
||||
|
||||
if ($request->hasFile('user_avatar')) {
|
||||
$pathFileAvatar = File::storeFile('avatar', $person->id, $request->file('user_avatar'));
|
||||
$person->files()->updateOrCreate([
|
||||
'type' => 'avatar',
|
||||
'name' => File::getFileName('avatar', $person->id, $request->file('user_avatar')),
|
||||
'extension' => $request->file('user_avatar')->getClientOriginalExtension(),
|
||||
'path' => $pathFileAvatar,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->hasFile('verification_file')) {
|
||||
$pathFileVerification = File::storeFile('dataDiri', $person->id, $request->file('verification_file'));
|
||||
$person->files()->updateOrCreate([
|
||||
'type' => 'dataDiri',
|
||||
'name' => File::getFileName('dataDiri', $person->id, $request->file('verification_file')),
|
||||
'extension' => $request->file('verification_file')->getClientOriginalExtension(),
|
||||
'path' => $pathFileVerification,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->has('relation_with_owner')) {
|
||||
$person->familyOwner()->updateOrCreate([
|
||||
'owner_id' => auth()->user()->person_id,
|
||||
'person_id' => $person->id,
|
||||
], [
|
||||
'owner_id' => auth()->user()->person_id,
|
||||
'relation_with_owner' => $request->relation_with_owner,
|
||||
'person_id' => $person->id,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'statusCode' => Response::HTTP_OK,
|
||||
'message' => 'Data Berhasil di update',
|
||||
'data' => [
|
||||
'person' => $person,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user