Exemplo n.º 1
0
class Favorites(RequestHandler):
    _path_extractor = None
    _favorite_data = None

    def set_default_headers(self):
        if ADD_CORS_HEADERS:
            self.set_header("Access-Control-Allow-Origin", "*")
            self.set_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
            self.set_header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')

    def initialize(self):
        self._path_extractor = PathExtractor(self)
        self._favorite_data = FavoriteData()
        self._favorite_data.open_connection()

    @asynchronous
    @engine
    def get(self, user_id, *args, **kwargs):
        favorites = self._favorite_data.find(
            self._path_extractor.user_id(user_id)
        )

        self.set_status(200)
        self.set_header("Content-Type", "application/json")
        self.finish(
            dumps(
                {
                    "favorites": [
                        x["_id"]["product_id"]
                        for x in favorites
                        ],
                    "version": __version__
                }
            )
        )
Exemplo n.º 2
0
class Favorites(RequestHandler):
    _path_extractor = None
    _favorite_data = None

    def set_default_headers(self):
        if ADD_CORS_HEADERS:
            self.set_header("Access-Control-Allow-Origin", "*")
            self.set_header('Access-Control-Allow-Methods',
                            'GET, POST, OPTIONS')
            self.set_header('Access-Control-Allow-Headers',
                            'Origin, X-Requested-With, Content-Type, Accept')

    def initialize(self):
        self._path_extractor = PathExtractor(self)
        self._favorite_data = FavoriteData()
        self._favorite_data.open_connection()

    @asynchronous
    @engine
    def get(self, user_id, *args, **kwargs):
        favorites = self._favorite_data.find(
            self._path_extractor.user_id(user_id))

        self.set_status(200)
        self.set_header("Content-Type", "application/json")
        self.finish(
            dumps({
                "favorites": [x["_id"]["product_id"] for x in favorites],
                "version": __version__
            }))
Exemplo n.º 3
0
class Favorites(Base):
    _favorite_data = None

    def initialize(self):
        self._favorite_data = FavoriteData()
        self._favorite_data.open_connection()

    def _get_from_service(self, _id):
        try:
            app_log.debug("Favorites,get_from_service,_id=%s", _id)
            favorites = self._favorite_data.find(_id)
            return [str(x["_id"]["product_id"]) for x in favorites]

        except:
            app_log.error("get_from_service,_id=%s", _id)
            return None
Exemplo n.º 4
0
class Favorite(RequestHandler):
    _path_extractor = None
    _favorite_data = None

    def set_default_headers(self):
        if ADD_CORS_HEADERS:
            self.set_header("Access-Control-Allow-Origin", "*")
            self.set_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
            self.set_header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')

    def initialize(self):
        self._path_extractor = PathExtractor(self)
        self._favorite_data = FavoriteData()
        self._favorite_data.open_connection()

    @asynchronous
    @engine
    def options(self, *args, **kwargs):
        self.finish()

    @asynchronous
    @engine
    def put(self, user_id, product_id, *args, **kwargs):
        self._favorite_data.insert(
            self._path_extractor.user_id(user_id),
            self._path_extractor.product_id(product_id)
        )

        self.set_status(201)
        self.finish()

    @asynchronous
    @engine
    def delete(self, user_id, product_id, *args, **kwargs):
        self._favorite_data.delete(
            self._path_extractor.user_id(user_id),
            self._path_extractor.product_id(product_id)
        )

        self.set_status(204)
        self.finish()


    @asynchronous
    @engine
    def get(self, user_id, product_id, *args, **kwargs):
        favorite_record = self._favorite_data.get(
            self._path_extractor.user_id(user_id),
            self._path_extractor.product_id(product_id)
        )

        self.set_status(201)
        self.finish(
            dumps(
                {
                    "favorited": favorite_record is not None
                }
            )
        )
Exemplo n.º 5
0
class Favorite(RequestHandler):
    _path_extractor = None
    _favorite_data = None

    def set_default_headers(self):
        if ADD_CORS_HEADERS:
            self.set_header("Access-Control-Allow-Origin", "*")
            self.set_header('Access-Control-Allow-Methods',
                            'GET, POST, OPTIONS')
            self.set_header('Access-Control-Allow-Headers',
                            'Origin, X-Requested-With, Content-Type, Accept')

    def initialize(self):
        self._path_extractor = PathExtractor(self)
        self._favorite_data = FavoriteData()
        self._favorite_data.open_connection()

    @asynchronous
    @engine
    def options(self, *args, **kwargs):
        self.finish()

    @asynchronous
    @engine
    def put(self, user_id, product_id, *args, **kwargs):
        self._favorite_data.insert(self._path_extractor.user_id(user_id),
                                   self._path_extractor.product_id(product_id))

        self.set_status(201)
        self.finish()

    @asynchronous
    @engine
    def delete(self, user_id, product_id, *args, **kwargs):
        self._favorite_data.delete(self._path_extractor.user_id(user_id),
                                   self._path_extractor.product_id(product_id))

        self.set_status(204)
        self.finish()

    @asynchronous
    @engine
    def get(self, user_id, product_id, *args, **kwargs):
        favorite_record = self._favorite_data.get(
            self._path_extractor.user_id(user_id),
            self._path_extractor.product_id(product_id))

        self.set_status(201)
        self.finish(dumps({"favorited": favorite_record is not None}))
Exemplo n.º 6
0
 def initialize(self):
     self._path_extractor = PathExtractor(self)
     self._favorite_data = FavoriteData()
     self._favorite_data.open_connection()
Exemplo n.º 7
0
 def initialize(self):
     self._favorite_data = FavoriteData()
     self._favorite_data.open_connection()
Exemplo n.º 8
0
 def initialize(self):
     self._path_extractor = PathExtractor(self)
     self._favorite_data = FavoriteData()
     self._favorite_data.open_connection()