1- from typing import Annotated , Any , cast
1+ from typing import Annotated , Any
22
33from fastapi import APIRouter , Depends , Request
44from fastcrud import PaginatedListResponse , compute_offset , paginated_response
@@ -28,8 +28,6 @@ async def write_post(
2828 if db_user is None :
2929 raise NotFoundException ("User not found" )
3030
31- db_user = cast (dict [str , Any ], db_user )
32-
3331 if current_user ["id" ] != db_user ["id" ]:
3432 raise ForbiddenException ()
3533
@@ -46,7 +44,7 @@ async def write_post(
4644 if post_read is None :
4745 raise NotFoundException ("Created post not found" )
4846
49- return cast ( dict [ str , Any ], post_read )
47+ return post_read
5048
5149
5250@router .get ("/{username}/posts" , response_model = PaginatedListResponse [PostRead ])
@@ -66,7 +64,6 @@ async def read_posts(
6664 if not db_user :
6765 raise NotFoundException ("User not found" )
6866
69- db_user = cast (dict [str , Any ], db_user )
7067 posts_data = await crud_posts .get_multi (
7168 db = db ,
7269 offset = compute_offset (page , items_per_page ),
@@ -88,15 +85,13 @@ async def read_post(
8885 if db_user is None :
8986 raise NotFoundException ("User not found" )
9087
91- db_user = cast (dict [str , Any ], db_user )
92-
9388 db_post = await crud_posts .get (
9489 db = db , id = id , created_by_user_id = db_user ["id" ], is_deleted = False , schema_to_select = PostRead
9590 )
9691 if db_post is None :
9792 raise NotFoundException ("Post not found" )
9893
99- return cast ( dict [ str , Any ], db_post )
94+ return db_post
10095
10196
10297@router .patch ("/{username}/post/{id}" )
@@ -113,17 +108,13 @@ async def patch_post(
113108 if db_user is None :
114109 raise NotFoundException ("User not found" )
115110
116- db_user = cast (dict [str , Any ], db_user )
117-
118111 if current_user ["id" ] != db_user ["id" ]:
119112 raise ForbiddenException ()
120113
121114 db_post = await crud_posts .get (db = db , id = id , is_deleted = False , schema_to_select = PostRead )
122115 if db_post is None :
123116 raise NotFoundException ("Post not found" )
124117
125- db_post = cast (dict [str , Any ], db_post )
126-
127118 await crud_posts .update (db = db , object = values , id = id )
128119 return {"message" : "Post updated" }
129120
@@ -141,17 +132,13 @@ async def erase_post(
141132 if db_user is None :
142133 raise NotFoundException ("User not found" )
143134
144- db_user = cast (dict [str , Any ], db_user )
145-
146135 if current_user ["id" ] != db_user ["id" ]:
147136 raise ForbiddenException ()
148137
149138 db_post = await crud_posts .get (db = db , id = id , is_deleted = False , schema_to_select = PostRead )
150139 if db_post is None :
151140 raise NotFoundException ("Post not found" )
152141
153- db_post = cast (dict [str , Any ], db_post )
154-
155142 await crud_posts .delete (db = db , id = id )
156143
157144 return {"message" : "Post deleted" }
@@ -166,13 +153,9 @@ async def erase_db_post(
166153 if db_user is None :
167154 raise NotFoundException ("User not found" )
168155
169- db_user = cast (dict [str , Any ], db_user )
170-
171156 db_post = await crud_posts .get (db = db , id = id , is_deleted = False , schema_to_select = PostRead )
172157 if db_post is None :
173158 raise NotFoundException ("Post not found" )
174159
175- db_post = cast (dict [str , Any ], db_post )
176-
177160 await crud_posts .db_delete (db = db , id = id )
178161 return {"message" : "Post deleted from the database" }
0 commit comments