added repository method to get the number of devices for an account.
parent
35fa76e6a2
commit
3c5983a194
|
@ -31,7 +31,6 @@ class DeviceRepository(object):
|
||||||
def get_devices_by_account_id(self, account_id: str) -> List[Device]:
|
def get_devices_by_account_id(self, account_id: str) -> List[Device]:
|
||||||
"""Fetch all devices associated to a user from a given account id
|
"""Fetch all devices associated to a user from a given account id
|
||||||
|
|
||||||
:param db: psycopg2 connection to mycroft database
|
|
||||||
:param account_id: uuid
|
:param account_id: uuid
|
||||||
:return: List of User's devices
|
:return: List of User's devices
|
||||||
"""
|
"""
|
||||||
|
@ -42,6 +41,18 @@ class DeviceRepository(object):
|
||||||
sql_results = self.cursor.select_all(query)
|
sql_results = self.cursor.select_all(query)
|
||||||
return [Device(**result) for result in sql_results]
|
return [Device(**result) for result in sql_results]
|
||||||
|
|
||||||
|
def get_account_device_count(self, account_id):
|
||||||
|
query = DatabaseRequest(
|
||||||
|
sql=get_sql_from_file(
|
||||||
|
path.join(SQL_DIR, 'get_account_device_count.sql')
|
||||||
|
),
|
||||||
|
args=dict(account_id=account_id)
|
||||||
|
|
||||||
|
)
|
||||||
|
sql_results = self.cursor.select_one(query)
|
||||||
|
|
||||||
|
return sql_results['device_count']
|
||||||
|
|
||||||
def get_subscription_type_by_device_id(self, device_id):
|
def get_subscription_type_by_device_id(self, device_id):
|
||||||
"""Return the type of subscription of device's owner
|
"""Return the type of subscription of device's owner
|
||||||
:param device_id: device uuid
|
:param device_id: device uuid
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
SELECT count(*) AS device_count FROM device.device WHERE account_id = %(account_id)s
|
Loading…
Reference in New Issue