-
-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update decoupled-example with abstraction layer #770
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""abstraction package.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""abstraction analytics package.""" |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,19 @@ | ||||||||
"""Analytics services module.""" | ||||||||
|
||||||||
import abc | ||||||||
|
||||||||
|
||||||||
from ..photo.repositories import PhotoRepositoryMeta | ||||||||
from ..user.repositories import UserRepositoryMeta | ||||||||
|
||||||||
|
||||||||
class AggregationServiceMeta(metaclass=abc.ABCMeta): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
def __init__(self, user_repository: UserRepositoryMeta, photo_repository: PhotoRepositoryMeta): | ||||||||
self.user_repository: UserRepositoryMeta = user_repository | ||||||||
self.photo_repository: PhotoRepositoryMeta = photo_repository | ||||||||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interfaces generally has no
Suggested change
|
||||||||
|
||||||||
@abc.abstractmethod | ||||||||
def call_user_photo(self): | ||||||||
"""Must be implemented in order to instantiate.""" | ||||||||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""abstraction photo package.""" |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||
"""Photo repositories Meta module.""" | ||||
|
||||
import abc | ||||
|
||||
|
||||
class PhotoRepositoryMeta(metaclass=abc.ABCMeta): | ||||
|
||||
@abc.abstractmethod | ||||
def get_photos(self, user_id): | ||||
"""Must be implemented in order to instantiate.""" | ||||
pass | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Coverage report treats |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""abstraction user package.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""User repositories meta module.""" | ||
|
||
|
||
import abc | ||
|
||
|
||
class UserRepositoryMeta(metaclass=abc.ABCMeta): | ||
|
||
@abc.abstractmethod | ||
def get(self, id): | ||
"""Must be implemented in order to instantiate.""" | ||
pass |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,18 @@ | ||||||||||
"""Analytics services module.""" | ||||||||||
|
||||||||||
|
||||||||||
class AggregationService: | ||||||||||
from ..abstraction.analytics.services import AggregationServiceMeta | ||||||||||
from ..abstraction.photo.repositories import PhotoRepositoryMeta | ||||||||||
from ..abstraction.user.repositories import UserRepositoryMeta | ||||||||||
|
||||||||||
def __init__(self, user_repository, photo_repository): | ||||||||||
self.user_repository = user_repository | ||||||||||
self.photo_repository = photo_repository | ||||||||||
|
||||||||||
class AggregationService(AggregationServiceMeta): | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or
Suggested change
See comment above. This way it would be much more clear about implementation specifics of the |
||||||||||
|
||||||||||
def __init__(self, user_repository: UserRepositoryMeta, photo_repository: PhotoRepositoryMeta): | ||||||||||
self.user_repository: UserRepositoryMeta = user_repository | ||||||||||
self.photo_repository: PhotoRepositoryMeta = photo_repository | ||||||||||
|
||||||||||
def call_user_photo(self): | ||||||||||
user1 = self.user_repository.get(id=1) | ||||||||||
user1_photos = self.photo_repository.get_photos(user1.id) | ||||||||||
print(f"Retrieve user id={user1.id}, photos count={len(user1_photos)} from aggregation service.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For such simple app example, I'd move everything into
interfaces.py
to keep app structure from bloating.