def get_item(self, _id=None, postId=None): try: coll = db[self.collection] query = {"_id": ObjectId(_id)} if request.args.get("embedded", None) is not None: return Utils.embedded_comments(_id) if postId is not None: query = {"_id": ObjectId(_id), "postId": ObjectId(postId)} if coll.find(query) is not None: return Utils.return_jsonify(list(coll.find(query))) else: return make_error(status=400, description="Not found") except Exception as e: return make_error(status=400, description=str(e))
def get_item(cls, postId=None): check = request.args.get("comments", "") if check != "": return Utils.embedded_comments(postId) else: query = {} try: coll = db[cls.collection] if cls.__name__ == "Post": query = {"_id": ObjectId(postId)} elif cls.__name__ == "Comment": query = {"postId": ObjectId(postId)} if coll.find(query) is not None: return Utils.return_jsonify(list(coll.find(query))) else: return make_error(status=400, description="Not found") except Exception as e: return make_error(status=400, description=str(e))