chore: refactor

This commit is contained in:
agatha 2024-04-06 14:50:59 -04:00
parent d0e593a268
commit 594c5c6de8
2 changed files with 14 additions and 16 deletions

View File

@ -8,5 +8,5 @@ app = FastAPI()
models.Base.metadata.create_all(bind=engine)
app.include_router(auth.router)
app.include_router(forum.router)
app.include_router(auth.router)

View File

@ -27,11 +27,24 @@ class PostCreate(BaseModel):
content: str = Field('')
@router.get('/catalog', status_code=status.HTTP_200_OK)
async def get_catalog(db: db_dependency):
return db.query(Thread).all()
@router.get('/', status_code=status.HTTP_200_OK)
async def get_posts(db: db_dependency):
return db.query(Post).all()
@router.get('/{thread_id}', status_code=status.HTTP_200_OK)
async def get_thread_by_id(db: db_dependency, thread_id: int = Path(gt=0)):
posts = db.query(Post).filter(Post.thread_id == thread_id).all()
if posts:
return posts
raise HTTPException(404, f'Could not find thread')
@router.post('/', status_code=status.HTTP_201_CREATED)
async def create_thread(db: db_dependency, data: PostCreate):
try:
@ -68,15 +81,6 @@ async def create_thread(db: db_dependency, data: PostCreate):
raise HTTPException(status_code=400, detail=str(e))
@router.get('/{thread_id}', status_code=status.HTTP_200_OK)
async def get_thread_by_id(db: db_dependency, thread_id: int = Path(gt=0)):
posts = db.query(Post).filter(Post.thread_id == thread_id).all()
if posts:
return posts
raise HTTPException(404, f'Could not find thread')
@router.post('/{thread_id}', status_code=status.HTTP_201_CREATED)
async def create_reply(db: db_dependency, data: PostCreate, thread_id: int = Path(gt=0)):
thread = db.query(Thread).filter(Thread.id == thread_id).first()
@ -98,9 +102,3 @@ async def create_reply(db: db_dependency, data: PostCreate, thread_id: int = Pat
}
raise HTTPException(status_code=404, detail='Could not find thread')
@router.get('/catalog', status_code=status.HTTP_200_OK)
async def get_catalog(db: db_dependency):
return db.query(Thread).all()