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.
 | 
			
		||||
        # 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")
 | 
			
		||||
        response = session.get(f"{VIKUNJA_URL}/api/v1/tasks/all")
 | 
			
		||||
        response.raise_for_status()
 | 
			
		||||
        data = response.json()
 | 
			
		||||
        # The API might return a list or an object with a 'tasks' key
 | 
			
		||||
        tasks = data if isinstance(data, list) else data.get("tasks", [])
 | 
			
		||||
        
 | 
			
		||||
        all_tasks = []
 | 
			
		||||
        page = 1
 | 
			
		||||
        per_page = 50 
 | 
			
		||||
        
 | 
			
		||||
        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()
 | 
			
		||||
        logger.info("search_tasks: raw query='%s'", q)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue