58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
from fastapi import APIRouter, Body, Depends, Form, Request
|
|
from module_admin.service.login_service import LoginService
|
|
from module_admin.entity.vo.test_vo import TestUserName, TestPostForm, TestUserNamePage
|
|
from typing import List, Optional
|
|
from module_admin.service.test_service import TestService
|
|
from config.get_db import get_db
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from module_admin.annotation.log_annotation import Log
|
|
from config.enums import BusinessType, RedisInitKeyConfig
|
|
from utils.response_util import ResponseUtil
|
|
from utils.log_util import logger
|
|
|
|
|
|
testController = APIRouter(prefix='/test')
|
|
|
|
@testController.get('/hello', response_model= List[TestUserName]
|
|
# ,dependencies=[Depends(LoginService.get_current_user)]
|
|
)
|
|
async def hello(request: Request,
|
|
name: Optional[str] = None,
|
|
|
|
query_db: AsyncSession = Depends(get_db), ):
|
|
print("名称", name)
|
|
user_name = await TestService.get_user_name(query_db,)
|
|
return user_name
|
|
|
|
@testController.post('/hello_post_json', response_model=str
|
|
,dependencies=[Depends(LoginService.get_current_user)]
|
|
)
|
|
@Log(title='测试Log', business_type=BusinessType.OTHER, log_type='operation')
|
|
async def hello_post_json(
|
|
request: Request,
|
|
login_info: TestUserNamePage,
|
|
query_db: AsyncSession = Depends(get_db)
|
|
|
|
):
|
|
print(login_info.user_name)
|
|
print(login_info.page_num)
|
|
print(login_info.page_size)
|
|
# print(login_info.password)
|
|
|
|
user_name = await TestService.get_user_name(query_db, login_info)
|
|
|
|
logger.info("测试成功")
|
|
|
|
return ResponseUtil.success(model_content=user_name)
|
|
|
|
@Log(title='测试post_form_data', business_type=BusinessType.OTHER, log_type='post')
|
|
@testController.post('/hello_post_form_data', response_model=str)
|
|
async def hello_post_form_data(
|
|
request: Request,
|
|
user_name: Optional[str] = Form(),
|
|
password: Optional[str] = Form()
|
|
):
|
|
print("*"*100)
|
|
print(user_name)
|
|
print(password)
|
|
return "success" |