Exemplo n.º 1
0
 def get(self):
     results = Store.get_items()
     if results:
         return ResponseHandler.success(
             'stores',
             ResponseHandler.OK,
             data=[result.json() for result in results])
     return ResponseHandler.error('stores not found',
                                  ResponseHandler.BAD_REQUEST)
Exemplo n.º 2
0
 def post(self):
     data = Register.parser.parse_args()
     if User.find_by_username(data.username):
         return ResponseHandler.error('user exists', 400)
     user = User(**data)
     user.save()
     if user.id:
         return ResponseHandler.success('User Added', 200, data=user.json())
     return ResponseHandler.error('user not added', 400)
Exemplo n.º 3
0
    def post(self):
        # Check if name exists
        data = StoreList.parser.parse_args()
        result = Store.get_item(data.name)
        if result:
            return ResponseHandler.error('store exists',
                                         ResponseHandler.BAD_REQUEST)

        store = Store(**data)
        store.save()

        return ResponseHandler.success('store added', 201, data=store.json())
Exemplo n.º 4
0
 def delete(self, query, params):
     try:
         if self.cursor.execute(query, params).rowcount > 0:
             return True
         return None
     except:
         return ResponseHandler.error('Something went wrong', 500)
Exemplo n.º 5
0
 def insert(self, query, values):
     try:
         if (self.cursor.execute(query, values)):
             return True
         return None
     except:
         return ResponseHandler.error('Something went wrong', 500)
Exemplo n.º 6
0
    def put(self, name):
        data = request.json()
        store = Store.get_item(name)
        if store is None:
            store = Store(name)
        else:
            store.name = data['name']

        return ResponseHandler.success('store updated', 200, data=store.json())
Exemplo n.º 7
0
    def select(self, query, params=None):
        try:
            if params:
                result = self.cursor.execute(query, params)
                return result.fetchone()
            else:
                result = self.cursor.execute(query)
                return result.fetchall()

            return None
        except:
            return ResponseHandler.error('Something went wrong', 500)
Exemplo n.º 8
0
 def delete(self, name):
     store = Store.get_item(name)
     store.delete()
     return ResponseHandler.success('store deleted', 200)
Exemplo n.º 9
0
 def get(self, name):
     store = Store.get_item(name)
     if store:
         return ResponseHandler.success('store', 200, data=store.json())
     return ResponseHandler.error('store not found', 404)