From 8cf0bf821aa1f2ef572d0fd4223c14fcf1049db2 Mon Sep 17 00:00:00 2001 From: pengtao Date: Fri, 17 Dec 2021 14:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0gamelist=20=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 9662203..e6e9dd7 100644 --- a/main.py +++ b/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,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,