def get(self, region_id=None, locality_id=None): if not locality_id and region_id: localities = locality_query.get_all_localities(region_id) if not localities: msg = 'region id ' + str(region_id) + ' not found in database' body = {'success': False, 'message': msg} return body, 409 body = {'success': True, 'localities': localities} return body, 200 elif locality_id and not region_id: locality = locality_query.consult_locality_byid(locality_id) if not locality: msg = 'locality id ' + str( locality_id) + ' not found in database' body = {'success': False, 'message': msg} return body, 409 body = {'success': True, 'locality': locality} return body, 200 body = {'success': False, 'message': 'was not possible to list'} return body, 500
def put(self, locality_id=None): put_parser = reqparse.RequestParser() put_parser.add_argument( 'name', dest='name', type=str, required=True, help='required field <name> not informed in locality.', ) put_parser.add_argument( 'region_id', dest='region_id', type=int, required=True, help='required field <region_id> not informed in locality.', ) data = dict() args = put_parser.parse_args() if not locality_query.consult_locality_byid(locality_id): body = { 'success': False, 'message': 'region id ' + str(locality_id) + ' not found in database' } return body, 409 if locality_query.consult_locality_byname(args.name, args.region_id): body = { 'success': False, 'message': 'name locality already registered!' } return body, 200 data['id'] = locality_id data['region_id'] = args.region_id data['name'] = args.name if locality_query.update_locality(data): body = { 'success': True, 'message': 'update with successfully!', } return body, 200 body = {'success': False, 'message': 'error to update'} return body, 500
def post(self): ''' +---------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | weather | text | NO | | NULL | | | precipitation | int(11) | NO | | NULL | | | date | date | NO | | NULL | | | max | int(11) | NO | | NULL | | | min | int(11) | NO | | NULL | | | locality_id | int(11) | NO | MUL | NULL | | | lag | int(11) | NO | | NULL | | +---------------+---------+------+-----+---------+----------------+ ''' post_parser = reqparse.RequestParser() post_parser.add_argument( 'weather', dest='weather', type=str, required=True, help='required field <atmospheric_pressure> not informed.', ) post_parser.add_argument( 'precipitation', dest='precipitation', type=int, required=True, help='required field <precipitation> not informed', ) post_parser.add_argument( 'date', dest='date', type=str, required=True, help='required field <date> not informed', ) post_parser.add_argument( 'max', dest='max', type=int, required=True, help='required field <max> not informed', ) post_parser.add_argument( 'min', dest='min', type=int, required=True, help='required field <min> not informed', ) post_parser.add_argument( 'locality_id', dest='locality_id', type=int, required=True, help='required field <locality_id> not informed', ) post_parser.add_argument( 'lag', dest='lag', type=int, required=True, help='required field <lag> not informed', ) data = dict() args = post_parser.parse_args() if not locality_query.consult_locality_byid(args.locality_id): body = { 'success': False, 'message': 'locality id ' + str(args.locality_id) + ' not found in database' } return body, 409 data['weather'] = args.weather data['precipitation'] = args.precipitation data['date'] = args.date data['max'] = args.max data['min'] = args.min data['locality_id'] = args.locality_id data['lag'] = args.lag if wfday_query.create_wfday(data): body = { 'success': True, 'message': 'created with successfully!', } return body, 201 body = {'success': False, 'message': 'error to create'} return body, 500
def post(self): ''' +----------------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------------+----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | atmospheric_pressure | int(11) | NO | | NULL | | | wind | int(11) | NO | | NULL | | | temp | int(11) | NO | | NULL | | | relative_humidity | int(11) | NO | | NULL | | | last_update | text | YES | | NULL | | | weather | text | NO | | NULL | | | locality_id | int(11) | NO | MUL | NULL | | | date_time | datetime | NO | | NULL | | +----------------------+----------+------+-----+---------+----------------+ ''' post_parser = reqparse.RequestParser() post_parser.add_argument( 'atmospheric_pressure', dest='atmospheric_pressure', type=int, required=True, help='required field <atmospheric_pressure> not informed.', ) post_parser.add_argument( 'wind', dest='wind', type=int, required=True, help='required field <wind> not informed', ) post_parser.add_argument( 'temp', dest='temp', type=int, required=True, help='required field <temp> not informed', ) post_parser.add_argument( 'relative_humidity', dest='relative_humidity', type=int, required=True, help='required field <relative_humidity> not informed', ) post_parser.add_argument('last_update', dest='last_update', type=str, default=None) post_parser.add_argument( 'weather', dest='weather', type=str, required=True, help='required field <weather> not informed', ) post_parser.add_argument( 'locality_id', dest='locality_id', type=int, required=True, help='required field <locality_id> not informed', ) post_parser.add_argument( 'date_time', dest='date_time', type=str, required=True, help='required field <date_time> not informed', ) data = dict() args = post_parser.parse_args() if not locality_query.consult_locality_byid(args.locality_id): body = { 'success': False, 'message': 'locality id ' + str(args.locality_id) + ' not found in database' } return body, 409 data['atmospheric_pressure'] = args.atmospheric_pressure data['wind'] = args.wind data['temp'] = args.temp data['relative_humidity'] = args.relative_humidity data['last_update'] = args.last_update data['weather'] = args.weather data['locality_id'] = args.locality_id data['date_time'] = args.date_time if wfhour_query.create_wfhour(data): body = { 'success': True, 'message': 'created with successfully!', } return body, 201 body = {'success': False, 'message': 'error to create'} return body, 500