Skip to content

Commit

Permalink
fix: summary bug
Browse files Browse the repository at this point in the history
  • Loading branch information
r-4bb1t committed Feb 15, 2024
1 parent c420bb6 commit 369ebd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/routers/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ async def skip_question(id: int, user=Depends(get_current_user), db: Session = D

contexts = make_context(parent=question, db=db, user_id=user.user_id)
print(contexts)

root = question
while root.parents_id != -1:
root = db.query(LQuestions).filter(LQuestions.question_id == root.parents_id).first()

if (len(contexts) > 0):
contents = generate_summary(contexts)
print(contents)
db.add(LSummary(user_id=user.user_id, question_id=id, content=contents[1]['text'], chapter_id=question.chapter_id))
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 {
Expand Down
23 changes: 20 additions & 3 deletions src/routers/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@
from routers.auth import get_current_user

from database import get_db
from models import LSummary
from models import LSummary, LChapter, LQuestions

router = APIRouter(responses={404: {"description": "Not found"}})

@router.get("", summary="모든 요약본 가져오기")
async def get_chapters(user=Depends(get_current_user), db: Session = Depends(get_db)):
result = db.query(LSummary).all()
print(result)
summary_list = db.query(LSummary).filter(LSummary.user_id == user.user_id).all()
result = []
chapters = db.query(LChapter).all()
for chapter in chapters:
summary = list(filter(lambda x: x.chapter_id == chapter.chapter_id, summary_list))
if summary:
summaries = []
for s in summary:
summaries.append({
"summary_id": s.summary_id,
"question": db.query(LQuestions).filter(LQuestions.question_id == s.question_id).first().content,
"content": s.content,
})
result.append({
"chapter_id": chapter.chapter_id,
"chapter_title": chapter.title,
"summaries": summaries
})
result = list(filter(lambda x: x["summaries"], result))
return result

0 comments on commit 369ebd8

Please sign in to comment.