Changed only_ids response (still not final)

This commit is contained in:
Profitroll 2023-01-23 10:36:28 +01:00
parent 30f11a7c83
commit 546600a29e
2 changed files with 13 additions and 4 deletions

View File

@ -3,7 +3,7 @@ from urllib.parse import quote_plus
from os import remove from os import remove
from typing import Dict, List, Literal, Union from typing import Dict, List, Literal, Union
from xmltodict import parse from xmltodict import parse
from models.saves import StardewSave from models.saves import StardewSave, StardewSaveBrief
from modules.app import app, get_api_key, user_by_key from modules.app import app, get_api_key, user_by_key
from modules.database import col_devices, col_saves from modules.database import col_devices, col_saves
from fastapi import HTTPException, Depends, UploadFile from fastapi import HTTPException, Depends, UploadFile
@ -14,7 +14,7 @@ from starlette.status import HTTP_204_NO_CONTENT, HTTP_403_FORBIDDEN, HTTP_404_N
from modules.utils import configGet, zip_saves from modules.utils import configGet, zip_saves
@app.get("/saves", response_class=UJSONResponse, response_model=Union[List[Dict[str, StardewSave]], List[int]], description="Get all available game saves") @app.get("/saves", response_class=UJSONResponse, response_model=Union[List[Dict[str, StardewSave]], List[StardewSaveBrief]], description="Get all available game saves")
async def saves_get(device: Union[str, None] = None, version: Union[str, None] = None, only_ids: bool = False, apikey: APIKey = Depends(get_api_key)): async def saves_get(device: Union[str, None] = None, version: Union[str, None] = None, only_ids: bool = False, apikey: APIKey = Depends(get_api_key)):
user = user_by_key(apikey) user = user_by_key(apikey)
@ -37,7 +37,12 @@ async def saves_get(device: Union[str, None] = None, version: Union[str, None] =
if only_ids is True: if only_ids is True:
for entry in saves_entries: for entry in saves_entries:
if entry["id"] not in output: if entry["id"] not in output:
output.append(entry["id"]) output.append(
{
"id": entry["id"],
"farmer": entry["data"]["farmer"]
}
)
else: else:
for entry in saves_entries: for entry in saves_entries:
out_entry = entry out_entry = entry

View File

@ -14,4 +14,8 @@ class StardewSave(BaseModel):
id: int id: int
device: str device: str
date: int date: int
data: StardewSaveData data: StardewSaveData
class StardewSaveBrief(BaseModel):
id: int
farmer: str