Skip to content

Commit

Permalink
fix: skip intro
Browse files Browse the repository at this point in the history
  • Loading branch information
r-4bb1t committed Feb 15, 2024
1 parent 369ebd8 commit 811fd07
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/routers/question.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, HTTPException
from fastapi import APIRouter, HTTPException, BackgroundTasks
from fastapi.params import Depends
from sqlalchemy.orm import Session
from database import get_db
Expand Down Expand Up @@ -92,7 +92,7 @@ async def make_followed_question(parent_id: int, db: Session, user_id: int):
}

@router.get("/{id}/skip")
async def skip_question(id: int, user=Depends(get_current_user), db: Session = Depends(get_db)):
async def skip_question(id: int, background_tasks: BackgroundTasks, user=Depends(get_current_user), db: Session = Depends(get_db)):
question = db.query(LQuestions).filter(LQuestions.question_id == id).first()

if question.user_id != user.user_id and question.user_id != -1:
Expand All @@ -105,6 +105,14 @@ async def skip_question(id: int, user=Depends(get_current_user), db: Session = D
user.last_answered_question_id = question.next_question_id
db.commit()

if question.chapter_id != 1:
background_tasks.add_task(add_summary, question, user, db)

return {
'question_id': question.next_question_id
}

def add_summary(question: LQuestions, user: LUsers, db: Session):
contexts = make_context(parent=question, db=db, user_id=user.user_id)
print(contexts)

Expand All @@ -118,11 +126,6 @@ async def skip_question(id: int, user=Depends(get_current_user), db: Session = D
db.add(LSummary(user_id=user.user_id, question_id=root.question_id, content=contents[1]['text'], chapter_id=question.chapter_id))
db.commit()

return {
'question_id': question.next_question_id
}


def make_context(parent: LQuestions, db: Session, user_id: int):
context = []
p = parent
Expand Down

0 comments on commit 811fd07

Please sign in to comment.