chore: refactor
This commit is contained in:
parent
d0e593a268
commit
594c5c6de8
@ -8,5 +8,5 @@ app = FastAPI()
|
|||||||
|
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
app.include_router(auth.router)
|
|
||||||
app.include_router(forum.router)
|
app.include_router(forum.router)
|
||||||
|
app.include_router(auth.router)
|
||||||
|
@ -27,11 +27,24 @@ class PostCreate(BaseModel):
|
|||||||
content: str = Field('')
|
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)
|
@router.get('/', status_code=status.HTTP_200_OK)
|
||||||
async def get_posts(db: db_dependency):
|
async def get_posts(db: db_dependency):
|
||||||
return db.query(Post).all()
|
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)
|
@router.post('/', status_code=status.HTTP_201_CREATED)
|
||||||
async def create_thread(db: db_dependency, data: PostCreate):
|
async def create_thread(db: db_dependency, data: PostCreate):
|
||||||
try:
|
try:
|
||||||
@ -68,15 +81,6 @@ async def create_thread(db: db_dependency, data: PostCreate):
|
|||||||
raise HTTPException(status_code=400, detail=str(e))
|
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)
|
@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)):
|
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()
|
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')
|
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()
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user