Add base handler for update(unworked)
This commit is contained in:
@@ -63,13 +63,26 @@ async def create_post(
|
|||||||
|
|
||||||
|
|
||||||
@router.put("/{id}")
|
@router.put("/{id}")
|
||||||
async def update_post(id: int, db: AsyncSession = Depends(get_async_session)):
|
async def update_post(
|
||||||
pass
|
id: int,
|
||||||
|
db: AsyncSession = Depends(get_async_session),
|
||||||
|
title: Optional[str] = None,
|
||||||
|
content: Optional[str] = None,
|
||||||
|
images: Optional[str] = None,
|
||||||
|
):
|
||||||
|
s = select(Post).where(Post.id == id)
|
||||||
|
result = await db.execute(s)
|
||||||
|
post = result.scalars().first()
|
||||||
|
|
||||||
|
if post is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Post not found")
|
||||||
|
await db.commit()
|
||||||
|
return post
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{id}")
|
@router.delete("/{id}")
|
||||||
async def delete_post(id: int, db: AsyncSession = Depends(get_async_session)):
|
async def delete_post(id: int, db: AsyncSession = Depends(get_async_session)):
|
||||||
stmt = delete(Post).where(Post.id == id)
|
s = delete(Post).where(Post.id == id)
|
||||||
await db.execute(stmt)
|
await db.execute(s)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
return {"message": f"Post with id {id} deleted"}
|
return {"message": "Post deleted"}
|
||||||
|
|||||||
Reference in New Issue
Block a user