diff --git a/sigl/cli.py b/sigl/cli.py index dd32808..e623f63 100644 --- a/sigl/cli.py +++ b/sigl/cli.py @@ -12,8 +12,12 @@ def init_shell(): # pragma: no cover from sigl.database import db from sigl.domain.models import ( + AccessKey, + AccessToken, + ListEntry, Product, ProductLocation, + ShoppingList, ) return { @@ -26,8 +30,12 @@ def init_shell(): # pragma: no cover 'session': db.session, # Models + 'AccessKey': AccessKey, + 'AccessToken': AccessToken, + 'ListEntry': ListEntry, 'Product': Product, 'ProductLocation': ProductLocation, + 'ShoppingList': ShoppingList, } diff --git a/sigl/database/orm.py b/sigl/database/orm.py index 8bab9c4..06deec9 100644 --- a/sigl/database/orm.py +++ b/sigl/database/orm.py @@ -8,9 +8,15 @@ from sigl.domain.models import ( Product, ProductLocation, ) +from sigl.domain.models.accessKey import AccessKey, AccessToken +from sigl.domain.models.list import ListEntry, ShoppingList from .globals import db from .tables import ( + access_keys, + access_tokens, + list_entries, + lists, product_locations, products, ) @@ -21,6 +27,21 @@ __all__ = ('init_orm', ) def init_orm(): """Initialize the Sigl ORM.""" + # Access Keys + db.mapper(AccessKey, access_keys, properties={ + 'tokens': db.relationship( + AccessToken, + backref='accessKey', + cascade='all, delete-orphan', + ) + }) + + # Access Tokens + db.mapper(AccessToken, access_tokens) + + # List Entries + db.mapper(ListEntry, list_entries) + # Products db.mapper(Product, products, properties={ 'locations': db.relationship( @@ -28,7 +49,21 @@ def init_orm(): backref='product', cascade='all, delete-orphan', ), + 'shoppingLists': db.relationship( + ShoppingList, + backref='product', + cascade='all, delete-orphan', + ), }) # Product Locations db.mapper(ProductLocation, product_locations) + + # Shopping Lists + db.mapper(ShoppingList, lists, properties={ + 'entries': db.relationship( + ListEntry, + backref='shoppingList', + cascade='all, delete-orphan', + ) + }) diff --git a/sigl/domain/models/__init__.py b/sigl/domain/models/__init__.py index 48e6706..b152645 100644 --- a/sigl/domain/models/__init__.py +++ b/sigl/domain/models/__init__.py @@ -4,8 +4,15 @@ Simple Grocery List (Sigl) | sigl.app Copyright (c) 2022 Asymworks, LLC. All Rights Reserved. """ +from .accessKey import AccessKey, AccessToken +from .list import ListEntry, ShoppingList from .product import Product, ProductLocation __all__ = ( - 'Product', 'ProductLocation', + 'AccessKey', + 'AccessToken', + 'ListEntry', + 'Product', + 'ProductLocation', + 'ShoppingList', ) diff --git a/sigl/domain/models/accessKey.py b/sigl/domain/models/accessKey.py index 144c3e5..0d880e3 100644 --- a/sigl/domain/models/accessKey.py +++ b/sigl/domain/models/accessKey.py @@ -13,7 +13,7 @@ __all__ = ('AccessKey', 'AccessToken') @dataclass class AccessKey: """Sigl Access Key Class. - + The Access Key represents a client or group of clients authorized to interact with their specific Sigl shopping lists and products. Access Keys are generally not revoked or deleted and remain for the lifetime of the @@ -42,7 +42,7 @@ class AccessKey: @dataclass class AccessToken: """Sigl Access Token Class. - + The Access Token represents authorization for a client (identified by an Access Key) to interact with the Sigl server. The token string, issue time, and expiry time must match the client-provided JWT for access to be granted. diff --git a/sigl/domain/models/list.py b/sigl/domain/models/list.py index 0b52e55..e796016 100644 --- a/sigl/domain/models/list.py +++ b/sigl/domain/models/list.py @@ -5,7 +5,6 @@ Copyright (c) 2022 Asymworks, LLC. All Rights Reserved. """ from dataclasses import dataclass -from typing import List from .mixins import NotesMixin, TimestampMixin from .product import Product diff --git a/sigl/domain/models/product.py b/sigl/domain/models/product.py index 8b716cf..d4ffcca 100644 --- a/sigl/domain/models/product.py +++ b/sigl/domain/models/product.py @@ -5,7 +5,6 @@ Copyright (c) 2022 Asymworks, LLC. All Rights Reserved. """ from dataclasses import dataclass -from typing import List from .mixins import NotesMixin, TimestampMixin