Kaynağa Gözat

视频分类

liuzejian 1 yıl önce
ebeveyn
işleme
1eae08f0be

+ 35 - 0
modules/Video/Http/Controllers/VideoCategoryController.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace Modules\Video\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+class VideoCategoryController extends CatchController
+{
+    /**
+     * 视频分类
+     * @param Request $request
+     * @return array
+     */
+    public function list(Request $request) {
+        $videoCategorys = DB::table('video_category')
+            ->get();
+        $pCategory = $videoCategorys->where('pid', '=', 0)->all();
+        $data = [];
+        foreach ($pCategory as $item) {
+            $data[$item->id] = [
+                'channel_id' => $item->id,
+                'channel_name' => $item->category_name,
+            ];
+        }
+        foreach ($videoCategorys->where('pid', '!=', 0)->all() as $item) {
+            $data[$item->pid]['list'][] = [
+                'category_id' => $item->id, 'category_name' => $item->category_name,
+            ];
+        }
+
+        return array_values($data);
+    }
+}

+ 2 - 0
modules/Video/routes/route.php

@@ -4,11 +4,13 @@ use Illuminate\Support\Facades\Route;
 use Modules\System\Http\Controllers\NoticesController;
 use Modules\System\Http\Controllers\NoticeTypesController;
 use Modules\Video\Http\Controllers\EpisodeController;
+use Modules\Video\Http\Controllers\VideoCategoryController;
 use Modules\Video\Http\Controllers\VideoController;
 
 Route::prefix('videoStock')->group(function () {
     Route::get('video/list', [VideoController::class, 'list']);
     Route::get('episode/list', [EpisodeController::class, 'list']);
+    Route::get('videoCategory/list', [VideoCategoryController::class, 'list']);
 
 
     Route::post('video/update', [VideoController::class, 'update']);

+ 4 - 4
tests/UsedTestCase.php

@@ -13,11 +13,11 @@ abstract class UsedTestCase extends BaseTestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $tokenInfo = $this->post('http://localhost/api/login', [
-//            'email' => 'catch@admin.com',
-//            'password' => 'catchadmin',
+            'email' => 'catch@admin.com',
+            'password' => 'catchadmin',
             'remember' => false,
-            'email' => 'xiaoli@qq.com',
-            'password' => 'Qaz123',
+//            'email' => 'xiaoli@qq.com',
+//            'password' => 'Qaz123',
 //        'email' => 'aa4@test.com',
 //            'password' => '123',
         ])->json();

+ 20 - 0
tests/Video/Http/Controllers/VideoCategoryControllerTest.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Tests\Video\Http\Controllers;
+
+use Modules\Video\Http\Controllers\VideoCategoryController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class VideoCategoryControllerTest extends UsedTestCase
+{
+
+    public function testList()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/videoStock/videoCategory/list');
+
+        $this->dumpJson($res);
+    }
+}