generated from Maua-Dev/battlesnake_fastapi_template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #5 from Maua-Dev/add-repo
Add repo to the template
- Loading branch information
Showing
9 changed files
with
350 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
from enum import Enum | ||
import os | ||
|
||
from .errors.environment_errors import EnvironmentNotFound | ||
|
||
from .repo.item_repository_interface import IItemRepository | ||
|
||
|
||
class STAGE(Enum): | ||
DOTENV = "DOTENV" | ||
DEV = "DEV" | ||
PROD = "PROD" | ||
TEST = "TEST" | ||
|
||
|
||
class Environments: | ||
""" | ||
Defines the environment variables for the application. You should not instantiate this class directly. Please use Environments.get_envs() method instead. | ||
Usage: | ||
""" | ||
stage: STAGE | ||
|
||
def _configure_local(self): | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
os.environ["STAGE"] = os.environ.get("STAGE") or STAGE.TEST.value | ||
|
||
def load_envs(self): | ||
if "STAGE" not in os.environ or os.environ["STAGE"] == STAGE.DOTENV.value: | ||
self._configure_local() | ||
|
||
self.stage = STAGE[os.environ.get("STAGE")] | ||
|
||
@staticmethod | ||
def get_item_repo() -> IItemRepository: | ||
if Environments.get_envs().stage == STAGE.TEST: | ||
from .repo.item_repository_mock import ItemRepositoryMock | ||
return ItemRepositoryMock | ||
# use "elif" conditional to add other stages | ||
else: | ||
raise EnvironmentNotFound("STAGE") | ||
|
||
|
||
@staticmethod | ||
def get_envs() -> "Environments": | ||
""" | ||
Returns the Environments object. This method should be used to get the Environments object instead of instantiating it directly. | ||
:return: Environments (stage={self.stage}) | ||
""" | ||
envs = Environments() | ||
envs.load_envs() | ||
return envs | ||
|
||
def __repr__(self): | ||
return self.__dict__ |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .base_error import BaseError | ||
|
||
|
||
class EnvironmentNotFound(BaseError): | ||
def __init__(self, env: str): | ||
super().__init__(f'The environment {env} is wrong') |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List, Optional, Tuple | ||
|
||
from ..enums.item_type_enum import ItemTypeEnum | ||
|
||
from ..entities.item import Item | ||
|
||
|
||
class IItemRepository(ABC): | ||
|
||
|
||
@abstractmethod | ||
def get_all_items(self) -> List[Item]: | ||
''' | ||
Returns all the itens in the database | ||
''' | ||
pass | ||
|
||
@abstractmethod | ||
def get_item(self, item_id: int) -> Optional[Item]: | ||
''' | ||
Returns the item with the given id. | ||
If the item does not exist, returns None | ||
''' | ||
pass | ||
|
||
@abstractmethod | ||
def create_item(self, item: Item, item_id: int) -> Item: | ||
''' | ||
Creates a new item in the database | ||
''' | ||
pass | ||
|
||
@abstractmethod | ||
def delete_item(self, item_id: int) -> Item: | ||
''' | ||
Deletes the item with the given id. | ||
If the item does not exist, returns None | ||
''' | ||
|
||
@abstractmethod | ||
def update_item(self, item_id:int, name:str=None, price:float=None, item_type:ItemTypeEnum=None, admin_permission:bool=None) -> Item: | ||
''' | ||
Updates the item with the given id. | ||
If the item does not exist, returns None | ||
''' | ||
pass | ||
|
||
|
Oops, something went wrong.