Created
October 20, 2021 17:56
-
-
Save pietrocolombo/36b660b4f07f27885855b735118d5af9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataDevice(Resource): | |
def put(self): | |
""" it receives the data from the devices and puts them in the database | |
:return: | |
""" | |
args = device_data_put_args.parse_args() | |
# check if the device exist | |
device = Device.query.get(args['id_device']) | |
if device is None: | |
# device is not in the database so we add to it | |
device = Device(id=args['id_device'], status=True, config=0) | |
# add data to the database | |
data = Data(id_device=args['id_device'], timestamp=args['timestamp'], data=args['data']) | |
device.data.append(data) | |
device.status = True | |
db.session.add(device) | |
db.session.add(data) | |
db.session.commit() | |
response = app.response_class( | |
response=json.dumps(device.config), | |
status=201, | |
mimetype='application/json') | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment