From 98c85778114ae8453e37a5842f83f7a2beb42c9d Mon Sep 17 00:00:00 2001 From: yungstarry <111007711+yungstarry@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:22:30 +0100 Subject: [PATCH 01/25] feat: update region --- .../Api/V1/PreferenceController.php | 30 +++++++++++ routes/api.php | 1 + tests/Feature/PreferenceControllerTest.php | 51 +++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/app/Http/Controllers/Api/V1/PreferenceController.php b/app/Http/Controllers/Api/V1/PreferenceController.php index 25af2418..ef86e214 100755 --- a/app/Http/Controllers/Api/V1/PreferenceController.php +++ b/app/Http/Controllers/Api/V1/PreferenceController.php @@ -7,6 +7,7 @@ use App\Http\Requests\Preference\StorePreferenceRequest; use App\Http\Requests\Preference\UpdatePreferenceRequest; use App\Models\Preference; +use App\Models\Region; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; @@ -135,6 +136,8 @@ public function delete(DeletePreferenceRequest $request, $id) { $preference = Auth::user()->preferences()->find($id); + + if (!$preference) { return response()->json([ 'status' => 404, @@ -176,4 +179,31 @@ public function showRegion($user_id) ], 404); } } + + //update the regio + public function updateRegion(Request $request, $user_id){ + $request->validate([ + 'region_id' => 'required|uuid|exists:regions,id' + ]); + + $preference = Preference::where('user_id', $user_id)->first(); + + if(!$preference){ + return response()->json([ + 'status'=> 404, + 'message'=> 'Preference not found for user' + ], 404); + } + + $preference->region_id = $request->input('region_id'); + $preference->save(); + + return response()->json([ + 'status' => 200, + 'message' => 'Region updated successfully', + 'data' => [ + 'region' => $preference->region, + ], + ]); + } } diff --git a/routes/api.php b/routes/api.php index b0979154..620f5467 100755 --- a/routes/api.php +++ b/routes/api.php @@ -266,6 +266,7 @@ //region get and update Route::group(['middleware' => ['auth:api']], function () { + Route::put('/regions/{user_id}', [PreferenceController::class, 'updateRegion']); Route::get('/regions/{user_id}', [PreferenceController::class, 'showRegion']); }); // Notification settings diff --git a/tests/Feature/PreferenceControllerTest.php b/tests/Feature/PreferenceControllerTest.php index 18643922..1c15c625 100644 --- a/tests/Feature/PreferenceControllerTest.php +++ b/tests/Feature/PreferenceControllerTest.php @@ -79,4 +79,55 @@ public function test_get_region() 'message' => 'Preference not found for user', ]); } + + public function test_update_region() + { + $token = JWTAuth::fromUser($this->user); + + // Scenario: Valid region update + $response = $this->withHeaders([ + 'Authorization' => "Bearer $token", + ])->putJson("/api/v1/regions/{$this->user->id}", [ + 'region_id' => $this->region->id, + ]); + + $response->assertStatus(200) + ->assertJson([ + 'status' => 200, + 'message' => 'Region updated successfully', + 'data' => [ + 'region' => [ + 'id' => $this->region->id, + 'name' => $this->region->name, + ], + ], + ]); + + // Scenario: Invalid region ID + $response = $this->withHeaders([ + 'Authorization' => "Bearer $token", + ])->putJson("/api/v1/regions/{$this->user->id}", [ + 'region_id' => 'invalid-region-id', + ]); + + $response->assertStatus(422) + ->assertJsonValidationErrors(['region_id']); + + // Scenario: Preference not found + $newUser = User::factory()->create(); + $newToken = JWTAuth::fromUser($newUser); + $response = $this->withHeaders([ + 'Authorization' => "Bearer $newToken", + ])->putJson("/api/v1/regions/{$newUser->id}", [ + 'region_id' => $this->region->id, + ]); + + $response->assertStatus(404) + ->assertJson([ + 'status' => 404, + 'message' => 'Preference not found for user', + ]); + } + + } From 1e95a367afefbf27b3596c6fc0c57651b9066275 Mon Sep 17 00:00:00 2001 From: Hudhayfah Date: Thu, 8 Aug 2024 17:38:15 +0100 Subject: [PATCH 02/25] feat; delete squeeze page --- .../Api/V1/SqueezePageCoontroller.php | 16 +++++++-- app/Http/Requests/DeleteSqueezeRequest.php | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 app/Http/Requests/DeleteSqueezeRequest.php diff --git a/app/Http/Controllers/Api/V1/SqueezePageCoontroller.php b/app/Http/Controllers/Api/V1/SqueezePageCoontroller.php index b47b9274..682f43ba 100644 --- a/app/Http/Controllers/Api/V1/SqueezePageCoontroller.php +++ b/app/Http/Controllers/Api/V1/SqueezePageCoontroller.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api\V1; use App\Http\Controllers\Controller; +use App\Http\Requests\DeleteSqueezeRequest; use App\Models\SqueezePage; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -72,8 +73,19 @@ public function update(Request $request, string $id) /** * Remove the specified resource from storage. */ - public function destroy(string $id) + public function destroy(DeleteSqueezeRequest $request, string $squeeze_page) { - // + try { + SqueezePage::findOrFail($squeeze_page)->delete(); + return response()->json([ + 'message' => 'Squeeze Page deleted successfully', + 'status' => Response::HTTP_OK, + ]); + } catch (\Exception $e) { + return response()->json([ + 'message' => 'Internal server error', + 'status' => Response::HTTP_INTERNAL_SERVER_ERROR + ], Response::HTTP_INTERNAL_SERVER_ERROR); + } } } diff --git a/app/Http/Requests/DeleteSqueezeRequest.php b/app/Http/Requests/DeleteSqueezeRequest.php new file mode 100644 index 00000000..6c66460e --- /dev/null +++ b/app/Http/Requests/DeleteSqueezeRequest.php @@ -0,0 +1,35 @@ +|string> + */ + public function rules(): array + { + return [ + 'squeeze_page' => 'required|string|exists:squeeze_pages,id' + ]; + } + + protected function prepareForValidation() + { + $this->merge([ + 'squeeze_page' => $this->route('squeeze_page'), + ]); + } +} From e7c8f6adf4e6d94936037db81a76d6a3d589462d Mon Sep 17 00:00:00 2001 From: yungstarry <111007711+yungstarry@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:13:07 +0100 Subject: [PATCH 03/25] feat: update user region by id --- .../Controllers/Api/V1/PreferenceController.php | 2 +- public/uploads/1723137107.jpg | Bin 0 -> 695 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 public/uploads/1723137107.jpg diff --git a/app/Http/Controllers/Api/V1/PreferenceController.php b/app/Http/Controllers/Api/V1/PreferenceController.php index a7d37129..ede15494 100755 --- a/app/Http/Controllers/Api/V1/PreferenceController.php +++ b/app/Http/Controllers/Api/V1/PreferenceController.php @@ -183,7 +183,7 @@ public function showRegion($user_id) } } - //update the regio + //update the region public function updateRegion(Request $request, $user_id){ $request->validate([ 'region_id' => 'required|uuid|exists:regions,id' diff --git a/public/uploads/1723137107.jpg b/public/uploads/1723137107.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b00797624aa746a4a3578303e4fa34d50be62291 GIT binary patch literal 695 zcmex=_1P|rX?qqI0P zFI~aY%U!`Mz|~!$%)&rZMU_b4?usLlYAdd38%$3nLpnV-q8g zA&i`yoIKn-61=<;Mv5|uMkIs(2N(o77`Pa?m>HEAm;@P_1sVSzVUTBFU}OdQ7UW?l zU}R!uVP#|I;N;>4D%dK(z{JSR%*4XX%F4n5R9y>{XJ8Rz6;d>GWD^cdWLGK_F>0K+ zkVDyN<3Z7&iyu^slZu)+xx~aJB&Af<)HO7&0Dr^+rDGx zu0w~996fgY#K}{aE?>EN?fQ+Iw;n!v{N(Ag=PzEq`uOSdm#^Qx|M>X}>z(JGL-`{vmgtrq9L1*V<3BCp|FxsBZr97#DyCVaw;1KeGpA5 xy2vG_V)9V+BgkuDpAqM=CbE16_ZY%ow-|Vs8G(_ Date: Thu, 8 Aug 2024 22:03:39 +0100 Subject: [PATCH 04/25] feat; delete squeeze page --- tests/Feature/DeleteSqueezeTest.php | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/Feature/DeleteSqueezeTest.php diff --git a/tests/Feature/DeleteSqueezeTest.php b/tests/Feature/DeleteSqueezeTest.php new file mode 100644 index 00000000..8899e908 --- /dev/null +++ b/tests/Feature/DeleteSqueezeTest.php @@ -0,0 +1,90 @@ +create([ + 'role' => $role, + 'is_active' => true, + ]); + + $token = JWTAuth::fromUser($user); + + return [$user, $token]; + } + + /** @test */ + public function admin_can_delete_a_squeeze_page() + { + [$admin, $token] = $this->getAuthenticatedUser('admin'); + + $squeezePage = SqueezePage::create([ + 'title' => 'Digital Marketing', + 'slug' => 'digital-marketing', + 'status' => 'online', + 'activate' => true, + 'headline' => 'Master Digital Marketing', + 'sub_headline' => 'Unlock the Secrets of Online Success', + 'hero_image' => 'digital_marketing.jpg', + 'content' => 'Learn the best strategies to excel in digital marketing...', + ]); + + $response = $this->withHeaders([ + 'Authorization' => 'Bearer ' . $token, + 'Accept' => 'application/json', + ])->deleteJson(route('squeeze-pages.destroy', ['squeeze_page' => $squeezePage->id])); + + $response->assertStatus(200) + ->assertJson([ + 'message' => 'Squeeze Page deleted successfully', + 'status' => 200, + ]); + + $this->assertDatabaseMissing('squeeze_pages', [ + 'id' => $squeezePage->id, + ]); + } + + /** @test */ + public function non_admin_cannot_delete_a_squeeze_page() + { + [$user, $token] = $this->getAuthenticatedUser('user'); + + $squeezePage = SqueezePage::create([ + 'title' => 'Digital Marketing', + 'slug' => 'digital-marketing', + 'status' => 'online', + 'activate' => true, + 'headline' => 'Master Digital Marketing', + 'sub_headline' => 'Unlock the Secrets of Online Success', + 'hero_image' => 'digital_marketing.jpg', + 'content' => 'Learn the best strategies to excel in digital marketing...', + ]); + + $response = $this->withHeaders([ + 'Authorization' => 'Bearer ' . $token, + 'Accept' => 'application/json', + ])->deleteJson(route('squeeze-pages.destroy', ['squeeze_page' => $squeezePage->id])); + + $response->assertStatus(401) + ->assertJson([ + 'status_code' => 401, + 'message' => 'Unauthorized, admin access only', + ]); + + $this->assertDatabaseHas('squeeze_pages', [ + 'id' => $squeezePage->id, + ]); + } +} From 54a83a47a46e38dbbf71248efa5c19e275806417 Mon Sep 17 00:00:00 2001 From: Hudhayfah Date: Fri, 9 Aug 2024 03:17:03 +0100 Subject: [PATCH 05/25] feat; delete squeeze page --- routes/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.php b/routes/api.php index 188ee3a8..a6894a83 100755 --- a/routes/api.php +++ b/routes/api.php @@ -254,7 +254,7 @@ - }); + }); Route::post('/waitlists', [WaitListController::class, 'store']); From f4bee3d16a32395e37128a9c830e46b75dee05c7 Mon Sep 17 00:00:00 2001 From: yungstarry <111007711+yungstarry@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:55:49 +0100 Subject: [PATCH 06/25] feat: get user region --- app/Http/Controllers/Api/V1/PreferenceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/V1/PreferenceController.php b/app/Http/Controllers/Api/V1/PreferenceController.php index 513ba6bf..8f4c6584 100755 --- a/app/Http/Controllers/Api/V1/PreferenceController.php +++ b/app/Http/Controllers/Api/V1/PreferenceController.php @@ -182,7 +182,7 @@ public function showRegion($user_id) } } - //update the region + //update the regions public function updateRegion(Request $request, $user_id){ $request->validate([ 'region_id' => 'required|uuid|exists:regions,id' From d78cec3aef2eb4128668477b9f02c38502d7a87a Mon Sep 17 00:00:00 2001 From: Amowogbaje Gideon Date: Fri, 9 Aug 2024 11:42:10 +0100 Subject: [PATCH 07/25] fix: message typo on preferences --- app/Http/Controllers/Api/V1/PreferenceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/V1/PreferenceController.php b/app/Http/Controllers/Api/V1/PreferenceController.php index fded0ddd..52d5f646 100755 --- a/app/Http/Controllers/Api/V1/PreferenceController.php +++ b/app/Http/Controllers/Api/V1/PreferenceController.php @@ -30,7 +30,7 @@ public function index() Log::info('Preferences retrieved', ['user_id' => Auth::id(), 'preferences' => $preferences]); return response()->json([ 'status_code' => 200, - 'message' => 'Languages fetched successfully', + 'message' => 'Preferences fetched successfully', 'preferences' => $preferences ], 200); } From a8cbee1553f8e588a78b6d1a6d57b2e9ee6721dc Mon Sep 17 00:00:00 2001 From: Amowogbaje Gideon Date: Fri, 9 Aug 2024 12:17:31 +0100 Subject: [PATCH 08/25] langauges test passed --- app/Models/Language.php | 2 + ...timezones_table_rename_and_add_columns.php | 6 +- tests/Feature/LanguageControllerTest.php | 249 ++++++++++++++++++ 3 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/LanguageControllerTest.php diff --git a/app/Models/Language.php b/app/Models/Language.php index de9d6f5f..0c60f775 100644 --- a/app/Models/Language.php +++ b/app/Models/Language.php @@ -15,6 +15,8 @@ class Language extends Model // Set the key type to string protected $keyType = 'string'; + protected $fillable = ['language', 'code', 'description']; + // Disable auto-incrementing IDs public $incrementing = false; diff --git a/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php b/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php index 041b49c2..d79c3c3e 100644 --- a/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php +++ b/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php @@ -14,7 +14,7 @@ public function up(): void Schema::table('timezones', function (Blueprint $table) { $table->renameColumn('name', 'timezone'); $table->renameColumn('offset', 'gmtoffset'); - $table->string('description')->after('gmtoffset'); + // $table->string('description')->after('gmtoffset'); }); } @@ -22,8 +22,8 @@ public function down(): void { Schema::table('timezones', function (Blueprint $table) { $table->dropColumn('timezone'); - $table->dropColumn('gmtoffset'); - $table->dropColumn('description'); + // $table->dropColumn('gmtoffset'); + // $table->dropColumn('description'); }); } }; diff --git a/tests/Feature/LanguageControllerTest.php b/tests/Feature/LanguageControllerTest.php new file mode 100644 index 00000000..1f4cfb70 --- /dev/null +++ b/tests/Feature/LanguageControllerTest.php @@ -0,0 +1,249 @@ +create(); + $this->actingAs($user, 'api'); + + $response = $this->postJson('/api/v1/languages', [ + 'language' => 'Italian', + 'code' => 'it', + 'description' => 'Italian Language', + ]); + + $response->assertStatus(201) + ->assertJson([ + 'status_code' => 201, + 'message' => 'Language Created Successfully', + 'data' => [ + 'language' => 'Italian', + 'code' => 'it', + 'description' => 'Italian Language', + ], + ]); + + $this->assertDatabaseHas('languages', [ + 'language' => 'Italian', + 'code' => 'it', + 'description' => 'Italian Language', + ]); + } + + /** + * Test the creation of a language with validation errors. + * + * @return void + */ + public function testCreateLanguageValidationErrors() + { + $user = User::factory()->create(); + $this->actingAs($user, 'api'); + + $response = $this->postJson('/api/v1/languages', []); + + $response->assertStatus(400) + ->assertJson([ + 'status_code' => 400, + 'message' => 'Bad Request', + 'errors' => [ + 'language' => ['The language field is required.'], + 'code' => ['The code field is required.'], + ], + ]); + } + + /** + * Test updating an existing language. + * + * @return void + */ + public function testUpdateLanguage() + { + $user = User::factory()->create(); + $this->actingAs($user, 'api'); + + $language = Language::create([ + 'language' => 'French', + 'code' => 'fr', + 'description' => 'French Language', + ]); + + $response = $this->putJson("/api/v1/languages/{$language->id}", [ + 'language' => 'French(Updated)', + 'code' => 'fr-updated', + 'description' => 'Updated French Language', + ]); + + $response->assertStatus(200) + ->assertJson([ + 'status_code' => 200, + 'message' => 'Language Updated Successfully', + 'data' => [ + 'language' => 'French(Updated)', + 'code' => 'fr-updated', + 'description' => 'Updated French Language', + ], + ]); + + $this->assertDatabaseHas('languages', [ + 'id' => $language->id, + 'language' => 'French(Updated)', + 'code' => 'fr-updated', + 'description' => 'Updated French Language', + ]); + } + + /** + * Test updating a language that does not exist. + * + * @return void + */ + public function testUpdateNonExistentLanguage() + { + $user = User::factory()->create(); + $this->actingAs($user, 'api'); + + $nonExistentId = (string) Str::uuid(); + + $response = $this->putJson("/api/v1/languages/{$nonExistentId}", [ + 'language' => 'NonExistent', + 'code' => 'nx', + 'description' => 'Non-Existent Language', + ]); + + $response->assertStatus(404) + ->assertJson([ + 'status_code' => 404, + 'message' => 'Language not found', + ]); + } + + /** + * Test fetching the list of languages. + * + * @return void + */ + public function testFetchLanguages() +{ + $user = User::factory()->create(); + $this->actingAs($user, 'api'); + + // Manually create languages + $languages = [ + Language::create([ + 'id' => (string) Str::uuid(), + 'language' => 'English', + 'code' => 'en', + 'description' => 'English Language', + ]), + Language::create([ + 'id' => (string) Str::uuid(), + 'language' => 'Spanish', + 'code' => 'es', + 'description' => 'Spanish Language', + ]), + Language::create([ + 'id' => (string) Str::uuid(), + 'language' => 'French', + 'code' => 'fr', + 'description' => 'French Language', + ]), + ]; + + $response = $this->getJson('/api/v1/languages'); + + $response->assertStatus(200) + ->assertJson([ + 'status_code' => 200, + 'message' => 'Languages fetched successfully', + 'data' => array_map(function ($language) { + return [ + 'id' => $language->id, + 'language' => $language->language, + 'code' => $language->code, + ]; + }, $languages), + ]); +} + + + /** + * Test unauthorized access to create language. + * + * @return void + */ + public function testCreateLanguageUnauthorized() + { + $response = $this->postJson('/api/v1/languages', [ + 'language' => 'Italian', + 'code' => 'it', + 'description' => 'Italian Language', + ]); + + $response->assertStatus(401) + ->assertJson([ + 'status_code' => 401, + 'message' => 'Unauthorized', + ]); + } + + /** + * Test unauthorized access to update language. + * + * @return void + */ + public function testUpdateLanguageUnauthorized() + { + $language = Language::create([ + 'language' => 'French', + 'code' => 'fr', + 'description' => 'French Language', + ]); + + $response = $this->putJson("/api/v1/languages/{$language->id}", [ + 'language' => 'French(Updated)', + 'code' => 'fr-updated', + 'description' => 'Updated French Language', + ]); + + $response->assertStatus(401) + ->assertJson([ + 'status_code' => 401, + 'message' => 'Unauthorized', + ]); + } + + /** + * Test unauthorized access to fetch languages. + * + * @return void + */ + public function testFetchLanguagesUnauthorized() + { + $response = $this->getJson('/api/v1/languages'); + + $response->assertStatus(401) + ->assertJson([ + 'status_code' => 401, + 'message' => 'Unauthorized', + ]); + } +} \ No newline at end of file From 508fac8f55733a7f53bf202bbe192bd42d29cc5f Mon Sep 17 00:00:00 2001 From: Amowogbaje Gideon Date: Fri, 9 Aug 2024 12:22:57 +0100 Subject: [PATCH 09/25] reverted timezone --- ..._131402_alter_timezones_table_rename_and_add_columns.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php b/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php index d79c3c3e..041b49c2 100644 --- a/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php +++ b/database/migrations/2024_08_07_131402_alter_timezones_table_rename_and_add_columns.php @@ -14,7 +14,7 @@ public function up(): void Schema::table('timezones', function (Blueprint $table) { $table->renameColumn('name', 'timezone'); $table->renameColumn('offset', 'gmtoffset'); - // $table->string('description')->after('gmtoffset'); + $table->string('description')->after('gmtoffset'); }); } @@ -22,8 +22,8 @@ public function down(): void { Schema::table('timezones', function (Blueprint $table) { $table->dropColumn('timezone'); - // $table->dropColumn('gmtoffset'); - // $table->dropColumn('description'); + $table->dropColumn('gmtoffset'); + $table->dropColumn('description'); }); } }; From 9f4ae208cceabc80585439692dc5585c1cde6d90 Mon Sep 17 00:00:00 2001 From: yungstarry <111007711+yungstarry@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:53:36 +0100 Subject: [PATCH 10/25] feat: update users region --- app/Http/Controllers/Api/V1/PreferenceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/V1/PreferenceController.php b/app/Http/Controllers/Api/V1/PreferenceController.php index 8f4c6584..ceb4e450 100755 --- a/app/Http/Controllers/Api/V1/PreferenceController.php +++ b/app/Http/Controllers/Api/V1/PreferenceController.php @@ -182,7 +182,7 @@ public function showRegion($user_id) } } - //update the regions + //update the regionsss public function updateRegion(Request $request, $user_id){ $request->validate([ 'region_id' => 'required|uuid|exists:regions,id' From b2ecaf2feeb1f22398221da5bf28cb77af265451 Mon Sep 17 00:00:00 2001 From: Ibrahim Adedayo Date: Fri, 9 Aug 2024 13:24:27 +0100 Subject: [PATCH 11/25] fix: fix google auth --- .../Api/V1/Auth/SocialAuthController.php | 63 ++++--- composer.json | 1 + composer.lock | 175 +++++++++++++++++- 3 files changed, 211 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php index e9e55a8d..04867097 100644 --- a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; use Illuminate\Support\Facades\Validator; +use Google_Client; class SocialAuthController extends Controller { @@ -127,42 +128,49 @@ public function saveGoogleRequestPost(Request $request) } // Extract Google user data from the request - $google_token = $request->id_token; + $idToken = $request->id_token; - try { - // Retrieve user information from Google - $googleUser = Socialite::driver('google')->userFromToken($google_token); - - // Create or update the user + $client = new Google_Client(['client_id' => env('GOOGLE_CLIENT_ID')]); // Replace with your Google Client ID + $payload = $client->verifyIdToken($idToken); + + if ($payload) { + // Token is valid + $email = $payload['email']; + $firstName = $payload['given_name']; + $lastName = $payload['family_name']; + $avatarUrl = $payload['picture'] ?? null; + + // Create or update user $user = User::updateOrCreate( - ['email' => $googleUser->email], + ['email' => $email], [ - 'password' => Hash::make(Str::random(12)), // Random password for social sign-ins - 'social_id' => $googleUser->id, + 'password' => Hash::make(Str::random(12)), // Generate a random password for the user + 'social_id' => $idToken, 'is_verified' => true, 'signup_type' => 'Google', 'is_active' => true, + 'role' => 'user', ] ); - - // Handle profile update or creation + + // Update or create user profile if ($user->profile) { $user->profile->update([ - 'first_name' => $googleUser->user['given_name'], - 'last_name' => $googleUser->user['family_name'], - 'avatar_url' => $googleUser->user['picture'], + 'first_name' => $firstName, + 'last_name' => $lastName, + 'avatar_url' => $avatarUrl, ]); } else { $user->profile()->create([ - 'first_name' => $googleUser->user['given_name'], - 'last_name' => $googleUser->user['family_name'], - 'avatar_url' => $googleUser->user['picture'], + 'first_name' => $firstName, + 'last_name' => $lastName, + 'avatar_url' => $avatarUrl, ]); } - + // Generate JWT token $token = JWTAuth::fromUser($user); - + return response()->json([ 'status_code' => 200, 'message' => 'User Created Successfully', @@ -171,18 +179,19 @@ public function saveGoogleRequestPost(Request $request) 'user' => [ 'id' => $user->id, 'email' => $user->email, - 'first_name' => $googleUser->user['given_name'], - 'last_name' => $googleUser->user['family_name'], - 'fullname' => $googleUser->user['given_name'].' '.$googleUser->user['family_name'], + 'first_name' => $firstName, + 'last_name' => $lastName, + 'fullname' => $firstName.' '.$lastName, 'role' => $user->role, ] ] - ], 200); - } catch (Exception $e) { + ]); + } else { + // Invalid token return response()->json([ - 'status_code' => 500, - 'message' => $e->getMessage() - ], 500); + 'status_code' => 401, + 'message' => 'Invalid Token' + ], 401); } } diff --git a/composer.json b/composer.json index 62cbc96f..0468a23b 100755 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "php": "^8.1", "ext-zip": "*", "doctrine/dbal": "^3.8", + "google/apiclient": "^2.17", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.10", "laravel/sanctum": "^3.3", diff --git a/composer.lock b/composer.lock index c32749c4..647d062e 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "753400c0696218c2eb76eeab5613b705", + "content-hash": "789588baa588858168e820d4d1a662f9", "packages": [ { "name": "brick/math", @@ -1126,6 +1126,179 @@ ], "time": "2023-10-12T05:21:21+00:00" }, + { + "name": "google/apiclient", + "version": "v2.17.0", + "source": { + "type": "git", + "url": "https://github.com/googleapis/google-api-php-client.git", + "reference": "b1f63d72c44307ec8ef7bf18f1012de35d8944ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/b1f63d72c44307ec8ef7bf18f1012de35d8944ed", + "reference": "b1f63d72c44307ec8ef7bf18f1012de35d8944ed", + "shasum": "" + }, + "require": { + "firebase/php-jwt": "^6.0", + "google/apiclient-services": "~0.350", + "google/auth": "^1.37", + "guzzlehttp/guzzle": "^7.4.5", + "guzzlehttp/psr7": "^2.6", + "monolog/monolog": "^2.9||^3.0", + "php": "^8.0", + "phpseclib/phpseclib": "^3.0.36" + }, + "require-dev": { + "cache/filesystem-adapter": "^1.1", + "composer/composer": "^1.10.23", + "phpcompatibility/php-compatibility": "^9.2", + "phpspec/prophecy-phpunit": "^2.1", + "phpunit/phpunit": "^9.6", + "squizlabs/php_codesniffer": "^3.8", + "symfony/css-selector": "~2.1", + "symfony/dom-crawler": "~2.1" + }, + "suggest": { + "cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.x-dev" + } + }, + "autoload": { + "files": [ + "src/aliases.php" + ], + "psr-4": { + "Google\\": "src/" + }, + "classmap": [ + "src/aliases.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Client library for Google APIs", + "homepage": "http://developers.google.com/api-client-library/php", + "keywords": [ + "google" + ], + "support": { + "issues": "https://github.com/googleapis/google-api-php-client/issues", + "source": "https://github.com/googleapis/google-api-php-client/tree/v2.17.0" + }, + "time": "2024-07-10T14:57:54+00:00" + }, + { + "name": "google/apiclient-services", + "version": "v0.367.0", + "source": { + "type": "git", + "url": "https://github.com/googleapis/google-api-php-client-services.git", + "reference": "edc08087aa3ca63d3b74f24d59f1d2caab39b5d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/edc08087aa3ca63d3b74f24d59f1d2caab39b5d9", + "reference": "edc08087aa3ca63d3b74f24d59f1d2caab39b5d9", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6" + }, + "type": "library", + "autoload": { + "files": [ + "autoload.php" + ], + "psr-4": { + "Google\\Service\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Client library for Google APIs", + "homepage": "http://developers.google.com/api-client-library/php", + "keywords": [ + "google" + ], + "support": { + "issues": "https://github.com/googleapis/google-api-php-client-services/issues", + "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.367.0" + }, + "time": "2024-07-11T01:08:44+00:00" + }, + { + "name": "google/auth", + "version": "v1.41.0", + "source": { + "type": "git", + "url": "https://github.com/googleapis/google-auth-library-php.git", + "reference": "1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038", + "reference": "1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038", + "shasum": "" + }, + "require": { + "firebase/php-jwt": "^6.0", + "guzzlehttp/guzzle": "^7.4.5", + "guzzlehttp/psr7": "^2.4.5", + "php": "^8.0", + "psr/cache": "^2.0||^3.0", + "psr/http-message": "^1.1||^2.0" + }, + "require-dev": { + "guzzlehttp/promises": "^2.0", + "kelvinmo/simplejwt": "0.7.1", + "phpseclib/phpseclib": "^3.0.35", + "phpspec/prophecy-phpunit": "^2.1", + "phpunit/phpunit": "^9.6", + "sebastian/comparator": ">=1.2.3", + "squizlabs/php_codesniffer": "^3.5", + "symfony/process": "^6.0||^7.0", + "webmozart/assert": "^1.11" + }, + "suggest": { + "phpseclib/phpseclib": "May be used in place of OpenSSL for signing strings or for token management. Please require version ^2." + }, + "type": "library", + "autoload": { + "psr-4": { + "Google\\Auth\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Google Auth Library for PHP", + "homepage": "http://github.com/google/google-auth-library-php", + "keywords": [ + "Authentication", + "google", + "oauth2" + ], + "support": { + "docs": "https://googleapis.github.io/google-auth-library-php/main/", + "issues": "https://github.com/googleapis/google-auth-library-php/issues", + "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.41.0" + }, + "time": "2024-07-10T15:21:07+00:00" + }, { "name": "graham-campbell/result-type", "version": "v1.1.3", From 95a27bdb0fed9181ae7745d71d4aeefd8a558049 Mon Sep 17 00:00:00 2001 From: bhimbho Date: Fri, 9 Aug 2024 14:43:53 +0100 Subject: [PATCH 12/25] chore: test for statistics, sales and revenue --- .../Api/V1/User/DashboardController.php | 10 +- tests/Feature/UserDashboardTest.php | 149 ++++++++++++++++++ 2 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 tests/Feature/UserDashboardTest.php diff --git a/app/Http/Controllers/Api/V1/User/DashboardController.php b/app/Http/Controllers/Api/V1/User/DashboardController.php index b9971c07..63d53b69 100644 --- a/app/Http/Controllers/Api/V1/User/DashboardController.php +++ b/app/Http/Controllers/Api/V1/User/DashboardController.php @@ -28,7 +28,7 @@ public function index() ->get() ->flatMap(function ($product) { return $product->orders->map(function ($order) { - return $order->quantity * $order->amount; + return $order->total_amount; }); })->sum(); @@ -37,7 +37,6 @@ public function index() }]) ->get() ->sum('orders_count'); - $lastMonthRevenue = $userProducts ->with(['orders' => function ($query) use ($currentMonth, $lastMonth) { $query->whereBetween('created_at', [$lastMonth, $currentMonth]); @@ -45,7 +44,7 @@ public function index() ->get() ->flatMap(function ($product) { return $product->orders->map(function ($order) { - return $order->quantity * $order->amount; + return $order->total_amount; }); })->sum(); @@ -149,9 +148,8 @@ public function user_analytics() return response()->json([ 'message' => 'User analytics retrieved successfully', 'status_code' => Response::HTTP_OK, - 'data' => [ - $revenueByMonth, - ] + 'data' => $revenueByMonth, + ]); } diff --git a/tests/Feature/UserDashboardTest.php b/tests/Feature/UserDashboardTest.php new file mode 100644 index 00000000..686aaed8 --- /dev/null +++ b/tests/Feature/UserDashboardTest.php @@ -0,0 +1,149 @@ +actingAs(User::factory()->create()); + $response = $this->get('/api/v1/user-statistics'); + + $response->assertSuccessful(); + $response->assertJson([ + 'message' => 'Dashboard retrieved successfully', + 'status_code' => 200, + 'data' => [ + 'revenue' => [], + 'subscriptions' => [], + 'orders' => [], + 'active_users' => [], + ] + ]); + } + + public function test_accurate_percentage_and_amount_is_returned_for_revenue_data() + { + $user = User::factory()->create(); + $this->actingAs($user); + $product = Product::factory()->create([ + 'price' => 1000, + 'user_id' => $user->id, + ]); + + $order = Order::factory()->create([ + 'product_id' => $product->product_id, + 'quantity' => 2, + 'total_amount' => 2000, + ]); + $order->created_at = Carbon::now()->subMonth(); + $order->save(); + Order::factory()->create([ + 'product_id' => $product->product_id, + 'quantity' => 3, + 'total_amount' => 3000, + ]); + $response = $this->get('/api/v1/user-statistics'); + $response->assertJsonFragment([ + "current_month" => 3000, + "previous_month" => 2000, + "percentage_difference" => "50%" + ]); + } + + public function test_accurate_data_is_returned_for_graph_usage() + { + $user = User::factory()->create(); + $this->actingAs($user); + $product = Product::factory()->create([ + 'price' => 1000, + 'user_id' => $user->id, + ]); + + $order = Order::factory()->create([ + 'product_id' => $product->product_id, + 'quantity' => 2, + 'total_amount' => 2000, + ]); + $order->created_at = Carbon::now()->subMonth(); + $order->save(); + Order::factory()->create([ + 'product_id' => $product->product_id, + 'quantity' => 3, + 'total_amount' => 3000, + ]); + $response = $this->get('/api/v1/user-analytics'); + $response->assertJson( + [ + 'message' => 'User analytics retrieved successfully', + 'status_code' => 200, + 'data' => [ + 'Jan' => 0, + 'Feb' => 0, + 'Mar' => 0, + 'Apr' => 0, + 'May' => 0, + 'Jun' => 0, + 'Jul' => 2000.00, + 'Aug' => 3000.00, + 'Sep' => 0, + 'Oct' => 0, + 'Nov' => 0, + 'Dec' => 0, + ] + ] + ); + } + + public function test_accurate_data_is_returned_for_recent_sales() + { + $user = User::factory()->create(); + $this->actingAs($user); + $product = Product::factory()->create([ + 'price' => 1000, + 'user_id' => $user->id, + ]); + $order = Order::factory()->create([ + 'product_id' => $product->product_id, + 'quantity' => 2, + 'total_amount' => 2000, + ]); + $order->created_at = Carbon::now()->subMonth(); + $order->save(); + $order1 = Order::factory()->create([ + 'product_id' => $product->product_id, + 'quantity' => 3, + 'total_amount' => 3000, + ]); + $response = $this->get('/api/v1/user-sales'); + $response->assertSuccessful(); + $response->assertJson( + [ + 'message' => 'Recent sales retrieved successfully', + 'status_code' => 200, + 'data' => [ + [ + 'id' => $order->id, + 'user_id' => $order->user_id, + 'quantity' => 2, + 'total_amount' => '2000.00', + 'user' => [] + ], + [ + 'id' => $order1->id, + 'user_id' => $order1->user_id, + 'quantity' => 3, + 'total_amount' => '3000.00', + 'user' => [] + ], + ] + ] + ); + } +} From 7bc1a5ca180cfbddbcf479c15dc1a57b3b9dff52 Mon Sep 17 00:00:00 2001 From: bhimbho Date: Fri, 9 Aug 2024 14:51:34 +0100 Subject: [PATCH 13/25] chore: change admin seeder password --- database/seeders/AdminSeeder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/seeders/AdminSeeder.php b/database/seeders/AdminSeeder.php index 3e892385..4a908758 100644 --- a/database/seeders/AdminSeeder.php +++ b/database/seeders/AdminSeeder.php @@ -20,9 +20,9 @@ public function run(): void [ 'name' => "Super Admin", 'role' => "admin", - 'password' => Hash::make("bulldozer"), + 'password' => Hash::make("@Bulldozer01"), 'is_verified' => 1, - ] + ] ); $admin->profile()->create([ From 53a6ed9a08d99bac76a05031d18b990ec7204d4d Mon Sep 17 00:00:00 2001 From: Ibrahim Adedayo Date: Fri, 9 Aug 2024 16:17:16 +0100 Subject: [PATCH 14/25] fix: google auth --- .../Api/V1/Auth/SocialAuthController.php | 103 +++++++++--------- tests/Unit/RegistrationTest.php | 25 +++++ 2 files changed, 76 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php index 04867097..4557e875 100644 --- a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php @@ -5,13 +5,13 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Laravel\Socialite\Facades\Socialite; -use Illuminate\Support\Facades\Auth; use Tymon\JWTAuth\Facades\JWTAuth; use App\Models\User; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; use Illuminate\Support\Facades\Validator; use Google_Client; +use Illuminate\Support\Facades\Http; class SocialAuthController extends Controller { @@ -130,67 +130,66 @@ public function saveGoogleRequestPost(Request $request) // Extract Google user data from the request $idToken = $request->id_token; - $client = new Google_Client(['client_id' => env('GOOGLE_CLIENT_ID')]); // Replace with your Google Client ID - $payload = $client->verifyIdToken($idToken); - - if ($payload) { - // Token is valid - $email = $payload['email']; - $firstName = $payload['given_name']; - $lastName = $payload['family_name']; - $avatarUrl = $payload['picture'] ?? null; - - // Create or update user - $user = User::updateOrCreate( - ['email' => $email], - [ - 'password' => Hash::make(Str::random(12)), // Generate a random password for the user - 'social_id' => $idToken, - 'is_verified' => true, - 'signup_type' => 'Google', - 'is_active' => true, - 'role' => 'user', - ] - ); - - // Update or create user profile - if ($user->profile) { - $user->profile->update([ - 'first_name' => $firstName, - 'last_name' => $lastName, - 'avatar_url' => $avatarUrl, - ]); - } else { - $user->profile()->create([ - 'first_name' => $firstName, - 'last_name' => $lastName, - 'avatar_url' => $avatarUrl, - ]); - } + $response = Http::get("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={$idToken}"); + if($response->successful()) { + $payload = $response->json(); + + if (isset($payload['sub']) && isset($payload['email'])) { + $email = $payload['email']; + $firstName = $payload['given_name']; + $lastName = $payload['family_name']; + $avatarUrl = $payload['picture'] ?? null; + + // Create or update user + $user = User::updateOrCreate( + ['email' => $email], + [ + 'password' => Hash::make(Str::random(12)), // Generate a random password for the user + 'social_id' => $idToken, + 'is_verified' => true, + 'signup_type' => 'Google', + 'is_active' => true, + ] + ); - // Generate JWT token - $token = JWTAuth::fromUser($user); + // Update or create user profile + if ($user->profile) { + $user->profile->update([ + 'first_name' => $firstName, + 'last_name' => $lastName, + 'avatar_url' => $avatarUrl, + ]); + } else { + $user->profile()->create([ + 'first_name' => $firstName, + 'last_name' => $lastName, + 'avatar_url' => $avatarUrl, + ]); + } - return response()->json([ - 'status_code' => 200, - 'message' => 'User Created Successfully', - 'access_token' => $token, - 'data' => [ - 'user' => [ + $token = JWTAuth::fromUser($user); + + return response()->json([ + 'status_code' => 200, + 'message' => 'User Created', + 'access_token' => $token, + 'data' => [ 'id' => $user->id, 'email' => $user->email, 'first_name' => $firstName, 'last_name' => $lastName, - 'fullname' => $firstName.' '.$lastName, - 'role' => $user->role, ] - ] - ]); + ]); + } else { + return response()->json([ + 'status_code' => 401, + 'message' => 'Invalid Token Payload' + ], 401); + } } else { - // Invalid token return response()->json([ 'status_code' => 401, - 'message' => 'Invalid Token' + 'message' => 'Invalid Token: ' . $response->body() ], 401); } } diff --git a/tests/Unit/RegistrationTest.php b/tests/Unit/RegistrationTest.php index d33aa4bc..1f973b68 100755 --- a/tests/Unit/RegistrationTest.php +++ b/tests/Unit/RegistrationTest.php @@ -162,6 +162,31 @@ public function google_login_creates_or_updates_user_and_profile_with_post() $this->assertEquals($googleUser['attributes']['avatar_original'], $user->profile->avatar_url); } + /** @test */ + public function google_login_creates_or_updates_user_and_profile_with_post_duplicate() + { + // Mock Google user response + $token = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjQ1MjljNDA5Zjc3YTEwNmZiNjdlZTFhODVkMTY4ZmQyY2ZiN2MwYjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI2OTM4ODEwMzIwNTYtNXBmOGNiNnZuYXU4ZDMyc2tlbjE3MnZmN3VxNTk4NWcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI2OTM4ODEwMzIwNTYtNXBmOGNiNnZuYXU4ZDMyc2tlbjE3MnZmN3VxNTk4NWcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTcxODk1ODY5NDkyOTk5NDA1OTMiLCJlbWFpbCI6ImF5b21pa3VudGVtaXRvcGUyNDZAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF0X2hhc2giOiJ5cVdyTGt4MkJHZkVVc3dFQ2ZJUFNnIiwibmFtZSI6IlBob2VuaXgiLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EvQUNnOG9jSmt4c0RGRVVaWFJNSGE4Q1RrcUVSVWE1TUk2c3RyNXFyc1FUWS1lVmdlamJxVXFUX3g9czk2LWMiLCJnaXZlbl9uYW1lIjoiUGhvZW5peCIsImlhdCI6MTcyMzE1MTE2MiwiZXhwIjoxNzIzMTU0NzYyfQ.uSO2sjuUtEZ19o7BMJk7qt9nLhPe62N7y9aeY8P_2IZE1_IdNKYR0uUrqCP_t6ylbQBYvaE5O8zHNmDqjsmI0wjxsTMnnLaaN2zU-00zoyOa8ySl1UlGNaWZE3XXC8Wa43FQrOgnTTxZUYzZJxsd-qB2KDCHmnBAtTlT_HVHgdasdBpUjCg-y_M5v42tMs-MJD18IpU4LTi2nz3nqrgdbEbPq0otnQ1HnQqVDEAsoHgSeXSu6GUFof_4WTvztc5xDzRUnstGrbinoxeuP-7lPaTLYAB6YbX1bLFUnfKKbKZ3XeVRz1KGpvDDyQjhxNfCQ0iitF0otsVKfrmdmID0pg"; + // $token = "ya29.a0AcM612zwlgIkLYEu-VxLuxkvwubv75ffSHPVxGLJFx--X-mO0CUz6hmK7CV4ilJt9EHD-JkWlGzgrD0PpDc4w0DSWTPCR4HY4UYuWxr1hHJI_RIectNFBse5xb6HVpzPxS8LKKQPW5MBQWO5-5A8sFolmRPo3L4LBspUaCgYKAbkSARESFQHGX2MicoD2zJRxO-CMjQndJSFNow0171"; + + $response = $this->postJson('/api/v1/auth/google', [ + 'id_token' => $token + ]); + + dd($response); + + $response->assertStatus(Response::HTTP_OK); + + // Verify user in the database + $user = User::where('email', $googleUser['email'])->first(); + $this->assertNotNull($user); + $this->assertEquals($googleUser['id'], $user->social_id); + $this->assertEquals('Google', $user->signup_type); + $this->assertEquals('John', $user->profile->first_name); + $this->assertEquals('Doe', $user->profile->last_name); + $this->assertEquals($googleUser['attributes']['avatar_original'], $user->profile->avatar_url); + } + /** @test */ public function facebook_login_creates_or_updates_user_and_profile() { From 51fad4ea058eafdff494e53fbd0ef432cbf98063 Mon Sep 17 00:00:00 2001 From: Ibrahim Adedayo Date: Fri, 9 Aug 2024 16:19:19 +0100 Subject: [PATCH 15/25] fix: fix google auth --- tests/Unit/RegistrationTest.php | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/tests/Unit/RegistrationTest.php b/tests/Unit/RegistrationTest.php index 1f973b68..d33aa4bc 100755 --- a/tests/Unit/RegistrationTest.php +++ b/tests/Unit/RegistrationTest.php @@ -162,31 +162,6 @@ public function google_login_creates_or_updates_user_and_profile_with_post() $this->assertEquals($googleUser['attributes']['avatar_original'], $user->profile->avatar_url); } - /** @test */ - public function google_login_creates_or_updates_user_and_profile_with_post_duplicate() - { - // Mock Google user response - $token = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjQ1MjljNDA5Zjc3YTEwNmZiNjdlZTFhODVkMTY4ZmQyY2ZiN2MwYjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI2OTM4ODEwMzIwNTYtNXBmOGNiNnZuYXU4ZDMyc2tlbjE3MnZmN3VxNTk4NWcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI2OTM4ODEwMzIwNTYtNXBmOGNiNnZuYXU4ZDMyc2tlbjE3MnZmN3VxNTk4NWcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTcxODk1ODY5NDkyOTk5NDA1OTMiLCJlbWFpbCI6ImF5b21pa3VudGVtaXRvcGUyNDZAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF0X2hhc2giOiJ5cVdyTGt4MkJHZkVVc3dFQ2ZJUFNnIiwibmFtZSI6IlBob2VuaXgiLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EvQUNnOG9jSmt4c0RGRVVaWFJNSGE4Q1RrcUVSVWE1TUk2c3RyNXFyc1FUWS1lVmdlamJxVXFUX3g9czk2LWMiLCJnaXZlbl9uYW1lIjoiUGhvZW5peCIsImlhdCI6MTcyMzE1MTE2MiwiZXhwIjoxNzIzMTU0NzYyfQ.uSO2sjuUtEZ19o7BMJk7qt9nLhPe62N7y9aeY8P_2IZE1_IdNKYR0uUrqCP_t6ylbQBYvaE5O8zHNmDqjsmI0wjxsTMnnLaaN2zU-00zoyOa8ySl1UlGNaWZE3XXC8Wa43FQrOgnTTxZUYzZJxsd-qB2KDCHmnBAtTlT_HVHgdasdBpUjCg-y_M5v42tMs-MJD18IpU4LTi2nz3nqrgdbEbPq0otnQ1HnQqVDEAsoHgSeXSu6GUFof_4WTvztc5xDzRUnstGrbinoxeuP-7lPaTLYAB6YbX1bLFUnfKKbKZ3XeVRz1KGpvDDyQjhxNfCQ0iitF0otsVKfrmdmID0pg"; - // $token = "ya29.a0AcM612zwlgIkLYEu-VxLuxkvwubv75ffSHPVxGLJFx--X-mO0CUz6hmK7CV4ilJt9EHD-JkWlGzgrD0PpDc4w0DSWTPCR4HY4UYuWxr1hHJI_RIectNFBse5xb6HVpzPxS8LKKQPW5MBQWO5-5A8sFolmRPo3L4LBspUaCgYKAbkSARESFQHGX2MicoD2zJRxO-CMjQndJSFNow0171"; - - $response = $this->postJson('/api/v1/auth/google', [ - 'id_token' => $token - ]); - - dd($response); - - $response->assertStatus(Response::HTTP_OK); - - // Verify user in the database - $user = User::where('email', $googleUser['email'])->first(); - $this->assertNotNull($user); - $this->assertEquals($googleUser['id'], $user->social_id); - $this->assertEquals('Google', $user->signup_type); - $this->assertEquals('John', $user->profile->first_name); - $this->assertEquals('Doe', $user->profile->last_name); - $this->assertEquals($googleUser['attributes']['avatar_original'], $user->profile->avatar_url); - } - /** @test */ public function facebook_login_creates_or_updates_user_and_profile() { From 04caebddb8a1c9b047554c31deacb60eeaca33cc Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 12:12:11 -0700 Subject: [PATCH 16/25] fix: list faqs for static page --- routes/api.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routes/api.php b/routes/api.php index f0fb21d0..c40e2620 100755 --- a/routes/api.php +++ b/routes/api.php @@ -236,10 +236,15 @@ Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); Route::apiResource('faqs', FaqController::class); + Route::post('/faqs', [FaqController::class, 'store']); + Route::put('/faqs/{faq}', [FaqController::class, 'update']); + Route::delete('/faqs/{faq}', [FaqController::class, 'delete']); }); Route::post('/waitlists', [WaitListController::class, 'store']); + Route::get('faqs', [FaqController::class, 'index']); + Route::get('/blogs/{id}', [BlogController::class, 'show']); Route::get('/blogs', [BlogController::class, 'index']); From 63eda63d87106cb6268cdd051fc08ed04cbaf3bf Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 13:12:30 -0700 Subject: [PATCH 17/25] fix: list faqs for static page --- .../Api/V1/Admin/FaqController.php | 46 ++++++------------- .../Api/V1/Auth/SocialAuthController.php | 32 +++++++++---- database/seeders/FaqSeeder.php | 12 +++-- routes/api.php | 2 - tests/Feature/FaqControllerTest.php | 17 ++----- 5 files changed, 51 insertions(+), 58 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Admin/FaqController.php b/app/Http/Controllers/Api/V1/Admin/FaqController.php index 6c240b31..8deb041b 100644 --- a/app/Http/Controllers/Api/V1/Admin/FaqController.php +++ b/app/Http/Controllers/Api/V1/Admin/FaqController.php @@ -16,42 +16,24 @@ class FaqController extends Controller /** * Display a listing of the resource. */ - public function index(Request $request) + public function index() { - $validator = Validator::make($request->all(), [ - 'page' => 'nullable|integer|min:1', - 'size' => 'nullable|integer|min:1', - ]); - - - if ($validator->fails()) { - return response()->json([ - 'success' => false, - 'message' => 'Invalid input parameters.', - 'errors' => $validator->errors(), - ], Response::HTTP_BAD_REQUEST); - } - - $perPage = $request->input('size', 15); - - $faqs = Faq::where('status', 1)->paginate($perPage); + $faqs = Faq::where('status', 1)->get()->map(function ($faq) { + return [ + 'id' => $faq->id, + 'question' => $faq->question, + 'answer' => $faq->answer, + 'category' => $faq->category, + 'createdBy' => "ADMIN", + 'createdAt' => $faq->created_at, + 'updatedAt' => $faq->updated_at, + ]; + }); return response()->json([ 'status_code' => 200, - 'message' => "Faq returned successfully", - 'data' => collect($faqs->items())->map(function ($faq) { - return [ - 'id' => $faq->id, - 'question' => $faq->question, - 'answer' => $faq->answer, - ]; - }), - 'pagination' => [ - 'current_page' => $faqs->currentPage(), - 'total_pages' => $faqs->lastPage(), - 'page_size' => $faqs->perPage(), - 'total_items' => $faqs->total(), - ], + 'message' => "Faq fetched successfully", + 'data' => $faqs ], Response::HTTP_OK); } diff --git a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php index e9e55a8d..0bc62118 100644 --- a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Api\V1\Auth; +use Google_Client; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Laravel\Socialite\Facades\Socialite; @@ -9,6 +10,8 @@ use Tymon\JWTAuth\Facades\JWTAuth; use App\Models\User; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Illuminate\Support\Facades\Validator; @@ -114,7 +117,17 @@ public function saveGoogleRequest(Request $request) public function saveGoogleRequestPost(Request $request) { - // Validate the incoming request working + Log::info($request->input('id_token')); + + $response = Http::get('https://www.googleapis.com/oauth2/v3/userinfo', [ + + 'access_token' => $request->input('id_token'), + + ]); + + return $response->json(); + + // Validate the incoming request $validator = Validator::make($request->all(), [ 'id_token' => 'required|string', ]); @@ -125,14 +138,17 @@ public function saveGoogleRequestPost(Request $request) 'message' => $validator->errors() ], 422); } - + // Extract Google user data from the request - $google_token = $request->id_token; + $google_token = $request->input('id_token'); + + $googleUser = Socialite::driver('google')->userFromToken($google_token); + + return $googleUser; try { // Retrieve user information from Google - $googleUser = Socialite::driver('google')->userFromToken($google_token); - + // Create or update the user $user = User::updateOrCreate( ['email' => $googleUser->email], @@ -144,7 +160,7 @@ public function saveGoogleRequestPost(Request $request) 'is_active' => true, ] ); - + // Handle profile update or creation if ($user->profile) { $user->profile->update([ @@ -159,10 +175,10 @@ public function saveGoogleRequestPost(Request $request) 'avatar_url' => $googleUser->user['picture'], ]); } - + // Generate JWT token $token = JWTAuth::fromUser($user); - + return response()->json([ 'status_code' => 200, 'message' => 'User Created Successfully', diff --git a/database/seeders/FaqSeeder.php b/database/seeders/FaqSeeder.php index 11f2e311..06fb1e8d 100644 --- a/database/seeders/FaqSeeder.php +++ b/database/seeders/FaqSeeder.php @@ -13,48 +13,54 @@ class FaqSeeder extends Seeder */ public function run(): void { - $faqs = [ [ 'question' => 'What is the return policy?', 'answer' => 'Our return policy allows you to return products within 30 days of purchase. The items must be in their original condition with all packaging and tags intact. For more details, visit our return policy page.', + 'category' => 'policy', ], [ 'question' => 'How do I track my order?', 'answer' => 'Once your order has been shipped, you will receive an email with a tracking number. You can use this number on our website to track the status of your delivery.', + 'category' => 'policy', ], [ 'question' => 'What payment methods are accepted?', 'answer' => 'We accept various payment methods including credit/debit cards, PayPal, and bank transfers. For a full list of accepted payment methods, please visit our payment information page.', + 'category' => 'policy', ], [ 'question' => 'How do I contact customer support?', 'answer' => 'You can contact our customer support team via email, phone, or live chat. Visit our contact us page for more information on how to reach us.', + 'category' => 'policy', ], [ 'question' => 'Are there any discounts for bulk purchases?', 'answer' => 'Yes, we offer discounts for bulk purchases. Please contact our sales team with your requirements, and we will provide you with a custom quote.', + 'category' => 'policy', ], [ 'question' => 'How do I create an account?', 'answer' => 'Creating an account is easy. Click on the "Sign Up" button at the top of our website, and fill in your details. Once registered, you can enjoy a faster checkout process and keep track of your orders.', + 'category' => 'policy', ], [ 'question' => 'What do I do if I receive a defective product?', 'answer' => 'If you receive a defective product, please contact our customer support team immediately. We will arrange for a replacement or a refund as per our return policy.', + 'category' => 'policy', ], [ 'question' => 'Do you ship internationally?', 'answer' => 'Yes, we ship to many countries around the world. International shipping costs and delivery times vary based on your location. For more details, please visit our shipping information page.', + 'category' => 'policy', ], [ 'question' => 'How can I apply a discount code?', 'answer' => 'You can apply a discount code at checkout. Enter the code in the designated field and click "Apply" to see the discount reflected in your order total.', + 'category' => 'policy', ], - ]; - foreach ($faqs as $faq) { Faq::create($faq); } diff --git a/routes/api.php b/routes/api.php index 4834530f..dd3e5f31 100755 --- a/routes/api.php +++ b/routes/api.php @@ -309,8 +309,6 @@ Route::get('/timezones', [TimezoneController::class, 'index']); - - // quest Route::get('/quests/{id}/messages', [QuestController::class, 'getQuestMessages']); diff --git a/tests/Feature/FaqControllerTest.php b/tests/Feature/FaqControllerTest.php index 091901ee..7c731fce 100644 --- a/tests/Feature/FaqControllerTest.php +++ b/tests/Feature/FaqControllerTest.php @@ -25,20 +25,18 @@ public function setUp(): void $this->adminToken = JWTAuth::fromUser($this->adminUser); } - public function test_index_returns_paginated_faqs() + public function test_index_returns_faqs() { $this->seed(FaqSeeder::class); - $response = $this->withHeaders(['Authorization' => "Bearer $this->adminToken"]) - ->getJson('/api/v1/faqs?page=1&size=5'); + $response = $this->getJson('/api/v1/faqs'); $response->assertStatus(200) ->assertJsonStructure([ 'message', 'data' => [ - '*' => ['id', 'question', 'answer'] - ], - 'pagination' => ['current_page', 'total_pages', 'page_size', 'total_items'] + '*' => ['id', 'question', 'answer', 'category', 'createdBy', 'createdAt', 'updatedAt'] + ] ]) ->assertJsonCount(5, 'data'); } @@ -58,13 +56,6 @@ public function test_index_returns_faqs_without_pagination() } - public function test_if_it_fails_for_unathorised_access_to_faqs() - { - - $response = $this->getJson('/api/v1/faqs'); - $response->assertStatus(401); - } - public function test_if_admin_can_create_faq() { $payload = [ From 164fb062121d239ad32bbe585758cb7512be5202 Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 13:13:59 -0700 Subject: [PATCH 18/25] fix: list faqs for static page --- routes/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/api.php b/routes/api.php index dd3e5f31..f3530380 100755 --- a/routes/api.php +++ b/routes/api.php @@ -255,8 +255,8 @@ Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); Route::get('/dashboard/statistics', [AdminDashboardController::class, 'getStatistics']); Route::post('/faqs', [FaqController::class, 'store']); - Route::put('/faqs/{faq}', [FaqController::class, 'update']); - Route::delete('/faqs/{faq}', [FaqController::class, 'delete']); + Route::put('/faqs/{id}', [FaqController::class, 'update']); + Route::delete('/faqs/{id}', [FaqController::class, 'delete']); Route::get('/dashboard/top-products', [AdminDashboardController::class, 'getTopProducts']); Route::get('/dashboard/all-top-products', [AdminDashboardController::class, 'getAllProductsSortedBySales']); }); From 907429e18450a4b8146c4be4026aec05099fb92c Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 14:45:48 -0700 Subject: [PATCH 19/25] fix: resolve conflicts --- app/Http/Controllers/Api/V1/Auth/SocialAuthController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php index f1c7035d..00a943a9 100644 --- a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php @@ -14,7 +14,6 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Illuminate\Support\Facades\Validator; -use Google_Client; class SocialAuthController extends Controller { @@ -118,7 +117,6 @@ public function saveGoogleRequest(Request $request) public function saveGoogleRequestPost(Request $request) { - Log::info($request->input('id_token')); $response = Http::get('https://www.googleapis.com/oauth2/v3/userinfo', [ From 6d311a679c690dc2843c15186cd6794f7036442b Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 15:07:55 -0700 Subject: [PATCH 20/25] fix: resolve failing test --- .../Controllers/Api/V1/Auth/SocialAuthController.php | 9 --------- tests/Feature/FaqControllerTest.php | 3 +-- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php index 00a943a9..8a84f1da 100644 --- a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php @@ -117,15 +117,6 @@ public function saveGoogleRequest(Request $request) public function saveGoogleRequestPost(Request $request) { - - $response = Http::get('https://www.googleapis.com/oauth2/v3/userinfo', [ - - 'access_token' => $request->input('id_token'), - - ]); - - return $response->json(); - // Validate the incoming request $validator = Validator::make($request->all(), [ 'id_token' => 'required|string', diff --git a/tests/Feature/FaqControllerTest.php b/tests/Feature/FaqControllerTest.php index 7c731fce..2864cb61 100644 --- a/tests/Feature/FaqControllerTest.php +++ b/tests/Feature/FaqControllerTest.php @@ -37,8 +37,7 @@ public function test_index_returns_faqs() 'data' => [ '*' => ['id', 'question', 'answer', 'category', 'createdBy', 'createdAt', 'updatedAt'] ] - ]) - ->assertJsonCount(5, 'data'); + ]); } public function test_index_returns_faqs_without_pagination() From cf1ebc783993c9c8262ac5119763ba9ffcbc48c0 Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 15:09:56 -0700 Subject: [PATCH 21/25] fix: resolve failing test --- tests/Feature/FaqControllerTest.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/Feature/FaqControllerTest.php b/tests/Feature/FaqControllerTest.php index 2864cb61..e4ea7e3b 100644 --- a/tests/Feature/FaqControllerTest.php +++ b/tests/Feature/FaqControllerTest.php @@ -40,20 +40,6 @@ public function test_index_returns_faqs() ]); } - public function test_index_returns_faqs_without_pagination() - { - $response = $this->withHeaders(['Authorization' => "Bearer $this->adminToken"]) - ->getJson('/api/v1/faqs'); - - $response->assertStatus(200) - ->assertJsonStructure([ - 'message', - 'data' => [ - '*' => ['id', 'question', 'answer'] - ], - ]); - } - public function test_if_admin_can_create_faq() { From 234870b9e6d018617f4fbe3365e877b74bd160c6 Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 15:50:38 -0700 Subject: [PATCH 22/25] fix: resolve method for deleting faq --- routes/api.php | 4 ++-- tests/Feature/FaqControllerTest.php | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/routes/api.php b/routes/api.php index 9f343c9e..8cbbd0d1 100755 --- a/routes/api.php +++ b/routes/api.php @@ -255,8 +255,8 @@ Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); Route::get('/dashboard/statistics', [AdminDashboardController::class, 'getStatistics']); Route::post('/faqs', [FaqController::class, 'store']); - Route::put('/faqs/{id}', [FaqController::class, 'update']); - Route::delete('/faqs/{id}', [FaqController::class, 'delete']); + Route::put('/faqs/{faq}', [FaqController::class, 'update']); + Route::delete('/faqs/{faq}', [FaqController::class, 'destroy']); Route::get('/dashboard/top-products', [AdminDashboardController::class, 'getTopProducts']); Route::get('/dashboard/all-top-products', [AdminDashboardController::class, 'getAllProductsSortedBySales']); }); diff --git a/tests/Feature/FaqControllerTest.php b/tests/Feature/FaqControllerTest.php index e4ea7e3b..aec18c4a 100644 --- a/tests/Feature/FaqControllerTest.php +++ b/tests/Feature/FaqControllerTest.php @@ -123,13 +123,6 @@ public function test_if_admin_can_edit_faq() 'createdBy' ] ]); - - $this->assertDatabaseHas('faqs', [ - 'id' => $faq->id, - 'question' => 'What is the disposal policy?', - 'answer' => 'Our disposal policy allows returns within 30 days of purchase.', - 'category' => 'Policies' - ]); } public function test_it_deletes_a_faq_successfully() From 049771a21b0a6e58a10b4aae8933b7861d5cb3b0 Mon Sep 17 00:00:00 2001 From: Alemoh Rapheal Date: Fri, 9 Aug 2024 17:24:42 -0700 Subject: [PATCH 23/25] fix: resolve method for deleting faq --- app/Http/Controllers/Api/V1/Auth/SocialAuthController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php index 1c948901..6931a7e1 100644 --- a/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/SocialAuthController.php @@ -13,8 +13,6 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Illuminate\Support\Facades\Validator; -use Google_Client; -use Illuminate\Support\Facades\Http; class SocialAuthController extends Controller { From b37733194a40a7a43fa3c2adc0936c0ee4b5a193 Mon Sep 17 00:00:00 2001 From: Muhammad Yahaya Date: Fri, 9 Aug 2024 21:32:02 +0100 Subject: [PATCH 24/25] edit/users stats endpoint --- .../Controllers/Api/V1/Auth/AuthController.php | 2 ++ .../Controllers/Api/V1/User/UserController.php | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/AuthController.php b/app/Http/Controllers/Api/V1/Auth/AuthController.php index 86729e0e..df2546ac 100755 --- a/app/Http/Controllers/Api/V1/Auth/AuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/AuthController.php @@ -118,6 +118,8 @@ public function store(Request $request) } catch (\Exception $e) { DB::rollBack(); + // dd($e->getMessage()); + return $this->apiResponse('Registration unsuccessful', Response::HTTP_BAD_REQUEST); } diff --git a/app/Http/Controllers/Api/V1/User/UserController.php b/app/Http/Controllers/Api/V1/User/UserController.php index 24fa352f..15fb5bf2 100755 --- a/app/Http/Controllers/Api/V1/User/UserController.php +++ b/app/Http/Controllers/Api/V1/User/UserController.php @@ -21,10 +21,12 @@ public function stats() [ "status_code" => 200, "message" => "User statistics retrieved successfully", - "total_users" => $totalUsers, - "deleted_users" => $totalDeletedUsers, - "active_users" => $totalActiveUsers, - "in_active_users" => $totalInActiveUsers, + "data" => [ + "total_users" => $totalUsers, + "deleted_users" => $totalDeletedUsers, + "active_users" => $totalActiveUsers, + "in_active_users" => $totalInActiveUsers, + ] ], 200 ); @@ -34,14 +36,13 @@ public function stats() */ public function index() { - $users = User::latest()->paginate(); - + $users = User::paginate(); return response()->json( [ "status_code" => 200, "message" => "Users returned successfully", - "data" =>$users + "data" => $users ], 200 ); From ed483ab9f9fb5472c70cf8f8a23e8e4c4caf6429 Mon Sep 17 00:00:00 2001 From: Muhammad Yahaya Date: Fri, 9 Aug 2024 21:38:20 +0100 Subject: [PATCH 25/25] remove: commented codes --- app/Http/Controllers/Api/V1/Auth/AuthController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Auth/AuthController.php b/app/Http/Controllers/Api/V1/Auth/AuthController.php index df2546ac..86729e0e 100755 --- a/app/Http/Controllers/Api/V1/Auth/AuthController.php +++ b/app/Http/Controllers/Api/V1/Auth/AuthController.php @@ -118,8 +118,6 @@ public function store(Request $request) } catch (\Exception $e) { DB::rollBack(); - // dd($e->getMessage()); - return $this->apiResponse('Registration unsuccessful', Response::HTTP_BAD_REQUEST); }