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

Feat/get blocked users #25

Merged
merged 4 commits into from
Mar 24, 2025
Merged
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
28 changes: 28 additions & 0 deletions app/api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def create_user(user_in: UserCreate, session: SessionDep) -> User | None:
user_db = user_service.create_user(session=session, user_create=user_in)
return user_db

#Get users that are blocked
#TODO: only admin can list blocked users
@router.get("/blocked_users", response_model=list[UserPublic])
def get_blocked_users(session: SessionDep):
users = session.exec(select(User).where(User.is_active == False)).all()
return users

@router.post("/signup", response_model=UserPublic)
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
Expand Down Expand Up @@ -129,3 +135,25 @@ def delete_user(user_id: uuid.UUID, session: SessionDep):
session.delete(user)
session.commit()
return {"ok": True}

# Block a user
# TODO: only admin can blocked
@router.patch("/block/{user_id}", response_model=dict)
def block_user(user_id: uuid.UUID, session: SessionDep):
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
user.is_active = False
session.add(user)
session.commit()
return {"ok":True}

@router.patch("/unblock/{user_id}", response_model=dict)
def unblock_user(user_id: uuid.UUID, session: SessionDep):
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
user.is_active = True
session.add(user)
session.commit()
return {"ok":True}