matsuap commited on
Commit
5a41f5d
·
verified ·
1 Parent(s): b582880

Upload workbook_server.py

Browse files
Files changed (1) hide show
  1. workbook_server.py +11 -3
workbook_server.py CHANGED
@@ -33,15 +33,23 @@ def get_chapters():
33
  class ChapterRequest(BaseModel):
34
  chapter_number: int
35
 
36
- @app.post('/api/chapter/questions')
37
  def get_questions_by_chapter(request: ChapterRequest):
38
  db = get_db()
39
  cursor = db.cursor()
40
- cursor.execute("SELECT question_id, question_text FROM questions WHERE chapter_number = ?", (request.chapter_number,))
41
  questions = cursor.fetchall()
42
  if not questions:
43
  raise HTTPException(status_code=404, detail="Questions not found for the given chapter number")
44
- question_list = [{"question_id": row[0], "question_text": row[1]} for row in questions]
 
 
 
 
 
 
 
 
45
  return JSONResponse(content=question_list)
46
 
47
  if __name__ == '__main__':
 
33
  class ChapterRequest(BaseModel):
34
  chapter_number: int
35
 
36
+ @app.post('/api/questions')
37
  def get_questions_by_chapter(request: ChapterRequest):
38
  db = get_db()
39
  cursor = db.cursor()
40
+ cursor.execute("SELECT question, options, answer, explain, '正誤判定' as kind FROM question WHERE chapter = ?", (request.chapter_number,))
41
  questions = cursor.fetchall()
42
  if not questions:
43
  raise HTTPException(status_code=404, detail="Questions not found for the given chapter number")
44
+ question_list = [
45
+ {
46
+ "question_text": row[0],
47
+ "options": row[1],
48
+ "kind": row[2],
49
+ "answer": row[3],
50
+ "explanation": row[4]
51
+ } for row in questions
52
+ ]
53
  return JSONResponse(content=question_list)
54
 
55
  if __name__ == '__main__':