def get_by_account_id(self, account_id: str, parent: str = None) -> List[Transaction]: coll_ref = self.collection_ref if parent: coll_ref = db.collection(parent + '/' + self.collection_name) transactions = coll_ref.where('account_id', '==', account_id).stream() return [Transaction(**doc.to_dict()) for doc in transactions if doc.to_dict()]
def get(self, id: UUID) -> Todo: doc_ref = db.collection(self.collection_name).document(str(id)) doc = doc_ref.get() if doc.exists: return Todo(**doc.to_dict()) return None
def __init__(self): self.collection_ref = db.collection(self.collection_name)
def get_client_ref(self, client_id: str): return db.collection(self.clients_collection).document(client_id)
def __init__(self, parent=None): self.collection_ref = db.collection(self.collection_name)
def delete(self, id: UUID) -> None: db.collection(self.collection_name).document(str(id)).delete()
def update(self, id: UUID, todo_update: TodoUpdate) -> Todo: data = todo_update.dict() doc_ref = db.collection(self.collection_name).document(str(id)) doc_ref.update(data) return self.get(id)
def list(self) -> List[Todo]: todos_ref = db.collection(self.collection_name) return [Todo(**doc.get().to_dict()) for doc in todos_ref.list_documents() if doc.get().to_dict()]
def create(self, todo_create: TodoCreate) -> Todo: data = todo_create.dict() data['id'] = str(data['id']) doc_ref = db.collection(self.collection_name).document(str(todo_create.id)) doc_ref.set(data) return self.get(todo_create.id)