From 432e8e9c95ebf90ebfb7cba84b377229fcc42bdd Mon Sep 17 00:00:00 2001 From: d3m0k1d Date: Tue, 25 Nov 2025 07:56:41 +0300 Subject: [PATCH] Add base handler for update(unworked) --- backend/app/api/v1/posts.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/app/api/v1/posts.py b/backend/app/api/v1/posts.py index b594d15..c1921e2 100644 --- a/backend/app/api/v1/posts.py +++ b/backend/app/api/v1/posts.py @@ -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"}