Skip to content

Commit

Permalink
Identification: Final release
Browse files Browse the repository at this point in the history
Resolution: Fix

Implementation:
- renamed data_point attribute to datapoint in set_device endpoint.
- device_uuid argument has from now uuid attribute of device not id.
- added check for datapoint id (if exist) in set_device endpoint.
  • Loading branch information
zurek11 committed May 6, 2020
1 parent 4c1c7cd commit 913fb62
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/forms/module_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class ModuleSetValueForm(FlaskForm):
UUID(message='Hodnota nie je vo formáte UUID.')
]
)
data_point = StringField('data_point', validators=[DataRequired(message='Hodnota data_point je povinná.')])
datapoint = StringField('data_point', validators=[DataRequired(message='Hodnota datapoint je povinná.')])
value = StringField('value', validators=[DataRequired(message='Hodnota value je povinná.')])
8 changes: 6 additions & 2 deletions api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,15 @@ def set_value_module(module_id):
raise ApiException('Daný modul sa nepodarilo nájsť.', status_code=http_status.HTTP_404_NOT_FOUND)

device = module.devices.filter_by(id=data.get('device_id')).first()
del data['device_id']
if not device:
raise ApiException('Dané zariadenie sa nepodarilo nájsť.', status_code=http_status.HTTP_404_NOT_FOUND)

data['device_uuid'] = data['device_id']
del data['device_id']
datapoint = module.module_device_type.device_type_datapoints.filter_by(code=data.get('datapoint')).first()
if not datapoint:
raise ApiException('Daný datapoint sa nepodarilo nájsť.', status_code=http_status.HTTP_404_NOT_FOUND)

data['device_uuid'] = str(device.uuid)

# TODO: Ziskat sequence number (odniekial)
data['sequence_number'] = 123
Expand Down
2 changes: 1 addition & 1 deletion core/models/module_device_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ModuleDeviceType(StandardModel):
code = db.Column(db.String(100), nullable=True)
protocol_id = db.Column(UUID(as_uuid=True), db.ForeignKey('protocols.id'))

device_type_datapoints = db.relationship("DeviceTypeDatapoint", back_populates="module_device_type")
device_type_datapoints = db.relationship("DeviceTypeDatapoint", lazy='dynamic', back_populates="module_device_type")
protocol = db.relationship("Protocol", back_populates="module_device_types")
modules = db.relationship("Module", back_populates="module_device_type")

Expand Down

0 comments on commit 913fb62

Please sign in to comment.