Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all users with specific post #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api_schemas/post_schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from api_schemas.base_schema import BaseSchema
from api_schemas.user_schemas import UserRead


class _PostPermissionRead(BaseSchema):
Expand All @@ -17,3 +18,7 @@ class PostRead(BaseSchema):
class PostCreate(BaseSchema):
name: str
council_id: int


class PostUserRead(BaseSchema):
user: UserRead
14 changes: 13 additions & 1 deletion routes/post_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from database import DB_dependency
from db_models.council_model import Council_DB
from db_models.post_model import Post_DB
from api_schemas.post_schemas import PostRead, PostCreate
from api_schemas.post_schemas import PostRead, PostCreate, PostUserRead
from user.permission import Permission
from fastapi import status, HTTPException

Expand Down Expand Up @@ -39,3 +39,15 @@ def delete_post(post_id: int, db: DB_dependency):


# TODO PATCH


@post_router.get("/{post_id}", response_model=list[PostUserRead])
def users_with_post(db: DB_dependency, post_id: int):
post = db.query(Post_DB).filter(Post_DB.id == post_id).one_or_none()

if post == None:
raise HTTPException(400, detail="Invalid post id")

users = post.post_users

return users