university-final-iot-backend/app/dashboards/api.py

56 lines
1.4 KiB
Python
Raw Normal View History

2018-09-19 23:42:37 +00:00
from .models import Dashboard
# Public interface
def create_dashboard(dashboard_data, account_id):
"""
Tries to create dashboard with given parameters
:param dashboard_data: JSON dashboard data
:param account_id: Id of owner of this dashboard
:type name: JSON
:type account_id: int
:returns: True if dashboard is successfully created
:rtype: Boolean
"""
dashboard = Dashboard(account_id, dashboard_data)
dashboard.save()
def get_dashboard(dashboard_id):
"""
Tries to fetch dashboard with given id
:param dashboard_id: Id of requested dashboard
:type name: int
:returns: Dashboard object
:rtype: Dashboard
"""
return Dashboard.get(id=dashboard_id)
def update_dashboard(dashboard_id, dashboard_data):
"""
Tries to update dashboard with given parameters
:param dashboard_data: JSON dashboard data
:param dashboard_id: Id of the dashboard
:type name: JSON
:type dashboard_id: int
"""
dashboard = Dashboard.get(id=dashboard_id)
dashboard.dashboard_data = dashboard_data
2018-09-23 13:29:15 +00:00
dashboard.save()
2018-09-19 23:42:37 +00:00
def get_dashboards(account_id):
"""
Tries to fetch dashboards owned by account with given id
:param account_id: Id of owner account
:type name: int
:returns: Dashboard list
:rtype: List of Dashboard
"""
return Dashboard.get_many(account_id=account_id)