diff --git a/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php b/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php new file mode 100644 index 00000000..811b22a0 --- /dev/null +++ b/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php @@ -0,0 +1,56 @@ +all(), [ + 'name' => 'required|string|max:255', + 'description' => 'required|string', + 'price' => 'required|numeric', + 'slug' => 'required|string|max:255', + 'tags' => 'required|string', + 'imageUrl' => 'nullable|string|max:255', + 'status' => 'required|string|max:50', + 'quantity' => 'required|integer', + 'org_id' => 'required|uuid', + ]); + + if ($validator->fails()) { + return response()->json([ + 'success' => false, + 'status_code' => 422, + 'message' => 'Validation errors', + 'data' => $validator->errors(), + ], 422); + } + + $product = Product::create([ + 'user_id' => auth()->id(), + 'name' => $request->name, + 'description' => $request->description, + 'price' => $request->price, + 'slug' => $request->slug, + 'tags' => $request->tags, + 'imageUrl' => $request->imageUrl, + 'status' => $request->status, + 'quantity' => $request->quantity, + 'is_archived' => false, + 'org_id' => $request->org_id, + ]); + + return response()->json([ + 'success' => true, + 'status_code' => 201, + 'message' => 'Product created successfully', + 'data' => $product, + ], 201); + } +} diff --git a/database/seeders/OrderSeeder.php b/database/seeders/OrderSeeder.php index 8accffea..5fd30d41 100644 --- a/database/seeders/OrderSeeder.php +++ b/database/seeders/OrderSeeder.php @@ -14,6 +14,6 @@ class OrderSeeder extends Seeder { public function run() { - Order::factory()->count(10)->create(); + // Order::factory()->count(10)->create(); } } diff --git a/database/seeders/QuestSeeder.php b/database/seeders/QuestsSeeder.php similarity index 100% rename from database/seeders/QuestSeeder.php rename to database/seeders/QuestsSeeder.php diff --git a/public/uploads/1723037656.jpg b/public/uploads/1723037656.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723037656.jpg differ diff --git a/public/uploads/1723038561.jpg b/public/uploads/1723038561.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723038561.jpg differ diff --git a/routes/api.php b/routes/api.php index d05283cb..383d42d3 100755 --- a/routes/api.php +++ b/routes/api.php @@ -1,52 +1,53 @@ group(function () { + Route::post('/products', [SuperAdminProductController::class, 'store']); + }); + Route::middleware(['auth:api', 'admin'])->group(function () { Route::get('/email-templates', [EmailTemplateController::class, 'index']); Route::post('/email-templates', [EmailTemplateController::class, 'store']); @@ -257,7 +263,6 @@ -// quest + // quest Route::get('/quests/{id}/messages', [QuestController::class, 'getQuestMessages']); - }); diff --git a/tests/Feature/SuperAdminProductControllerTest.php b/tests/Feature/SuperAdminProductControllerTest.php new file mode 100644 index 00000000..b2cdb4ed --- /dev/null +++ b/tests/Feature/SuperAdminProductControllerTest.php @@ -0,0 +1,74 @@ +artisan('migrate:fresh --seed'); + + $loginResponse = $this->postJson('/api/v1/auth/login', [ + 'email' => 'bulldozeradmin@hng.com', + 'password' => 'bulldozer', + ]); + + $loginResponse->assertStatus(200); + $loginResponse->assertJsonStructure([ + 'status_code', + 'message', + 'access_token', + 'data' => [ + 'user' => [ + 'id', + 'email', + 'role', + ], + ], + ]); + + $accessToken = $loginResponse->json('access_token'); + $userId = $loginResponse->json('data.user.id'); + + $validOrgId = Product::first()->org_id; + + $productResponse = $this->withHeaders([ + 'Authorization' => 'Bearer ' . $accessToken, + ])->postJson('/api/v1/products', [ + 'name' => 'okoz', + 'description' => 'boy', + 'price' => 10, + 'status' => 'active', + 'slug' => 'jkdffjk', + 'tags' => 'gk;fk', + 'quantity' => '5', + 'org_id' => $validOrgId, + ]); + + $productResponse->assertStatus(201); + $productResponse->assertJson([ + 'success' => true, + 'status_code' => 201, + 'message' => 'Product created successfully', + 'data' => [ + 'name' => 'okoz', + 'description' => 'boy', + 'price' => 10, + 'status' => 'active', + 'slug' => 'jkdffjk', + 'tags' => 'gk;fk', + 'quantity' => '5', + 'org_id' => $validOrgId, + 'is_archived' => false, + 'imageUrl' => null, + 'user_id' => $userId, + ], + ]); + } +}