Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
r-4bb1t committed Feb 15, 2024
2 parents 6615225 + b38cf61 commit bbdec40
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ CREATE TABLE `LUsers` (
PRIMARY KEY (`user_id`)
);

CREATE TABLE `LChapter` (
`chapter_id` INT AUTO_INCREMENT NOT NULL,
`title` VARCHAR(255) NOT NULL,
PRIMARY KEY (`chapter_id`)
);
)

CREATE TABLE `LQuestions` (
`question_id` INT AUTO_INCREMENT NOT NULL,
`is_fixed` BOOL NOT NULL DEFAULT FALSE,
Expand All @@ -16,7 +23,8 @@ CREATE TABLE `LQuestions` (
`content` TEXT NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`question_id`),
FOREIGN KEY (`user_id`) REFERENCES `LUsers`(`user_id`)
FOREIGN KEY (`user_id`) REFERENCES `LUsers`(`user_id`),
FOREIGN kEY (`chapter_id`) REFERENCES `LChapter`(`chapter_id`
);

CREATE TABLE `LAnswers` (
Expand Down
7 changes: 7 additions & 0 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ class LUsers(Base):
created_at = Column(DATETIME(fsp=3), nullable=False, server_default=text("CURRENT_TIMESTAMP(3)"))
kakao_id = Column(BIGINT, nullable=True)

class LChapter(Base):
__tablename__ = 'LChapter'
chapter_id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(String(255), nullable=False)

class LQuestions(Base):
__tablename__ = 'LQuestions'
question_id = Column(Integer, primary_key=True, autoincrement=True)
is_fixed = Column(Boolean, nullable=False, default=False)
chatper_id = Column(Integer, ForeignKey('LChapter.chapter_id', onupdate='Cascade'), nullable=False)
user_id = Column(Integer, ForeignKey('LUsers.user_id', onupdate='Cascade'), nullable=False)
parents_id = Column(Integer, nullable=False)
content = Column(Text, nullable=False)
created_at = Column(DATETIME(fsp=3), nullable=False, server_default=text("CURRENT_TIMESTAMP(3)"))

LUsers = relationship('LUsers')
LChapter = relationship('LChapter')

class LAnswers(Base):
__tablename__ = 'LAnswers'
Expand Down
1 change: 0 additions & 1 deletion src/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from datetime import datetime, timedelta
from fastapi.security import HTTPBearer


from jose import jwt, JWTError

SECRET_KEY = "secretkey"
Expand Down
13 changes: 12 additions & 1 deletion src/routers/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from database import get_db
from models import LQuestions

from auth import get_current_user

router = APIRouter()

@router.get("/")
Expand All @@ -12,4 +14,13 @@ async def get_question(id: int, db: Session = Depends(get_db)):

if question is None:
raise HTTPException(status_code=404, detail="Question not found")
return {'id': question.question_id, 'content': question.content}
return {'id': question.question_id, 'content': question.content}

# 마지막으로 답변한 question_id 가져오기
# request: user_id(access_token, ge
@router.get("/last")
async def get_last_question(user=Depends(get_current_user), db: Session = Depends(get_db)):
question = db.query(LQuestions).filter(LQuestions.user_id == user.user_id).order_by(LQuestions.question_id.desc()).first()
if question is None:
return {'question_id': 1}
return {'question_id': question.question_id, 'content': question.content}

0 comments on commit bbdec40

Please sign in to comment.