datavorous
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -325,72 +325,6 @@ async def generate_test(
|
|
325 |
|
326 |
return test
|
327 |
|
328 |
-
@app.get("/dpps/{dpp_name}",
|
329 |
-
summary="Get all questions from a specific DPP",
|
330 |
-
tags=["DPPs"],
|
331 |
-
response_description="List of questions from the specified DPP."
|
332 |
-
)
|
333 |
-
@cached(ttl=300, cache=SimpleMemoryCache, serializer=JsonSerializer())
|
334 |
-
async def get_dpp_questions(
|
335 |
-
dpp_name: str = Path(..., description="Name of the DPP file without .db extension"),
|
336 |
-
offset: int = Query(0, ge=0, description="Offset for pagination"),
|
337 |
-
limit: int = Query(1000, ge=1, le=1000, description="Limit for pagination")
|
338 |
-
):
|
339 |
-
"""
|
340 |
-
Get questions from a specific DPP file with pagination support.
|
341 |
-
|
342 |
-
Args:
|
343 |
-
dpp_name: Name of the DPP file (without .db extension)
|
344 |
-
offset: Number of questions to skip
|
345 |
-
limit: Maximum number of questions to return
|
346 |
-
|
347 |
-
Returns:
|
348 |
-
Dictionary containing DPP name and list of questions
|
349 |
-
"""
|
350 |
-
db_path = Path("dpps") / f"{dpp_name}.db"
|
351 |
-
|
352 |
-
if not db_path.exists():
|
353 |
-
raise HTTPException(
|
354 |
-
status_code=404,
|
355 |
-
detail=f"DPP file '{dpp_name}' not found"
|
356 |
-
)
|
357 |
-
|
358 |
-
try:
|
359 |
-
async with aiosqlite.connect(str(db_path)) as db:
|
360 |
-
db.row_factory = aiosqlite.Row
|
361 |
-
|
362 |
-
# First get total count
|
363 |
-
async with db.execute("SELECT COUNT(*) as count FROM selected_questions") as cursor:
|
364 |
-
total_count = (await cursor.fetchone())['count']
|
365 |
-
|
366 |
-
# Then get paginated questions
|
367 |
-
query = "SELECT * FROM selected_questions LIMIT ? OFFSET ?"
|
368 |
-
async with db.execute(query, [limit, offset]) as cursor:
|
369 |
-
questions = await cursor.fetchall()
|
370 |
-
|
371 |
-
if not questions:
|
372 |
-
raise HTTPException(
|
373 |
-
status_code=404,
|
374 |
-
detail=f"No questions found in DPP '{dpp_name}' for the specified page"
|
375 |
-
)
|
376 |
-
|
377 |
-
return {
|
378 |
-
"dpp_name": dpp_name,
|
379 |
-
"total_questions": total_count,
|
380 |
-
"questions": [dict(q) for q in questions],
|
381 |
-
"pagination": {
|
382 |
-
"offset": offset,
|
383 |
-
"limit": limit,
|
384 |
-
"total": total_count
|
385 |
-
}
|
386 |
-
}
|
387 |
-
|
388 |
-
except aiosqlite.Error as e:
|
389 |
-
raise HTTPException(
|
390 |
-
status_code=500,
|
391 |
-
detail=f"Database error occurred while accessing DPP '{dpp_name}': {str(e)}"
|
392 |
-
)
|
393 |
-
|
394 |
# Main application runner
|
395 |
if __name__ == "__main__":
|
396 |
import uvicorn
|
|
|
325 |
|
326 |
return test
|
327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
# Main application runner
|
329 |
if __name__ == "__main__":
|
330 |
import uvicorn
|