diff --git a/web_app/api/serializers/user.py b/web_app/api/serializers/user.py index 10671536..fc42cf9b 100644 --- a/web_app/api/serializers/user.py +++ b/web_app/api/serializers/user.py @@ -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.") \ No newline at end of file diff --git a/web_app/api/user.py b/web_app/api/user.py index e3fb1bca..342d0c2a 100644 --- a/web_app/api/user.py +++ b/web_app/api/user.py @@ -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",