添加gamelist 排序字段
This commit is contained in:
parent
8276f0bde3
commit
8cf0bf821a
31
main.py
31
main.py
@ -25,6 +25,8 @@ tags_metadata = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
orderby_list = {1: "pubDate", 2: "discountLeftTime", 3: "isLowest"}
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
# application = FastAPI(dependencies=[Depends(get_token_header)],
|
# application = FastAPI(dependencies=[Depends(get_token_header)],
|
||||||
@ -72,17 +74,16 @@ async def getPlatform(request: Request, platformAlias: str):
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/getgamelist")
|
@app.get("/getgamelist")
|
||||||
async def getgamelist(
|
async def getgamelist(request: Request,
|
||||||
request: Request,
|
category: str = '',
|
||||||
category: str = '',
|
name: str = '',
|
||||||
name: str = '',
|
gameids: str = "",
|
||||||
gameids: str = "",
|
cutoff: bool = False,
|
||||||
cutoff: bool = False,
|
isLowest: bool = False,
|
||||||
isLowest: bool = False,
|
platform: int = 1,
|
||||||
platform: int = 1,
|
skip: int = 0,
|
||||||
skip: int = 0,
|
limit: int = 10,
|
||||||
limit: int = 10,
|
orderbyid: int = 1):
|
||||||
):
|
|
||||||
db = request.app.state.mongo
|
db = request.app.state.mongo
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -114,6 +115,12 @@ async def getgamelist(
|
|||||||
content=str(e),
|
content=str(e),
|
||||||
)
|
)
|
||||||
find_args["platform"] = platform
|
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(
|
gamelist = db["gameinfo"].find(
|
||||||
find_args, {
|
find_args, {
|
||||||
"_id": 0,
|
"_id": 0,
|
||||||
@ -132,7 +139,7 @@ async def getgamelist(
|
|||||||
"mcScore": 1,
|
"mcScore": 1,
|
||||||
"priceCountry": 1,
|
"priceCountry": 1,
|
||||||
"subName": 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}!")
|
logger.info(f"get gamelist with {find_args}!")
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=starlette.status.HTTP_200_OK,
|
status_code=starlette.status.HTTP_200_OK,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user