Spaces:
Running
Running
File size: 694 Bytes
7402e0f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
from app.infra.firebase import db
COL = "notes"
def create_note(note: dict):
ref = db.collection(COL).document(note["note_id"])
if ref.get().exists:
raise ValueError(f"Note already exists: {note['note_id']}")
ref.set(note)
def update_note(note_id: str, data: dict):
if not data:
return
db.collection(COL).document(note_id).update(data)
def get_note(note_id: str):
doc = db.collection(COL).document(note_id).get()
return doc.to_dict() if doc.exists else None
def list_notes(folder_id: str | None = None):
q = db.collection(COL)
if folder_id:
q = q.where("folder_id", "==", folder_id)
return [d.to_dict() for d in q.stream()] |