Changed only_ids behavior + sorting added
This commit is contained in:
parent
546600a29e
commit
1294d1a037
@ -3,6 +3,7 @@ from urllib.parse import quote_plus
|
||||
from os import remove
|
||||
from typing import Dict, List, Literal, Union
|
||||
from xmltodict import parse
|
||||
from pymongo import DESCENDING
|
||||
from models.saves import StardewSave, StardewSaveBrief
|
||||
from modules.app import app, get_api_key, user_by_key
|
||||
from modules.database import col_devices, col_saves
|
||||
@ -27,28 +28,24 @@ async def saves_get(device: Union[str, None] = None, version: Union[str, None] =
|
||||
if version is not None:
|
||||
query["data.game_version"] = version
|
||||
|
||||
saves_entries = list(col_saves.find(query))
|
||||
saves_entries = list(col_saves.find(query).sort("date", DESCENDING))
|
||||
|
||||
if len(saves_entries) == 0:
|
||||
raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find any saves.")
|
||||
|
||||
output = []
|
||||
added = []
|
||||
|
||||
if only_ids is True:
|
||||
for entry in saves_entries:
|
||||
if entry["id"] not in output:
|
||||
output.append(
|
||||
{
|
||||
"id": entry["id"],
|
||||
"farmer": entry["data"]["farmer"]
|
||||
}
|
||||
)
|
||||
else:
|
||||
for entry in saves_entries:
|
||||
out_entry = entry
|
||||
del out_entry["_id"]
|
||||
del out_entry["user"]
|
||||
del out_entry["file"]
|
||||
if only_ids is True:
|
||||
if entry["id"] in added:
|
||||
continue
|
||||
else:
|
||||
added.append(entry["id"])
|
||||
output.append(out_entry)
|
||||
|
||||
return UJSONResponse(output)
|
||||
@ -65,7 +62,7 @@ async def saves_get_by_id(id: int, device: Union[str, None] = None, version: Uni
|
||||
if version is not None:
|
||||
query["data.game_version"] = version
|
||||
|
||||
saves_entries = list(col_saves.find(query))
|
||||
saves_entries = list(col_saves.find(query).sort("date", DESCENDING))
|
||||
|
||||
if len(saves_entries) == 0:
|
||||
raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find save with such id.")
|
||||
|
Loading…
Reference in New Issue
Block a user