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: public user profile pic #177

Merged
merged 4 commits into from
Nov 28, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ConversationInfoResponse(BaseModel):
agent_ids: List[str]
access_type: ConversationAccessType
is_creator: bool
creator_id: str

class Config:
from_attributes = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ async def get_conversation_info(
agent_ids=conversation.agent_ids,
access_type=access_type,
is_creator=is_creator,
creator_id=conversation.user_id,
)
except ConversationNotFoundError as e:
logger.warning(str(e))
Expand Down
4 changes: 4 additions & 0 deletions app/modules/users/user_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

from app.modules.users.user_schema import UserConversationListResponse
from app.modules.users.user_service import UserService
from app.modules.users.user_schema import UserProfileResponse


class UserController:
def __init__(self, db: Session):
self.service = UserService(db)

async def get_user_profile_pic(self, uid: str) -> UserProfileResponse:
return await self.service.get_user_profile_pic(uid)

async def get_conversations_for_user(
self, user_id: str, start: int, limit: int
) -> List[UserConversationListResponse]:
Expand Down
10 changes: 10 additions & 0 deletions app/modules/users/user_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from app.modules.auth.auth_service import AuthService
from app.modules.users.user_controller import UserController
from app.modules.users.user_schema import UserConversationListResponse
from app.modules.users.user_schema import UserProfileResponse
from app.modules.utils.APIRouter import APIRouter

router = APIRouter()
Expand All @@ -27,3 +28,12 @@ async def get_conversations_for_user(
user_id = user["user_id"]
controller = UserController(db)
return await controller.get_conversations_for_user(user_id, start, limit)

@router.get("/user/{user_id}/public-profile", response_model=UserProfileResponse)
async def fetch_user_profile_pic(
user_id: str,
user=Depends(AuthService.check_auth),
db: Session = Depends(get_db),
):
controller = UserController(db)
return await controller.get_user_profile_pic(user_id)
5 changes: 5 additions & 0 deletions app/modules/users/user_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ class CreateUser(BaseModel):
last_login_at: datetime
provider_info: dict
provider_username: str


class UserProfileResponse(BaseModel):
user_id: str
profile_pic_url: Optional[str] = None
17 changes: 17 additions & 0 deletions app/modules/users/user_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging
from datetime import datetime
from typing import List
Expand All @@ -9,6 +10,9 @@
from app.modules.conversations.conversation.conversation_model import Conversation
from app.modules.users.user_model import User
from app.modules.users.user_schema import CreateUser
from firebase_admin import auth
from app.modules.users.user_schema import UserProfileResponse


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -143,3 +147,16 @@ def get_user_ids_by_emails(self, emails: List[str]) -> List[str]:
except Exception as e:
logger.error(f"Error fetching user ID by emails {emails}: {e}")
return None


async def get_user_profile_pic(self, uid: str) -> UserProfileResponse:
try:
user_record = await asyncio.to_thread(auth.get_user, uid)
Yash-pede marked this conversation as resolved.
Show resolved Hide resolved
profile_pic_url = user_record.photo_url
return {
"user_id": user_record.uid,
"profile_pic_url": profile_pic_url
}
except Exception as e:
logging.error(f"Error retrieving user profile picture: {e}")
return None
Loading