Major overhaul to the Notes/Issues. Minor tweaks to the UI. Added Profile photos
This commit is contained in:
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from google.cloud.firestore_v1 import DocumentReference
|
||||
|
||||
from shared.firebase import get_db
|
||||
from shared.firebase import get_db, get_bucket
|
||||
from shared.exceptions import NotFoundError
|
||||
from users.models import UserCreate, UserUpdate, UserInDB
|
||||
|
||||
@@ -250,3 +250,29 @@ def get_user_devices(user_doc_id: str) -> list[dict]:
|
||||
break
|
||||
|
||||
return devices
|
||||
|
||||
|
||||
def upload_photo(user_doc_id: str, file_bytes: bytes, filename: str, content_type: str) -> str:
|
||||
"""Upload a profile photo to Firebase Storage and update the user's photo_url."""
|
||||
db = get_db()
|
||||
bucket = get_bucket()
|
||||
if not bucket:
|
||||
raise RuntimeError("Firebase Storage not initialized")
|
||||
|
||||
# Verify user exists
|
||||
doc_ref = db.collection(COLLECTION).document(user_doc_id)
|
||||
doc = doc_ref.get()
|
||||
if not doc.exists:
|
||||
raise NotFoundError("User")
|
||||
|
||||
ext = filename.rsplit(".", 1)[-1] if "." in filename else "jpg"
|
||||
storage_path = f"users/{user_doc_id}/uploads/profile.{ext}"
|
||||
|
||||
blob = bucket.blob(storage_path)
|
||||
blob.upload_from_string(file_bytes, content_type=content_type)
|
||||
blob.make_public()
|
||||
|
||||
photo_url = blob.public_url
|
||||
doc_ref.update({"photo_url": photo_url})
|
||||
|
||||
return photo_url
|
||||
|
||||
Reference in New Issue
Block a user