2023-10-24 13:34:23 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use frontend\modules\api\models\profile\User;
|
2023-10-25 14:37:29 +03:00
|
|
|
|
use frontend\modules\api\models\tg_bot\forms\TgBotDialogForm;
|
|
|
|
|
use frontend\modules\api\models\tg_bot\UserTgBotToken;
|
2023-10-24 13:34:23 +03:00
|
|
|
|
use frontend\modules\api\services\UserTgBotTokenService;
|
|
|
|
|
use Yii;
|
|
|
|
|
|
|
|
|
|
class UserTgBotController extends ApiController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var UserTgBotTokenService
|
|
|
|
|
*/
|
|
|
|
|
private UserTgBotTokenService $userTgBotTokenService;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
$id,
|
|
|
|
|
$module,
|
|
|
|
|
UserTgBotTokenService $userTgBotTokenService,
|
|
|
|
|
$config = []
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
$this->userTgBotTokenService = $userTgBotTokenService;
|
|
|
|
|
parent::__construct($id, $module, $config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-01 14:59:52 +03:00
|
|
|
|
* @OA\Get(path="/user-tg-bot/get-token",
|
2023-10-24 13:34:23 +03:00
|
|
|
|
* summary="Токен ТГ бота",
|
|
|
|
|
* description="Метод для возвращает токен для ТГ бота",
|
|
|
|
|
* security={
|
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
|
* },
|
2023-10-25 14:37:29 +03:00
|
|
|
|
* tags={"TgBot"},
|
2023-10-24 13:34:23 +03:00
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response=200,
|
|
|
|
|
* description="Возвращает объект токен ТГ бота",
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(ref="#/components/schemas/UserTgBotTokenExample"),
|
|
|
|
|
* ),
|
|
|
|
|
* ),
|
|
|
|
|
* )
|
|
|
|
|
*
|
|
|
|
|
* @return UserTgBotToken
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2023-10-25 14:37:29 +03:00
|
|
|
|
public function actionGetToken(): UserTgBotToken
|
2023-10-24 13:34:23 +03:00
|
|
|
|
{
|
|
|
|
|
return $this->userTgBotTokenService->getToken(Yii::$app->user->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-01 14:59:52 +03:00
|
|
|
|
* @OA\Get(path="/user-tg-bot/get-user",
|
2023-10-24 13:34:23 +03:00
|
|
|
|
* summary="Получить данные пользователя",
|
|
|
|
|
* description="Метод для получения данныех пользователя по токену ТГ бота",
|
|
|
|
|
* security={
|
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
|
* },
|
2023-10-25 14:37:29 +03:00
|
|
|
|
* tags={"TgBot"},
|
2023-10-24 13:34:23 +03:00
|
|
|
|
* @OA\Parameter(
|
|
|
|
|
* name="token",
|
|
|
|
|
* in="query",
|
|
|
|
|
* example="HDAS7J",
|
|
|
|
|
* required=true,
|
|
|
|
|
* description="Токен ТГ бота",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* type="string",
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response=200,
|
|
|
|
|
* description="Возвращает данные пользователя",
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* ),
|
|
|
|
|
* ),
|
|
|
|
|
* )
|
|
|
|
|
*
|
|
|
|
|
* @param string $token
|
|
|
|
|
* @return User|string[]
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function actionGetUser(string $token)
|
|
|
|
|
{
|
|
|
|
|
return $this->userTgBotTokenService->getUserByToken($token);
|
|
|
|
|
}
|
2023-10-25 14:37:29 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-01 14:59:52 +03:00
|
|
|
|
* @OA\Post(path="/user-tg-bot/set-dialog",
|
2023-10-25 14:37:29 +03:00
|
|
|
|
* 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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-01 14:59:52 +03:00
|
|
|
|
* @OA\Get(path="/user-tg-bot/dialog/get-dialog-id",
|
2023-10-25 14:37:29 +03:00
|
|
|
|
* 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
|
|
|
|
|
*/
|
2023-11-01 14:59:52 +03:00
|
|
|
|
public function actionGetDialogId(string $userId): array
|
2023-10-25 14:37:29 +03:00
|
|
|
|
{
|
|
|
|
|
return $this->userTgBotTokenService->getDialogIdByUserId($userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-01 14:59:52 +03:00
|
|
|
|
* @OA\Get(path="/user-tg-bot/get-user-id",
|
2023-10-25 14:37:29 +03:00
|
|
|
|
* 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
|
|
|
|
|
*/
|
2023-11-01 14:59:52 +03:00
|
|
|
|
public function actionGetUserId(string $dialogId): array
|
2023-10-25 14:37:29 +03:00
|
|
|
|
{
|
|
|
|
|
return $this->userTgBotTokenService->getUserIdByDialogId($dialogId);
|
|
|
|
|
}
|
2023-10-24 13:34:23 +03:00
|
|
|
|
}
|