51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
import logger
|
|
from db.mysql import database
|
|
from model.car.dto.list import ListDto
|
|
from orm.jiakaobaodian import JiaKaoBaoDian
|
|
from utils.common import response, amis_response
|
|
from utils.model import model_list
|
|
|
|
router = APIRouter(tags=["Car"], prefix="/api/car")
|
|
|
|
|
|
@router.post("/list", summary="题目列表")
|
|
def get_list(dto: ListDto, db: Session = Depends(database)):
|
|
(page, size, keyword) = (dto.page, dto.size, dto.keyword)
|
|
order_by_wrong_rate = dto.order_by_wrong_rate
|
|
logger.logger.info("page => {}, size => {}, keyword => {}", page, size, keyword)
|
|
|
|
query = db.query(JiaKaoBaoDian)
|
|
if len(keyword) > 0:
|
|
query = query.filter(
|
|
JiaKaoBaoDian.question.like("%%%s%%" % keyword) |
|
|
JiaKaoBaoDian.illiteracy_explain.like("%%%s%%" % keyword))
|
|
if order_by_wrong_rate:
|
|
query = query.order_by(JiaKaoBaoDian.wrong_rate.desc())
|
|
|
|
total = query.count()
|
|
|
|
offset = (page - 1) * size
|
|
data = query.offset(offset).limit(size).all()
|
|
logger.logger.info("data num {}", len(data))
|
|
return response({
|
|
"data": model_list(data),
|
|
"page": page,
|
|
"size": size,
|
|
"total": total
|
|
})
|
|
|
|
|
|
@router.post("/amis/list", summary="amis 题目列表")
|
|
def amis_get_list(dto: ListDto, db: Session = Depends(database)):
|
|
result = get_list(dto, db)['data']
|
|
|
|
return amis_response({
|
|
"rows": result['data'],
|
|
"page": result['page'],
|
|
"size": result['size'],
|
|
"total": result['total']
|
|
})
|