query changes

This commit is contained in:
Justin Weins 2025-06-26 09:22:47 +02:00
parent 11087ead17
commit be28592dfa
1 changed files with 10 additions and 5 deletions

View File

@ -124,7 +124,7 @@ def list_patchnotes(since: str | None = None):
"""GET /patchnotes liefert neue Patchnotes und setzt last_login."""
user_id = current_user_id() # 1) aktueller Benutzer
last_login = last_login_collection.find_one({"user_id": user_id},{"last_login"})
if since is None:
try:
docs = collection.find({})
@ -141,6 +141,12 @@ def list_patchnotes(since: str | None = None):
# 3) Datum validieren (nur wenn vorhanden)
if since:
query = {
"patch_date": {
"$gte": last_login,
"$lte": since
}
}
try:
datetime.strptime(since, "%Y-%m-%d")
except ValueError:
@ -149,12 +155,11 @@ def list_patchnotes(since: str | None = None):
detail="since must be YYYY-MM-DD",
status=400,
)
mongo_filter = {"patch_date": {"$gte": since}}
else:
mongo_filter = {} # erster Login → alle Notes
query = {} # erster Login → alle Notes
# 4) Patchnotes abholen
docs = list(collection.find(mongo_filter).sort("patch_date", 1))
docs = list(collection.find(query).sort("patch_date", 1))
for d in docs:
d.pop("_id", None)
if isinstance(d["patch_date"], (datetime, date)):
@ -167,7 +172,7 @@ def list_patchnotes(since: str | None = None):
{"$set": {"last_login": today}},
upsert=True,
)
if since == last_login_collection.find_one({"user_id": user_id},{"last_login"}):
if since == last_login:
return Response(json_util.dumps([]), mimetype="application/json", status=200)
return Response(json_util.dumps(docs), mimetype="application/json", status=200)