diff --git a/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php b/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php new file mode 100644 index 00000000..74df4b84 --- /dev/null +++ b/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php @@ -0,0 +1,90 @@ +organization_id; + $specialityId = $request->speciality_id; + + if (empty($organizationId) || empty($specialityId)) { + $messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or '; + $messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id'; + + abort(400, 'missing parameter' . $messageorganizationId . $messageSpecialityId); + } + + return PractitionerRole::query()->with('practitioner')->where('organization_id', $organizationId)->where('speciality_id', $specialityId)->get(); + } + + /** + * Show the form for creating a new resource. + * @return Renderable + */ + public function 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(Request $request, $id) + { + // + } + + /** + * Show the form for editing the specified resource. + * @param int $id + * @return Renderable + */ + public function edit($id) + { + // + } + + /** + * 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) + { + // + } +} diff --git a/Modules/Linksehat/Routes/api.php b/Modules/Linksehat/Routes/api.php index f1890218..ce6c6822 100644 --- a/Modules/Linksehat/Routes/api.php +++ b/Modules/Linksehat/Routes/api.php @@ -6,6 +6,7 @@ use Modules\Linksehat\Http\Controllers\Api\DashboardController; use Modules\Linksehat\Http\Controllers\Api\DoctorController; use Modules\Linksehat\Http\Controllers\Api\HospitalController; use Modules\Linksehat\Http\Controllers\Api\ProfileController; +use Modules\Linksehat\Http\Controllers\Api\SpecialityController; /* |-------------------------------------------------------------------------- @@ -29,8 +30,7 @@ Route::prefix('linksehat')->group(function () { Route::get('social-login/{provider}', [AuthController::class, 'redirectSocialLogin']); Route::get('social-login/{provider}/callback', [AuthController::class, 'handleSocialLoginCallback']); - // Route::get('articles', [ArticleController::class, 'index']); - // Route::get('articles/id', [ArticleController::class, 'show']); + Route::get('specialities', [SpecialityController::class, 'index']); Route::get('hospitals', [HospitalController::class, 'index']); Route::get('hospitals/{id}', [HospitalController::class, 'show']); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 008b40fa..cf283605 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,7 +2,12 @@ namespace App\Exceptions; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Auth\AuthenticationException; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Validation\ValidationException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; class Handler extends ExceptionHandler @@ -47,4 +52,59 @@ class Handler extends ExceptionHandler // }); } + + public function render($request, Throwable $exception) + { + if ($request->wantsJson()) { + if ($exception instanceof AuthenticationException) { + return response()->json([ + 'status' => 'error', + 'message' => 'Unauthenticated', + 'errors' => [ + 'Unauthenticated' + ] + ], 401); + } + + if ($exception instanceof AuthorizationException) { + return response()->json([ + 'status' => 'error', + 'message' => 'This action is unauthorized.', + 'errors' => [ + 'This action is unauthorized.' + ] + ], 403); + } + + if ($exception instanceof NotFoundHttpException) { + return response()->json([ + 'status' => 'error', + 'message' => 'Route Not Found', + 'errors' => [ + 'Route Not Found' + ] + ], 404); + } + + if ($exception instanceof ModelNotFoundException) { + return response()->json([ + 'status' => 'error', + 'message' => 'Record for ' . str_replace('App', '', str_replace('\\Models\\', '', $exception->getModel())) . ' not found', + 'errors' => [ + 'Record for ' . str_replace('App', '', str_replace('\\Models\\', '', $exception->getModel())) . ' not found' + ] + ], 404); + } + + if ($exception instanceof ValidationException) { + return response()->json([ + 'status' => 'error', + 'message' => 'The given data was invalid.', + 'errors' => collect($exception->errors())->flatten() + ], 422); + } + } + + return parent::render($request, $exception); + } }