-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Xenia101/feature/refactor-by-xenia101
Refactoring 🦥
- Loading branch information
Showing
8 changed files
with
53 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,43 @@ | ||
from typing import Any, Protocol | ||
|
||
|
||
class RepositoryProtocol(Protocol): | ||
def read_by_options(self, schema: Any) -> Any: ... | ||
|
||
def read_by_id(self, id: int) -> Any: ... | ||
|
||
def create(self, schema: Any) -> Any: ... | ||
|
||
def update(self, id: int, schema: Any) -> Any: ... | ||
|
||
def update_attr(self, id: int, attr: str, value: Any) -> Any: ... | ||
|
||
def whole_update(self, id: int, schema: Any) -> Any: ... | ||
|
||
def delete_by_id(self, id: int) -> Any: ... | ||
|
||
|
||
class BaseService: | ||
def __init__(self, repository) -> None: | ||
def __init__(self, repository: RepositoryProtocol) -> None: | ||
self._repository = repository | ||
|
||
def get_list(self, schema): | ||
def get_list(self, schema: Any) -> Any: | ||
return self._repository.read_by_options(schema) | ||
|
||
def get_by_id(self, id: int): | ||
def get_by_id(self, id: int) -> Any: | ||
return self._repository.read_by_id(id) | ||
|
||
def add(self, schema): | ||
def add(self, schema: Any) -> Any: | ||
return self._repository.create(schema) | ||
|
||
def patch(self, id: int, schema): | ||
def patch(self, id: int, schema: Any) -> Any: | ||
return self._repository.update(id, schema) | ||
|
||
def patch_attr(self, id: int, attr: str, value): | ||
def patch_attr(self, id: int, attr: str, value: Any) -> Any: | ||
return self._repository.update_attr(id, attr, value) | ||
|
||
def put_update(self, id: int, schema): | ||
def put_update(self, id: int, schema: Any) -> Any: | ||
return self._repository.whole_update(id, schema) | ||
|
||
def remove_by_id(self, id): | ||
def remove_by_id(self, id: int) -> Any: | ||
return self._repository.delete_by_id(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
from pytz import timezone | ||
|
||
|
||
def get_now(): | ||
def get_now() -> datetime: | ||
return datetime.now(tz=timezone("UTC")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import uuid | ||
|
||
|
||
def get_rand_hash(length=16): | ||
def get_rand_hash(length: int = 16) -> str: | ||
return uuid.uuid4().hex[:length] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters