添加gamelist 排序字段
This commit is contained in:
parent
8276f0bde3
commit
8cf0bf821a
15
main.py
15
main.py
@ -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,8 +74,7 @@ async def getPlatform(request: Request, platformAlias: str):
|
||||
|
||||
|
||||
@app.get("/getgamelist")
|
||||
async def getgamelist(
|
||||
request: Request,
|
||||
async def getgamelist(request: Request,
|
||||
category: str = '',
|
||||
name: str = '',
|
||||
gameids: str = "",
|
||||
@ -82,7 +83,7 @@ async def getgamelist(
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user