File size: 1,045 Bytes
0785301
 
 
 
 
357cf4e
 
0785301
 
 
 
 
 
 
357cf4e
0785301
357cf4e
 
0785301
 
 
 
 
 
 
 
 
 
 
357cf4e
0785301
357cf4e
 
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
27
28
29
30
31
32
33
from datetime import datetime
from app.services.firebase import db

COLLECTION = "notes"

import logging

def create_note(note_id: str, payload: dict):
    now = datetime.utcnow()
    payload.update({
        "status": "created",
        "created_at": now,
        "updated_at": now
    })
    logging.info(f"[NoteService] create_note: id={note_id}, keys={list(payload.keys())}")
    db.collection(COLLECTION).document(note_id).set(payload)
    logging.info(f"[NoteService] create_note: saved id={note_id}")


def update_note(note_id: str, data: dict = None, status: str = None):
    updates = {"updated_at": datetime.utcnow()}
    if data:
        updates.update(data)
    if status:
        updates["status"] = status

    db.collection(COLLECTION).document(note_id).update(updates)

def get_note(note_id: str):
    logging.info(f"[NoteService] get_note: id={note_id}")
    doc = db.collection(COLLECTION).document(note_id).get()
    logging.info(f"[NoteService] get_note: exists={doc.exists}")
    return doc.to_dict() if doc.exists else None