-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fc9d68
commit bc1a01c
Showing
13 changed files
with
188 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
from src.apps.backoffice.boot import boot | ||
import argparse | ||
|
||
from src.apps.backoffice.boot import boot as boot_backoffice | ||
from src.apps.photostore.boot import boot as boot_photostore | ||
|
||
|
||
service_mapping = { | ||
'backoffice': boot_backoffice, | ||
'photostore': boot_photostore, | ||
} | ||
|
||
if __name__ == "__main__": | ||
print("Booting backoffice server!") | ||
boot() | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'--service', | ||
type=str, | ||
nargs='?', | ||
help='Service to run must be one of ["backoffice", "photostore"]', | ||
) | ||
params = vars(parser.parse_args()) | ||
service_name = params['service'] | ||
service_booter = service_mapping[service_name] | ||
|
||
print(f'Booting {service_name} server') | ||
service_booter() | ||
print(f'{service_name} server start success') |
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,16 @@ | ||
import uvicorn | ||
|
||
from src.apps.backoffice.BackofficeApp import BackofficeApp | ||
from src.contexts.shared.Infrastructure.environment.EnvManager import EnvManager | ||
from src.contexts.shared.Infrastructure.environment.EnvVar import EnvVar | ||
|
||
|
||
class PhotoStoreServer: | ||
|
||
def __init__(self): | ||
self.app = BackofficeApp() | ||
|
||
def run(self): | ||
host = EnvManager.get(EnvVar.PHOTOSTORE_SERVER_HOST) | ||
port = EnvManager.get(EnvVar.PHOTOSTORE_SERVER_PORT, parser=int) | ||
uvicorn.run(self.app.get_runnable(), host=host, port=port) |
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,15 @@ | ||
from fastapi import FastAPI, APIRouter | ||
|
||
from src.apps.photostore.routes import register_routes | ||
|
||
|
||
class PhotoStoreApp: | ||
|
||
def __init__(self): | ||
self.__app: FastAPI = FastAPI() | ||
router: APIRouter = APIRouter() | ||
register_routes(router) | ||
self.__app.include_router(router, prefix='/api') | ||
|
||
def get_runnable(self): | ||
return self.__app |
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 src.apps.photostore.PhotoStoreServer import PhotoStoreServer | ||
|
||
|
||
def boot(): | ||
server = PhotoStoreServer() | ||
server.run() |
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,11 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from fastapi import Request | ||
from fastapi.responses import JSONResponse | ||
|
||
|
||
class PhotoStoreController(ABC): | ||
|
||
@abstractmethod | ||
async def run(self, req: Request) -> JSONResponse: | ||
raise NotImplementedError() |
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,14 @@ | ||
from starlette.requests import Request | ||
from starlette.responses import JSONResponse | ||
from http import HTTPStatus | ||
|
||
from src.apps.photostore.controllers.PhotoStoreController import PhotoStoreController | ||
|
||
|
||
class StatusGetController(PhotoStoreController): | ||
|
||
def __init__(self): | ||
pass | ||
|
||
async def run(self, req: Request) -> JSONResponse: | ||
return JSONResponse(status_code=HTTPStatus.OK) |
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,35 @@ | ||
from dependency_injector import containers, providers | ||
|
||
from src.apps.backoffice.controllers.StatusGetController import StatusGetController | ||
from src.contexts.backoffice.users.application.createone.CreateUserCommandHandler import CreateUserCommandHandler | ||
from src.contexts.backoffice.users.application.createone.UserCreator import UserCreator | ||
from src.contexts.photostore.photo.infrastructure.persistence.MinioPhotoStorePhotoRepository import MinioPhotoRepository | ||
from src.contexts.photostore.photo.infrastructure.persistence.config.MinioPhotoConfigFactory import \ | ||
MinioPhotoConfigFactory | ||
from src.contexts.shared.Infrastructure.eventbus.InMemoryEventBus import InMemoryEventBus | ||
from src.contexts.shared.Infrastructure.persistence.minio.MinioClientFactory import MinioClientFactory | ||
|
||
|
||
class PhotoStoreContainer(containers.DeclarativeContainer): | ||
|
||
event_bus = providers.Singleton( | ||
InMemoryEventBus, | ||
) | ||
|
||
db_config = providers.Singleton(MinioPhotoConfigFactory.create) | ||
db_client = providers.Singleton(MinioClientFactory.create_instance, 'photostore', db_config) | ||
|
||
user_repository = providers.Singleton(MinioPhotoRepository, db_client) | ||
|
||
user_creator = providers.Singleton(UserCreator, user_repository, event_bus) | ||
create_user_command_handler = providers.Singleton( | ||
CreateUserCommandHandler, | ||
user_creator, | ||
) | ||
|
||
status_get_controller = providers.Singleton(StatusGetController) | ||
|
||
|
||
backoffice_container: PhotoStoreContainer = PhotoStoreContainer() | ||
|
||
|
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,7 @@ | ||
from fastapi import APIRouter | ||
|
||
from src.apps.photostore.routes.status_routes import register as register_status_routes | ||
|
||
|
||
def register_routes(router: APIRouter): | ||
register_status_routes(router) |
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,18 @@ | ||
import sys | ||
|
||
from dependency_injector.wiring import inject, Provide | ||
from fastapi import APIRouter | ||
|
||
from src.apps.photostore.controllers.StatusGetController import StatusGetController | ||
from src.apps.backoffice.dependencies.BackofficeContainer import BackofficeContainer, backoffice_container | ||
|
||
|
||
@inject | ||
def register( | ||
router: APIRouter, | ||
status_get_controller: StatusGetController = Provide[BackofficeContainer.status_get_controller] | ||
): | ||
router.add_route('/status', status_get_controller.run) | ||
|
||
|
||
backoffice_container.wire(modules=[sys.modules[__name__]]) |
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
31 changes: 31 additions & 0 deletions
31
src/contexts/shared/Infrastructure/persistence/minio/MinioClientFactory.py
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,31 @@ | ||
from typing import Dict, Optional | ||
|
||
from minio import Minio | ||
|
||
from src.contexts.shared.Infrastructure.persistence.minio.MinioConfiguration import MinioConfiguration | ||
from src.contexts.shared.Infrastructure.persistence.mongo.PyMongoConfiguration import PyMongoConfiguration | ||
|
||
|
||
class MinioClientFactory: | ||
|
||
__clients: Dict[str, Minio] = {} | ||
|
||
@staticmethod | ||
def __get_client(context_name: str): | ||
return MinioClientFactory.__clients.get(context_name) | ||
|
||
@staticmethod | ||
def __add_client(context_name: str, client: Minio): | ||
MinioClientFactory.__clients[context_name] = client | ||
|
||
@staticmethod | ||
def create_instance(context_name: str, config: Optional[PyMongoConfiguration] = None): | ||
client = MinioClientFactory.__get_client(context_name) | ||
if client is not None: | ||
return client | ||
|
||
if config is None: | ||
config = MinioConfiguration() | ||
client = config.create_client_from_config() | ||
MinioClientFactory.__add_client(context_name, client) | ||
return client |