NoteServicesAPI / app /services /note_store.py
bichnhan2701's picture
Update note services logic
7402e0f
raw
history blame contribute delete
694 Bytes
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()]