def get_user(self, document): doc = db.collection(self.collction).document(document).get() if doc.exists: print("Duplicate Key Found. {}".format(doc.get('email'))) return doc.to_dict() else: return None
def create_user(self, model): doc = db.collection(self.collction).document(str(model.email)).get() if doc.exists: print("Duplicate Key Found. {}".format(doc.get('email'))) return False doc = self.db.collection(self.collction).document(str(model.email)).set(model.dict()) if not doc: raise("document not saved") return True
def get_all_users(self): docs = db.collection(self.collction).stream() users_list = [doc.to_dict() for doc in docs ] return users_list
def delete_user(self, document): doc_ref = db.collection(self.collction).document(document).delete() return True
def update_user(self, document, data={}): print(data) doc_ref = db.collection(self.collction).document(document).update(data) if not doc_ref: raise("document not saved") return True
def update_article(self, document, model): doc_ref = db.collection(self.collction).document(document).update( model.dict()) if not doc_ref: raise ("document not saved") return True
def get_article(self, document): doc = db.collection(self.collction).document(document).get() if doc.exists: return doc.to_dict() else: raise ("No Details Found")