From 2088d0f467fc724380e9d9b405f4483c842849d4 Mon Sep 17 00:00:00 2001 From: Mohammad Javad Ghasemy Date: Fri, 7 Apr 2023 10:20:29 +0330 Subject: [PATCH] #9 feat: api to get list of users repositories from third party like github --- .../ThirdPartyRepositoriesListController.php | 30 +++++++++++++++++++ .../ThirdPartyRepositoryResource.php | 23 ++++++++++++++ app/Models/User.php | 5 ++++ app/Providers/RouteServiceProvider.php | 1 + routes/api.php | 4 +++ ...irdPartyRepositoriesListControllerTest.php | 7 +++++ 6 files changed, 70 insertions(+) create mode 100644 app/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListController.php create mode 100644 app/Http/Resources/Dashboard/ThirdPartyRepositoryResource.php create mode 100644 tests/Feature/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListControllerTest.php diff --git a/app/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListController.php b/app/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListController.php new file mode 100644 index 0000000..aca1c0d --- /dev/null +++ b/app/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListController.php @@ -0,0 +1,30 @@ + "geeksesi/code-review-pals", + "url" => "https://github.com/geeksesi/code-review-pals", + "provider" => $provider + ]), false) + ]); + return ThirdPartyRepositoryResource::collection($data); + } +} diff --git a/app/Http/Resources/Dashboard/ThirdPartyRepositoryResource.php b/app/Http/Resources/Dashboard/ThirdPartyRepositoryResource.php new file mode 100644 index 0000000..74b025e --- /dev/null +++ b/app/Http/Resources/Dashboard/ThirdPartyRepositoryResource.php @@ -0,0 +1,23 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'name' => $this->name, + 'url' => $this->url, + 'provider' => $this->provider + ]; + } +} diff --git a/app/Models/User.php b/app/Models/User.php index d15bc94..54660d8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -83,4 +83,9 @@ public function isAuthUser(): Attribute get: fn() => !$this->login_provider instanceof SocialiteProvider, ); } + + public function tokenAbilities(): array + { + return ['*']; + } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index f859850..b79e91d 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -29,6 +29,7 @@ public function boot(): void $this->routes(function () { Route::middleware('api') ->prefix('api') + ->name("api.") ->group(base_path('routes/api.php')); Route::middleware('web') diff --git a/routes/api.php b/routes/api.php index 889937e..2c9ff46 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,3 +17,7 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); }); + +Route::middleware(['auth:sanctum', 'api'])->prefix('/dashboard')->name("dashboard.")->group(function () { + Route::get('/third-party-repo-list/{provider}', \App\Http\Controllers\Dashboard\API\ThirdPartyRepositoriesListController::class)->name("third-party-repo-list"); +}); diff --git a/tests/Feature/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListControllerTest.php b/tests/Feature/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListControllerTest.php new file mode 100644 index 0000000..b46239f --- /dev/null +++ b/tests/Feature/Http/Controllers/Dashboard/API/ThirdPartyRepositoriesListControllerTest.php @@ -0,0 +1,7 @@ +get('/'); + + $response->assertStatus(200); +});