feat: done setup dependencies injection for auth
This commit is contained in:
parent
c40fd7a3c9
commit
b53e5f4cb6
|
@ -1,3 +1,4 @@
|
|||
import sys
|
||||
from flask import Blueprint
|
||||
from controllers import AuthController
|
||||
from di_container import Container
|
||||
|
@ -10,6 +11,7 @@ auth_blueprint = Blueprint("auth", __name__)
|
|||
@auth_blueprint.route("/register", methods=["POST"])
|
||||
@inject
|
||||
def register(auth_controller: AuthController = Provide[Container.auth_controller]):
|
||||
print(auth_controller.test(), file=sys.stderr)
|
||||
return auth_controller.register()
|
||||
|
||||
|
||||
|
|
|
@ -18,3 +18,12 @@ class AuthController:
|
|||
"data": users,
|
||||
}
|
||||
return jsonify(response)
|
||||
|
||||
def register(self):
|
||||
return jsonify({"message": "register"})
|
||||
|
||||
def logout(self):
|
||||
return jsonify({"message": "logout"})
|
||||
|
||||
def test(self):
|
||||
return "test"
|
||||
|
|
|
@ -9,18 +9,12 @@ class Container(containers.DeclarativeContainer):
|
|||
"""Dependency Injection Container"""
|
||||
|
||||
mongo = providers.Dependency()
|
||||
# repository
|
||||
user_repository = providers.Factory(UserRepository, mongo.provided.db)
|
||||
|
||||
user_repository = providers.Factory(
|
||||
UserRepository,
|
||||
mongo.provided.db,
|
||||
)
|
||||
# services
|
||||
auth_service = providers.Factory(AuthService, user_repository)
|
||||
user_service = providers.Factory(UserService, user_repository)
|
||||
|
||||
auth_service = providers.Factory(
|
||||
AuthService,
|
||||
user_repository,
|
||||
)
|
||||
|
||||
auth_controller = providers.Factory(
|
||||
AuthController,
|
||||
AuthService,
|
||||
)
|
||||
# controllers
|
||||
auth_controller = providers.Factory(AuthController, auth_service, user_service)
|
||||
|
|
|
@ -17,6 +17,8 @@ def createApp() -> Flask:
|
|||
if mongo is not None:
|
||||
container.mongo.override(mongo)
|
||||
|
||||
container.wire(modules=["blueprints.auth"])
|
||||
|
||||
# Register Blueprints
|
||||
app.register_blueprint(default_blueprint)
|
||||
app.register_blueprint(auth_blueprint, url_prefix="/api")
|
||||
|
|
|
@ -2,8 +2,8 @@ from repositories import UserRepository
|
|||
|
||||
|
||||
class UserService:
|
||||
def __init__(self):
|
||||
self.user_repository = UserRepository()
|
||||
def __init__(self, user_repository: UserRepository):
|
||||
self.user_repository = user_repository
|
||||
|
||||
def get_all_users(self):
|
||||
return self.user_repository.get_all_users()
|
||||
|
|
Loading…
Reference in New Issue