Add base handler for update(unworked)

This commit is contained in:
d3m0k1d
2025-11-25 07:56:41 +03:00
parent 73c626eada
commit 432e8e9c95

View File

@@ -63,13 +63,26 @@ async def create_post(
@router.put("/{id}")
async def update_post(id: int, db: AsyncSession = Depends(get_async_session)):
pass
async def update_post(
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}")
async def delete_post(id: int, db: AsyncSession = Depends(get_async_session)):
stmt = delete(Post).where(Post.id == id)
await db.execute(stmt)
s = delete(Post).where(Post.id == id)
await db.execute(s)
await db.commit()
return {"message": f"Post with id {id} deleted"}
return {"message": "Post deleted"}