add Telegram bot id dialogs table and API methods
This commit is contained in:
@ -4,8 +4,8 @@
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\User;
|
||||
use frontend\modules\api\models\profile\ProfileChangeEmailForm;
|
||||
use frontend\modules\api\models\profile\ProfileChangePersonalDataForm;
|
||||
use frontend\modules\api\models\profile\forms\ProfileChangeEmailForm;
|
||||
use frontend\modules\api\models\profile\forms\ProfileChangePersonalDataForm;
|
||||
use frontend\modules\api\services\UserService;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
@ -5,27 +5,13 @@ namespace frontend\modules\api\controllers;
|
||||
|
||||
use Exception;
|
||||
use frontend\modules\api\models\profile\User;
|
||||
use frontend\modules\api\models\UserTgBotToken;
|
||||
use frontend\modules\api\models\tg_bot\forms\TgBotDialogForm;
|
||||
use frontend\modules\api\models\tg_bot\UserTgBotToken;
|
||||
use frontend\modules\api\services\UserTgBotTokenService;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class UserTgBotController extends ApiController
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
|
||||
'verbs' => [
|
||||
'class' => \yii\filters\VerbFilter::class,
|
||||
'actions' => [
|
||||
'get-token' => ['get'],
|
||||
'get-user-by-token' => ['get'],
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var UserTgBotTokenService
|
||||
*/
|
||||
@ -43,13 +29,13 @@ class UserTgBotController extends ApiController
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(path="/user-tg-bot/get-token",
|
||||
* @OA\Get(path="/tg-bot/token",
|
||||
* summary="Токен ТГ бота",
|
||||
* description="Метод для возвращает токен для ТГ бота",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"UserTgBotToken"},
|
||||
* tags={"TgBot"},
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает объект токен ТГ бота",
|
||||
@ -63,20 +49,20 @@ class UserTgBotController extends ApiController
|
||||
* @return UserTgBotToken
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionGetToken()
|
||||
public function actionGetToken(): UserTgBotToken
|
||||
{
|
||||
return $this->userTgBotTokenService->getToken(Yii::$app->user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Get(path="/user-tg-bot/get-user",
|
||||
* @OA\Get(path="/tg-bot/user",
|
||||
* summary="Получить данные пользователя",
|
||||
* description="Метод для получения данныех пользователя по токену ТГ бота",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"UserTgBotToken"},
|
||||
* tags={"TgBot"},
|
||||
* @OA\Parameter(
|
||||
* name="token",
|
||||
* in="query",
|
||||
@ -104,4 +90,124 @@ class UserTgBotController extends ApiController
|
||||
{
|
||||
return $this->userTgBotTokenService->getUserByToken($token);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Post(path="/tg-bot/dialog/create",
|
||||
* summary="Сохранить новый id диалога",
|
||||
* description="Метод создает новую запись с id пользователя и id диалога",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"TgBot"},
|
||||
* @OA\Parameter(
|
||||
* name="userId",
|
||||
* in="query",
|
||||
* example="1",
|
||||
* required=true,
|
||||
* description="id пользователя",
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* )
|
||||
* ),
|
||||
* @OA\Parameter(
|
||||
* name="dialogId",
|
||||
* in="query",
|
||||
* example="2355",
|
||||
* required=true,
|
||||
* description="id диалога",
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает сообщение об успехе",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @return TgBotDialogForm|string[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionSetDialog()
|
||||
{
|
||||
return $this->userTgBotTokenService->createDialog(Yii::$app->request->post());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Get(path="/tg-bot/dialog/dialog/id",
|
||||
* summary="Получить id диалога по id пользователя",
|
||||
* description="Метод для получения id пользователя по id пользователя",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"TgBot"},
|
||||
* @OA\Parameter(
|
||||
* name="userId",
|
||||
* in="query",
|
||||
* example="1",
|
||||
* required=true,
|
||||
* description="id пользователя",
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает dialog_id",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @param string $userId
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionGetDialogIdByUserId(string $userId): array
|
||||
{
|
||||
return $this->userTgBotTokenService->getDialogIdByUserId($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Get(path="/tg-bot/dialog/user/id",
|
||||
* summary="Получить id пользователя по id диалога",
|
||||
* description="Метод для получения id пользователя по id диалога",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"TgBot"},
|
||||
* @OA\Parameter(
|
||||
* name="dialogId",
|
||||
* in="query",
|
||||
* example="225",
|
||||
* required=true,
|
||||
* description="id диалога",
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает user_id",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @param string $dialogId
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionGetUserIdByDialogId(string $dialogId): array
|
||||
{
|
||||
return $this->userTgBotTokenService->getUserIdByDialogId($dialogId);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user