Skip to content

Commit

Permalink
Implement endpoint for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelkingsdev committed Nov 12, 2024
1 parent fdf927e commit 7b6105c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions web_app/api/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ class GetStatsResponse(BaseModel):
example=5,
description="Number of unique users in the database.",
)

class SubscribeToNotificationRequest(BaseModel):
"""
Pydantic model for the subscribe to notification request.
"""
telegram_id: str = Field(..., example="123457789", description="The Telegram ID of the user.")
wallet_id: str = Field(..., example="0xabc123772", description="The wallet ID of the user.")
16 changes: 16 additions & 0 deletions web_app/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ async def update_user_contract(
else:
return {"is_contract_deployed": False}

@router.post(
"/api/subscribe-to-notification",
tags=["User Operations"],
summary="Subscribe user to notifications",
response_description="Returns 200 if the subscription is successful.",
)
async def subscribe_to_notification(data: SubscribeToNotificationRequest):
user = user_db.get_user_by_wallet_id(data.wallet_id)
if user is None:
raise HTTPException(status_code=404, detail="User not found")

success = user_db.subscribe_to_notification(user_id=user.id, telegram_id=data.telegram_id)
if success:
return {"detail": "User subscribed to notifications successfully"}
else:
raise HTTPException(status_code=500, detail="Failed to subscribe user to notifications")

@router.get(
"/api/get-user-contract-address",
Expand Down

0 comments on commit 7b6105c

Please sign in to comment.