Beispiel #1
0
 def get_resource(self, db_name, resource_name):
     """根据资源名称获取资源对象
     :param resource_name: 资源名称
     """
     resource = self._resource_map.get(db_name, {}).get(resource_name, None)
     if resource is None:
         raise NotFoundError("no resource named {}".format(resource_name))
     return resource
Beispiel #2
0
 def get_db(self, db_name):
     """通过db_name获取数据库对象
     """
     # 如果db不存在会排除ValueError异常
     database = self.handler.settings['service_manager'].database
     if db_name not in database:
         raise NotFoundError("no db named {}".format(db_name))
     return database[db_name]
Beispiel #3
0
 def delete(self, email):
     try:
         user_dal = UserDAL()
         user = user_dal.get(email)
         if not user:
             raise NotFoundError("User:{} Not Found".format(email))
         user_dal.delete(email)
     except Exception as e:
         raise e
Beispiel #4
0
 def update(self, email, payload):
     try:
         user_dal = UserDAL()
         user = user_dal.get(email)
         if not user:
             raise NotFoundError("User:{} Not Found".format(email))
         user_dal.update(email, payload)
     except Exception as e:
         raise e
 def add(self, email, payload):
     try:
         user_dal = UserDAL()
         if not user_dal.get(email):
             raise NotFoundError("User:{} does not exists".format(email))
         follow_dal = FollowingConnectionDAL()
         follow_dal.add(email, payload)
         # TODO: Background task to run dijkstra's algorithm to be done here
     except Exception as e:
         raise e
 def delete(self, email, follow_email):
     try:
         user_dal = UserDAL()
         user = user_dal.get(email)
         if not user:
             raise NotFoundError("User:{} Not Found".format(email))
         conn_dal = FollowingConnectionDAL()
         conn_dal.delete(email, follow_email)
         # TODO: Background task to run dijkstra's algorithm to be done here
     except Exception as e:
         raise e
 def get(self, email):
     try:
         user_dal = UserDAL()
         result = user_dal.get(email)
         if not result:
             raise NotFoundError("User:{} Not Found".format(email))
         conn_dal = FollowingConnectionDAL()
         following_users = [
             user["following_user_email"] for user in conn_dal.get(email)
         ]
         return {"following_users": following_users}
     except Exception as e:
         raise e
Beispiel #8
0
    def get(self, email):
        try:
            user_dal = UserDAL()
            result = user_dal.get(email)
            if not result:
                raise NotFoundError("User:{} Not Found".format(email))
            conn_dal = FollowingConnectionDAL()
            following_users = []
            for user in conn_dal.get(email):
                following_users.append({
                    "following_user_email": user["following_user_email"],
                    "created_at": user["created_at"]
                })

            result["following_users"] = following_users
            return result
        except Exception as e:
            raise e