添加gamelist 排序字段

This commit is contained in:
pengtao 2021-12-17 14:15:45 +08:00
parent 8276f0bde3
commit 8cf0bf821a

31
main.py
View File

@ -25,6 +25,8 @@ tags_metadata = [
},
]
orderby_list = {1: "pubDate", 2: "discountLeftTime", 3: "isLowest"}
def create_app():
# application = FastAPI(dependencies=[Depends(get_token_header)],
@ -72,17 +74,16 @@ async def getPlatform(request: Request, platformAlias: str):
@app.get("/getgamelist")
async def getgamelist(
request: Request,
category: str = '',
name: str = '',
gameids: str = "",
cutoff: bool = False,
isLowest: bool = False,
platform: int = 1,
skip: int = 0,
limit: int = 10,
):
async def getgamelist(request: Request,
category: str = '',
name: str = '',
gameids: str = "",
cutoff: bool = False,
isLowest: bool = False,
platform: int = 1,
skip: int = 0,
limit: int = 10,
orderbyid: int = 1):
db = request.app.state.mongo
try:
@ -114,6 +115,12 @@ async def getgamelist(
content=str(e),
)
find_args["platform"] = platform
if orderbyid not in orderby_list.keys():
return JSONResponse(
status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR,
content="orderbyid not define!",
)
gamelist = db["gameinfo"].find(
find_args, {
"_id": 0,
@ -132,7 +139,7 @@ async def getgamelist(
"mcScore": 1,
"priceCountry": 1,
"subName": 1
}).sort("_id").skip(skip).limit(limit)
}).sort(orderby_list[orderbyid], -1).skip(skip).limit(limit)
logger.info(f"get gamelist with {find_args}!")
return JSONResponse(
status_code=starlette.status.HTTP_200_OK,