gq %!s(int64=7) %!d(string=hai) anos
pai
achega
e9fff3a1cf

+ 22 - 1
server/app/Http/Controllers/Api/V1/DreamController.php

xqd
@@ -729,16 +729,37 @@ class DreamController extends Controller
         }
     }
 
+    /**
+     * @api {get} /api/dream/share 分享
+     * @apiDescription 分享
+     * @apiParam {int}  id          梦想id
+     * @apiGroup Dream
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * @apiErrorExample {json} Error-Response:
+     */
 //    分享梦想
     public function share(Request $request)
     {
+        $validator = \Validator::make($request->all(),
+            [
+                'id'  => 'required',
+            ],
+            [
+                'id.required'  => '梦想id不存在',
+            ]
+        );
+        if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
         $url = env('APP_URL').'/api/dream/show?id='.$request->id;
         $dream = DreamInfoModel::with('img')->find($request->id);
+        $img = !empty($dream->img) ? $dream->img->pic : '';
         $html =
             "<div style='text-align: center'>
                 <a href='$url'>
                     <h1>$dream->name</h1>
-                    <img src='$dream->img->pic' style='width: 20px;height: 20px;' alt=''>
+                    <img src=\"$img\" style='width: 20px;height: 20px;' alt=''>
                 </a>
             </div>";
         return $html;

+ 4 - 0
server/routes/api.php

xqd
@@ -229,6 +229,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'dream.show',
         'uses' => 'DreamController@show',
     ]);
+    $api->get('dream/share', [
+        'as' => 'dream.share',
+        'uses' => 'DreamController@share',
+    ]);
     $api->get('dream/search', [
         'as' => 'dream.search',
         'uses' => 'DreamController@search',