Spaces:
Sleeping
Sleeping
Download app/services/note_store.py from bichnhan2701/NoteServicesAPI: direct link, hf CLI and curl.
- Browser
- Download file 777 Bytes
-
https://huggingface.co/spaces/bichnhan2701/NoteServicesAPI/resolve/main/app/services/note_store.py
- Command line
-
hf download hf://spaces/bichnhan2701/NoteServicesAPI/app/services/note_store.py
-
curl -L -o note_store.py https://huggingface.co/spaces/bichnhan2701/NoteServicesAPI/resolve/main/app/services/note_store.py
777 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()] | |
| def delete_note(note_id: str): | |
| db.collection(COL).document(note_id).delete() |