From be28592dfa4f3226d6c89052a36af3ab7135e1f2 Mon Sep 17 00:00:00 2001 From: justinbaer Date: Thu, 26 Jun 2025 09:22:47 +0200 Subject: [PATCH] query changes --- .../controllers/patchnotes_controller.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gen/openapi_server/controllers/patchnotes_controller.py b/gen/openapi_server/controllers/patchnotes_controller.py index 79998ab..fd2caf3 100644 --- a/gen/openapi_server/controllers/patchnotes_controller.py +++ b/gen/openapi_server/controllers/patchnotes_controller.py @@ -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)