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)
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)
def insert(self, query, values): try: if (self.cursor.execute(query, values)): return True return None except: return ResponseHandler.error('Something went wrong', 500)
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)
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)
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())
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)