gq преди 8 години
родител
ревизия
0119ebb17c
променени са 3 файла, в които са добавени 61 реда и са изтрити 49 реда
  1. 28 25
      server/app/Http/Controllers/Api/V1/DreamController.php
  2. 29 24
      server/app/Http/Controllers/Api/V1/MyController.php
  3. 4 0
      server/routes/api.php

+ 28 - 25
server/app/Http/Controllers/Api/V1/DreamController.php

xqd xqd
@@ -419,24 +419,31 @@ class DreamController extends Controller
      * @apiParam {string}  keyword   关键字
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     *{
-     *   "status": true,
-     *   "status_code": 0,
-     *   "message": "",
-     *   "data": {
-     *       "data": [
-     *           {
-     *              "dream": "haha",  梦想名
-     *               "user_pic": [
-     *               {
-     *                  "pic": "",   用户头像
-     *               }
-     *               ],
-     *              "dream_img": "",  梦想图片
-     *          }
-     *       ]
-     *   }
-     *}
+    {
+        "status": true,
+        "status_code": 0,
+        "message": "",
+        "data": [
+            {
+                "id": 5,
+                "user_id": 1,
+                "name": "梦想标题1",
+                "about": "梦想介绍",
+                "coin": 2500,
+                "time": 72000,
+                "get_coin": 0,
+                "mark": 0,
+                "status": 0,
+                "video": "url",
+                "score": 100079365,
+                "sign": "梦想达人",
+                "created_at": "2017-06-25 12:45:22",
+                "updated_at": "2017-06-28 15:50:41",
+                "user": {},
+                "imgs": []
+            },
+        ]
+    }
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      */
@@ -447,14 +454,10 @@ class DreamController extends Controller
             return $this->api('');
         }
         $keyword ='%'.$request->keyword.'%';
-        $data = DreamInfoModel::where('dream','like',$keyword)->
-        orWhere('sign','like',$keyword)->get();
-        foreach ($data as $k => $value) {
-            $value->user_pic = $value->dreamFindUser;
-            $value->dream_img = $value->dreamImgsFirst->pic;
-        }
+        $data = DreamInfoModel::where('name','like',$keyword)->
+        orWhere('sign','like',$keyword)->with('user','imgs')->get();
         $this->insertSearchTable($user->id,$request->keyword);
-        return $this->api(compact('data'));
+        return $this->api($data);
     }
 
     public function insertSearchTable($id,$keyword)

+ 29 - 24
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd xqd
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Api\V1;
 
 use App\Models\BaseDictionaryOptionModel;
 use App\Models\BaseSettingsModel;
+use App\Models\DreamInfoModel;
+use App\Models\SearchInfoModel;
 use App\Models\SystemInfoModel;
 use App\Models\UserCareDream;
 use App\Models\UserInfoModel;
@@ -416,24 +418,31 @@ class MyController extends Controller
      * @apiParam {string}  keyword   关键字
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     *{
-     *   "status": true,
-     *   "status_code": 0,
-     *   "message": "",
-     *   "data": {
-     *       "data": [
-     *           {
-     *              "dream": "haha",  梦想名
-     *               "user_pic": [
-     *               {
-     *                  "pic": "",   用户头像
-     *               }
-     *               ],
-     *              "dream_img": "",  梦想图片
-     *          }
-     *       ]
-     *   }
-     *}
+    {
+        "status": true,
+        "status_code": 0,
+        "message": "",
+        "data": [
+            {
+                "id": 5,
+                "user_id": 1,
+                "name": "梦想标题1",
+                "about": "梦想介绍",
+                "coin": 2500,
+                "time": 72000,
+                "get_coin": 0,
+                "mark": 0,
+                "status": 0,
+                "video": "url",
+                "score": 100079365,
+                "sign": "梦想达人",
+                "created_at": "2017-06-25 12:45:22",
+                "updated_at": "2017-06-28 15:50:41",
+                "user": {},
+                "imgs": []
+            },
+        ]
+    }
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      */
@@ -444,12 +453,8 @@ class MyController extends Controller
             return $this->api('');
         }
         $keyword ='%'.$request->keyword.'%';
-        $data = DreamInfoModel::where('dream','like',$keyword)->
-        orWhere('sign','like',$keyword)->get();
-        foreach ($data as $k => $value) {
-            $value->user_pic = $value->dreamFindUser;
-            $value->dream_img = $value->dreamImgsFirst->pic;
-        }
+        $data = DreamInfoModel::where('name','like',$keyword)->
+        orWhere('sign','like',$keyword)->with('user','imgs')->get();
         $this->insertSearchTable($user->id,$request->keyword);
         return $this->api(compact('data'));
     }

+ 4 - 0
server/routes/api.php

xqd
@@ -141,6 +141,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'my.collection',
         'uses' => 'MyController@collection',
     ]);
+    $api->get('my/search_collection', [
+        'as' => 'my.search_collection',
+        'uses' => 'MyController@searchCollection',
+    ]);
     $api->get('my/setting', [
         'as' => 'my.setting',
         'uses' => 'MyController@setting',