def post(self): """ create new data :return: """ args = self.reqparse.parse_args() parts = args['Authorization'].split() user_id = DBHelper.get_user_id(parts[1]) sample = request.get_json() if 'label' not in sample: raise CustomError('Parameter <label> missing', status_code=400) if 'data' not in sample: raise CustomError('Parameter <data> missing', status_code=400) label = sample['label'] data = sample['data'] lb = DBHelper.get_label_by_name(label) if lb is None: raise CustomError('Label Not Found', status_code=404) label_id = lb.id for d in data: d.update({ 'user_id': user_id, 'label_id': label_id }) DBHelper.set_data(d) return { 'message': 'Upload successfully!', 'status_code': 201 }, 201
def post(self): """ create a new label for this specific DataSource :return: JSON {message:"", status_code:""} """ sample = request.get_json() if 'label' not in sample: raise CustomError('Parameter <label> missing', status_code=400) if 'units' not in sample: raise CustomError('Parameter <units> missing', status_code=400) if 'category' not in sample: raise CustomError('Parameter <category> missing', status_code=400) label = sample['label'] units = sample['units'] category = sample['category'] if DBHelper.get_label_by_name(label) is not None: raise CustomError(('{0} has been created').format(label), status_code=409) if units is None: u_id = None else: un = DBHelper.get_units_by_name(units) if un is None: raise NotFound(payload={'detail': ('{0} Not Found').format(units)}) u_id = un.id ca = DBHelper.get_category_by_name(category) if ca is None: raise NotFound(payload={'detail': ('{0} Not Found').format(category)}) if 'desc' in sample: DBHelper.set_label(label, u_id, ca.id, sample['desc']) else: DBHelper.set_label(label, u_id, ca.id) return { 'message': 'Upload successfully!', 'status_code': 201 }, 201