Files
cycle_api/app/Http/Controllers/Post/PostController.php
2024-03-03 09:39:06 +08:00

60 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers\Post;
use App\Http\Controllers\Base\BaseController;
use App\Models\Post\PostModel;
use App\Models\Post\PostPushBoxModel;
use App\Service\AuthService;
class PostController extends BaseController
{
//$uid, $content = null, $media = null,$mid = null,$sBachSn = null
public array $validateMethodParams = [
'addPost' => [
'type' => 'required|numeric|max:2',
'content' => 'required|numeric|max:255',
'media' => 'json',
],
'pullPostList' => [
'lastId' => 'numeric|max:10',
'limit' => 'numeric|max:5',
],
];
public function addPost(): \Illuminate\Http\JsonResponse
{
$aParams = request()->only([
'type',
'content',
'media',
]);
if (!in_array($aParams['type'], [PostModel::TYPE_POST, PostModel::TYPE_REPOST])) return $this->error('type params error');
$oAuthService = new AuthService();
$aUser = $oAuthService->getCurrentUser();
$oFollowModel = new PostModel();
$aParams['uid'] = $aUser['id'];
$oFollowModel->addBatchPost([$aParams]);
return $this->success();
}
function pullPostList()
{
$aParams = request()->only([
'lastId',
'limit',
]);
$oAuthService = new AuthService();
$aUser = $oAuthService->getCurrentUser();
$oPostModel = new PostPushBoxModel();
$aPostList = $oPostModel->getPushBoxList($aUser['id'],$aParams['lastId']??0,$aParams['limit']??15);
return $this->success($aPostList);
}
}