Files
cycle_api/app/Http/Controllers/Follow/FollowController.php
2024-02-26 00:41:25 +08:00

60 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers\Follow;
use App\Exceptions\ModelException;
use App\Http\Controllers\Base\BaseController;
use App\Models\Follow\FollowHistoryModel;
use App\Models\Follow\FollowModel;
use App\Service\AuthService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class FollowController extends BaseController
{
public array $validateMethodParams = [
'addFollow' => [
'uid' => 'required|numeric|max:15',
],
'unFollow' => [
'uid' => 'required|numeric|max:15',
],
];
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ModelException
*/
function addFollow()
{
$oAuthService = new AuthService();
$aUser = $oAuthService->getCurrentUser();
$follow_uid = request()->input('uid');
if($aUser['id'] == $follow_uid) return $this->error('不能关注自己');
$oFollowModel = new FollowModel();
$aFollow = $oFollowModel->isFollow($aUser['id'], $follow_uid);
if($aFollow) return $this->error('已关注');
$oFollowModel->addFollow($aUser['id'], $follow_uid);
return $this->success();
}
function unFollow()
{
$oAuthService = new AuthService();
$aUser = $oAuthService->getCurrentUser();
$follow_uid = request()->input('uid');
$oFollowModel = new FollowModel();
$oFollowModel->unFollow($aUser['id'], $follow_uid);
return $this->success();
}
}