working search
This commit is contained in:
parent
aeff5f8260
commit
aa200e4aa6
21
main.py
21
main.py
|
@ -62,11 +62,22 @@ def search_tasks(query: str):
|
||||||
# Vikunja does not expose a /tasks/search endpoint in the public API.
|
# Vikunja does not expose a /tasks/search endpoint in the public API.
|
||||||
# Fetch all tasks and filter client-side by title/description.
|
# Fetch all tasks and filter client-side by title/description.
|
||||||
logger.info("search_tasks: fetching all tasks from %s", f"{VIKUNJA_URL}/api/v1/tasks/all")
|
logger.info("search_tasks: fetching all tasks from %s", f"{VIKUNJA_URL}/api/v1/tasks/all")
|
||||||
response = session.get(f"{VIKUNJA_URL}/api/v1/tasks/all")
|
|
||||||
response.raise_for_status()
|
all_tasks = []
|
||||||
data = response.json()
|
page = 1
|
||||||
# The API might return a list or an object with a 'tasks' key
|
per_page = 50
|
||||||
tasks = data if isinstance(data, list) else data.get("tasks", [])
|
|
||||||
|
while True:
|
||||||
|
response = session.get(f"{VIKUNJA_URL}/api/v1/tasks/all?page={page}&limit={per_page}")
|
||||||
|
response.raise_for_status()
|
||||||
|
data = response.json()
|
||||||
|
tasks = data if isinstance(data, list) else data.get("tasks", [])
|
||||||
|
if not tasks:
|
||||||
|
break
|
||||||
|
all_tasks.extend(tasks)
|
||||||
|
page += 1
|
||||||
|
|
||||||
|
tasks = all_tasks
|
||||||
|
|
||||||
q = (query or "").strip()
|
q = (query or "").strip()
|
||||||
logger.info("search_tasks: raw query='%s'", q)
|
logger.info("search_tasks: raw query='%s'", q)
|
||||||
|
|
Loading…
Reference in New Issue