Skip to content

Commit

Permalink
create_post documentation added
Browse files Browse the repository at this point in the history
  • Loading branch information
Pupper0n1 committed Jan 26, 2024
1 parent 1209275 commit 8818214
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Backend/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,24 @@ async def update_profile_picture(self, request: 'Request[User, Token, Any]', ses

@post('/post', media_type=MediaType.TEXT)
async def create_post(self, request: 'Request[User, Token, Any]', session: AsyncSession, data: Annotated[CreateMultiplePostSchema, Body(media_type=RequestEncodingType.MULTI_PART)]) -> str:
'''
Creates one or multiple posts with images associated with communities.
Args:
request (Request): The request object containing user and token information.
session (AsyncSession): The database session for performing database transactions.
data (CreateMultiplePostSchema): The data received in the request payload, expected to be in multipart form-data format.
Returns:
str: A message indicating the path where the image file associated with the posts has been saved.
'''
user = await get_user_by_id(session, request.user)
image = await data.file.read()

for community_id in (data.communities_id):
post = Post(id=uuid7(), title=data.title, caption=data.caption, user_id=user.id, community_id=community_id)
session.add(post)


image_dir = "static/images/posts"
os.makedirs(image_dir, exist_ok=True)
Expand Down

0 comments on commit 8818214

Please sign in to comment.