Skip to content

Commit

Permalink
chore: fix typo in create_tables.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkweon17 committed Nov 10, 2023
1 parent e162947 commit efdf482
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

#from routers import auth
from routers import test

app = FastAPI()

# 라우터 등록
# app.include_router(auth.router)
app.include_router(test.router)

# CORS 설정
origins = [
Expand Down
36 changes: 24 additions & 12 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ class HKUser(Base):
created_at = Column(DateTime, nullable=False)
github_id = Column(String(255), nullable=False)
blog_link = Column(String(255), nullable=False)

reviews = relationship('HKReview', back_populates='user')
bookmarks = relationship('HKBookmark', back_populates='user')
boards = relationship('HKBoard', back_populates='user')
user_stacks = relationship('HKUserStack', back_populates='user')

class HKCompany(Base):
__tablename__ = 'HKCompany'
company_id = Column(Integer, primary_key=True, autoincrement=True)
company_name = Column(String(255), nullable=False)

lectures = relationship('HKLecture', back_populates='company')

class HKLecture(Base):
__tablename__ = 'HKLecture'
lecture_id = Column(Integer, primary_key=True, autoincrement=True)
Expand All @@ -30,9 +37,15 @@ class HKLecture(Base):
difficulty = Column(String(255), nullable=True)
company_id = Column(Integer, ForeignKey('HKCompany.company_id'), nullable=False)
price = Column(String(255), nullable=True)
discount_rate = Column(String(255), nullable=True)
discount_price = Column(String(255), nullable=True)
introduction = Column(Text, nullable=True)
keyword = Column(String(255), nullable=True)
link = Column(String(255), nullable=True)

company = relationship('HKCompany', back_populates='lectures')
lecture_stacks = relationship('HKLectureStack', back_populates='lecture')
reviews = relationship('HKReview', back_populates='lecture')
bookmarks = relationship('HKBookmark', back_populates='lecture')

class HKReview(Base):
__tablename__ = 'HKReview'
Expand All @@ -44,6 +57,7 @@ class HKReview(Base):
bad_review = Column(Text, nullable=False)
is_active = Column(Boolean, nullable=False, default=True)
created_at = Column(DateTime, nullable=False)

lecture = relationship('HKLecture', back_populates='reviews')
user = relationship('HKUser', back_populates='reviews')

Expand All @@ -52,21 +66,26 @@ class HKBookmark(Base):
bookmark_id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer, ForeignKey('HKUser.user_id'), nullable=False)
lecture_id = Column(Integer, ForeignKey('HKLecture.lecture_id'), nullable=False)

user = relationship('HKUser', back_populates='bookmarks')
lecture = relationship('HKLecture', back_populates='bookmarks')

class HKStackCategory(Base):
__tablename__ = 'HKStackCategory'
stack_category_id = Column(Integer, primary_key=True, autoincrement=True)
parent_id = Column(Integer, ForeignKey('HKStackCategory.stack_category_id'), nullable=True)
stack_name = Column(Integer, nullable=False)
stack_name = Column(String(255), nullable=False)

parent = relationship('HKStackCategory', remote_side=[stack_category_id])
lecture_stacks = relationship('HKLectureStack', back_populates='stack_category')
user_stacks = relationship('HKUserStack', back_populates='stack_category')

class HKLectureStack(Base):
__tablename__ = 'HKLectureStack'
lecture_stack_id = Column(Integer, primary_key=True, autoincrement=True)
stack_category_id = Column(Integer, ForeignKey('HKStackCategory.stack_category_id'), nullable=False)
lecture_id = Column(Integer, ForeignKey('HKLecture.lecture_id'), nullable=False)

stack_category = relationship('HKStackCategory', back_populates='lecture_stacks')
lecture = relationship('HKLecture', back_populates='lecture_stacks')

Expand All @@ -75,6 +94,7 @@ class HKUserStack(Base):
user_stack_id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer, ForeignKey('HKUser.user_id'), nullable=False)
stack_category_id = Column(Integer, ForeignKey('HKStackCategory.stack_category_id'), nullable=False)

user = relationship('HKUser', back_populates='user_stacks')
stack_category = relationship('HKStackCategory', back_populates='user_stacks')

Expand All @@ -86,13 +106,5 @@ class HKBoard(Base):
created_at = Column(DateTime, nullable=False)
is_active = Column(Boolean, nullable=False, default=True)
content = Column(Text, nullable=False)
user = relationship('HKUser', back_populates='boards')

# Set up relationships
HKCompany.lectures = relationship('HKLecture', back_populates='company')
HKLecture.reviews = relationship('HKReview', back_populates='lecture')
HKUser.reviews = relationship('HKReview', back_populates='user')
HKUser.bookmarks = relationship('HKBookmark', back_populates='user')
HKStackCategory.lecture_stacks = relationship('HKLectureStack', back_populates='stack_category')
HKStackCategory.user_stacks = relationship('HKUserStack', back_populates='stack_category')
HKUser.boards = relationship('HKBoard', back_populates='user')

user = relationship('HKUser', back_populates='boards')
7 changes: 2 additions & 5 deletions app/routers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
from database import get_db
from models import HKUser

router = APIRouter()

router = APIRouter(previx="/test", tags=["test"], responses={404: {"description": "Not found"}})
router = APIRouter(prefix="/test", tags=["test"], responses={404: {"description": "Not found"}})

# test 핸들러
@router.get("/")
async def get_users(db: Session = Depends(get_db)):
users = db.query(HKUser).all()
# return users
return {"message": "users"}
return users
6 changes: 5 additions & 1 deletion create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
CREATE TABLE `HKUser` (
`user_id` INT AUTO_INCREMENT NOT NULL,
`user_name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`is_active` BOOL NOT NULL DEFAULT TRUE,
`created_at` DATETIME NOT NULL,
Expand All @@ -26,8 +28,10 @@ CREATE TABLE `HKLecture` (
`difficulty` VARCHAR(255) NULL,
`company_id` INT NOT NULL,
`price` VARCHAR(255) NULL,
`discount_rate` VARCHAR(255) NULL,
`discount_price` VARCHAR(255) NULL,
`introduction` TEXT NULL,
`keyword` VARCHAR(255) NULL,
`link` VARCHAR(255) NULL,
PRIMARY KEY (`lecture_id`),
FOREIGN KEY (`company_id`) REFERENCES `HKCompany` (`company_id`) ON UPDATE CASCADE
);
Expand Down

0 comments on commit efdf482

Please sign in to comment.