Showing
3 changed files
with
67 additions
and
0 deletions
... | @@ -79,4 +79,51 @@ class HomeController extends Controller | ... | @@ -79,4 +79,51 @@ class HomeController extends Controller |
79 | return Response::fail($exception->getMessage()); | 79 | return Response::fail($exception->getMessage()); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | + | ||
83 | + /** | ||
84 | + * 目前的逻辑是:点赞或者收藏过的不显示在里面 | ||
85 | + * @param Request $request | ||
86 | + * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource | ||
87 | + */ | ||
88 | + public function fresh(Request $request) | ||
89 | + { | ||
90 | + $page = $request->get('page',1); | ||
91 | + $page_size = $request->get('page_size',20); | ||
92 | + $lists = Immerse::query() | ||
93 | + ->where('state', 1) | ||
94 | + ->orderByDesc('created_at') | ||
95 | + ->skip(($page - 1) * $page_size)->take($page_size + 1)->get(); | ||
96 | + $token = $request->bearerToken(); | ||
97 | + $user_id = $token ? ((Sanctum::$personalAccessTokenModel)::findToken($token))->tokenable_id : 'asdasd'; | ||
98 | + | ||
99 | + $data = []; | ||
100 | + foreach ($lists as $list) { | ||
101 | + if (!$list->isPraise($list->id, $user_id) && !$list->isCollect($list->id, $user_id)){ | ||
102 | + $data[] = [ | ||
103 | + 'id' => $list->id, | ||
104 | + 'user_id' => $list->user_id, | ||
105 | + 'title' => $list->title, | ||
106 | + 'content' => $list->content, | ||
107 | + 'weather' => $list->weather, | ||
108 | + 'haungli' => $list->haungli, | ||
109 | + 'longitude' => $list->longitude, | ||
110 | + 'latitude' => $list->latitude, | ||
111 | + 'location' => $list->location, | ||
112 | + 'url' => $list->url, | ||
113 | + 'type' => $list->type, | ||
114 | + 'poem_id' => $list->poem_id, | ||
115 | + 'temp_id' => $list->temp_id, | ||
116 | + 'bgm' => $list->bgm, | ||
117 | + 'praise' => $list->praise, | ||
118 | + 'view' => $list->view, | ||
119 | + 'collect' => $list->collect, | ||
120 | + 'share' => $list->share, | ||
121 | + 'is_praise' => $list->isPraise($list->id, $user_id), | ||
122 | + 'is_collect' => $list->isCollect($list->id, $user_id), | ||
123 | + ]; | ||
124 | + } | ||
125 | + } | ||
126 | + | ||
127 | + return Response::success($data); | ||
128 | + } | ||
82 | } | 129 | } | ... | ... |
... | @@ -150,4 +150,18 @@ class ImmerseController extends Controller | ... | @@ -150,4 +150,18 @@ class ImmerseController extends Controller |
150 | 150 | ||
151 | else return Response::success(); | 151 | else return Response::success(); |
152 | } | 152 | } |
153 | + | ||
154 | + public function collectList(Request $request) | ||
155 | + { | ||
156 | + $page = $request->get('page',1); | ||
157 | + $page_size = $request->get('page_size',20); | ||
158 | + | ||
159 | + $user = $request->user(); | ||
160 | + | ||
161 | + $data = Collect::query()->where(['user_id' => $user->id, 'state' => 1]) | ||
162 | + ->orderByDesc('created_at') | ||
163 | + ->skip(($page - 1) * $page_size)->take($page_size + 1)->get(); | ||
164 | + | ||
165 | + return Response::success($data); | ||
166 | + } | ||
153 | } | 167 | } | ... | ... |
... | @@ -39,6 +39,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route | ... | @@ -39,6 +39,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route |
39 | /**首页*/ | 39 | /**首页*/ |
40 | $api->apiResource('/home', 'HomeController'); | 40 | $api->apiResource('/home', 'HomeController'); |
41 | 41 | ||
42 | + /**首页"新鲜"*/ | ||
43 | + $api->get('/fresh', 'HomeController@fresh'); | ||
44 | + | ||
42 | /** 图片上传 */ | 45 | /** 图片上传 */ |
43 | $api->post('/upload/image', 'SettingController@uploadImage'); | 46 | $api->post('/upload/image', 'SettingController@uploadImage'); |
44 | 47 | ||
... | @@ -88,6 +91,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc | ... | @@ -88,6 +91,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc |
88 | /** 收藏 */ | 91 | /** 收藏 */ |
89 | $api->post('/collect/{id}', 'ImmerseController@collect'); | 92 | $api->post('/collect/{id}', 'ImmerseController@collect'); |
90 | 93 | ||
94 | + /** 收藏列表 */ | ||
95 | + $api->post('/collect', 'ImmerseController@collectList'); | ||
96 | + | ||
91 | /** 众妙 */ | 97 | /** 众妙 */ |
92 | $api->get('/packpoem', 'HomeController@packpoem'); | 98 | $api->get('/packpoem', 'HomeController@packpoem'); |
93 | 99 | ... | ... |
-
Please register or login to post a comment