99
1010
1111async def initdb ():
12+ """Run the init.sql script for creating tables for tsuki"""
1213 connection = await psycopg .AsyncConnection .connect (
1314 secrets .POSTGRES_URI , autocommit = True
1415 )
@@ -22,6 +23,7 @@ async def initdb():
2223# TODO:
2324# Use Redis for storing shortened URLs for 48 hours.
2425async def create_short_url (token : Any , _id : str ) -> bool :
26+ """Shortened token URL for verifying a user"""
2527 connection = await psycopg .AsyncConnection .connect (
2628 secrets .POSTGRES_URI , autocommit = True
2729 )
@@ -37,6 +39,7 @@ async def create_short_url(token: Any, _id: str) -> bool:
3739
3840
3941async def read_short_url (_id : str ) -> str | None :
42+ """Fetch the shortened URL"""
4043 connection = await psycopg .AsyncConnection .connect (
4144 secrets .POSTGRES_URI , autocommit = True
4245 )
@@ -100,6 +103,7 @@ async def read_user(username: str) -> User | None:
100103
101104
102105async def read_users (username : str , limit : int = 10 ) -> List [User ]:
106+ """Read multiple users at the same time, default limit 10"""
103107 connection = await psycopg .AsyncConnection .connect (
104108 secrets .POSTGRES_URI , autocommit = True
105109 )
@@ -129,6 +133,7 @@ async def read_users(username: str, limit: int = 10) -> List[User]:
129133
130134
131135async def update_user (username : str , updates : Mapping [str , Any ]) -> bool :
136+ """Update user profile information"""
132137 connection = await psycopg .AsyncConnection .connect (
133138 secrets .POSTGRES_URI , autocommit = True
134139 )
@@ -166,6 +171,7 @@ async def delete_user(username: str) -> bool:
166171
167172
168173async def read_avatar (username : str ) -> str | None :
174+ """Fetch user avatar URL for displaying on user profile"""
169175 connection = await psycopg .AsyncConnection .connect (
170176 secrets .POSTGRES_URI , autocommit = True
171177 )
@@ -182,6 +188,7 @@ async def read_avatar(username: str) -> str | None:
182188
183189
184190async def update_avatar (username : str , url : str ) -> bool :
191+ """Update user avatar URL"""
185192 connection = await psycopg .AsyncConnection .connect (
186193 secrets .POSTGRES_URI , autocommit = True
187194 )
@@ -236,6 +243,7 @@ async def read_post(_id: str) -> PostResponse | None:
236243
237244
238245async def read_post_count (username : str ) -> int :
246+ """Fetch the total number of posts made by a user"""
239247 connection = await psycopg .AsyncConnection .connect (
240248 secrets .POSTGRES_URI , autocommit = True
241249 )
@@ -252,6 +260,7 @@ async def read_post_count(username: str) -> int:
252260
253261
254262async def read_recent_posts (username : str , limit : int = 5 ) -> List [PostResponse ]:
263+ """Get data of recent posts made by a user for showing on user profile"""
255264 connection = await psycopg .AsyncConnection .connect (
256265 secrets .POSTGRES_URI , autocommit = True
257266 )
@@ -279,6 +288,7 @@ async def read_recent_posts(username: str, limit: int = 5) -> List[PostResponse]
279288
280289
281290async def read_feed_posts (username : str , limit : int = 10 ) -> List [PostResponse ]:
291+ """Read posts of users followed by the current user, ordered by most recent"""
282292 connection = await psycopg .AsyncConnection .connect (
283293 secrets .POSTGRES_URI , autocommit = True
284294 )
@@ -307,6 +317,7 @@ async def read_feed_posts(username: str, limit: int = 10) -> List[PostResponse]:
307317
308318
309319async def read_explore_posts (username : str ) -> List [Tuple [str , ...]]:
320+ """Fetch recent 1000 posts"""
310321 connection = await psycopg .AsyncConnection .connect (
311322 secrets .POSTGRES_URI , autocommit = True
312323 )
@@ -327,6 +338,7 @@ async def read_explore_posts(username: str) -> List[Tuple[str, ...]]:
327338
328339
329340async def read_liked_posts (username : str ) -> List [Tuple [str , ...]]:
341+ """Fetch last 100 posts liked by a user"""
330342 connection = await psycopg .AsyncConnection .connect (
331343 secrets .POSTGRES_URI , autocommit = True
332344 )
@@ -381,6 +393,7 @@ async def toggle_follow(username: str, to_toggle: str):
381393
382394
383395async def follows (username : str , following : str ) -> bool | None :
396+ """Check if a user follows another user"""
384397 if username == following :
385398 return None
386399 connection = await psycopg .AsyncConnection .connect (
@@ -399,6 +412,7 @@ async def follows(username: str, following: str) -> bool | None:
399412
400413
401414async def read_followers (username : str ) -> List [str ]:
415+ """Fetch the followers of a user"""
402416 connection = await psycopg .AsyncConnection .connect (
403417 secrets .POSTGRES_URI , autocommit = True
404418 )
@@ -413,6 +427,7 @@ async def read_followers(username: str) -> List[str]:
413427
414428
415429async def read_following (username : str ) -> List [str ]:
430+ """Fetch the following of a user"""
416431 connection = await psycopg .AsyncConnection .connect (
417432 secrets .POSTGRES_URI , autocommit = True
418433 )
@@ -449,6 +464,7 @@ async def toggle_vote(username: str, _id: str):
449464
450465
451466async def voted (username : str , _id : str ) -> bool :
467+ """Check if the user has voted on the current post"""
452468 connection = await psycopg .AsyncConnection .connect (
453469 secrets .POSTGRES_URI , autocommit = True
454470 )
@@ -465,6 +481,7 @@ async def voted(username: str, _id: str) -> bool:
465481
466482
467483async def read_votes (_id : str ) -> List [str ]:
484+ """Fetch total count of votes on a post"""
468485 connection = await psycopg .AsyncConnection .connect (
469486 secrets .POSTGRES_URI , autocommit = True
470487 )
0 commit comments