enum
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from fastapi import FastAPI
|
||||
from sqlalchemy.ext.asyncio import (AsyncEngine, AsyncSession,
|
||||
async_sessionmaker)
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker
|
||||
|
||||
from api.application.abstractions.transaction import TransactionContextManager
|
||||
from api.application.protocols.date_time import DateTimeProvider
|
||||
@@ -9,27 +8,36 @@ from api.application.protocols.password_hasher import PasswordHasher
|
||||
from api.application.usecase.auth.auth_user import LoginUser
|
||||
from api.application.usecase.auth.create_user import CreateUser
|
||||
from api.application.usecase.company.create_company import CreateCompany
|
||||
from api.application.usecase.company.get_users_company import \
|
||||
GetCompaniesByOwnerEmail
|
||||
from api.application.usecase.company.get_users_company import GetCompaniesByOwnerEmail
|
||||
from api.domain.company.repository import CompanyRepository
|
||||
from api.domain.user.repository import UserRepository
|
||||
from api.infrastructure.auth.jwt_settings import JwtSettings
|
||||
from api.infrastructure.dependencies.adapters import (create_engine,
|
||||
create_session_maker,
|
||||
get_transaction_context,
|
||||
new_session)
|
||||
from api.infrastructure.dependencies.configs import (app_settings,
|
||||
get_db_settings,
|
||||
get_jwt_settings)
|
||||
from api.infrastructure.dependencies.protocols import (get_date_time_provider,
|
||||
get_jwt_token_processor,
|
||||
get_password_hasher,
|
||||
get_user_login)
|
||||
from api.infrastructure.dependencies.adapters import (
|
||||
create_engine,
|
||||
create_session_maker,
|
||||
get_transaction_context,
|
||||
new_session,
|
||||
)
|
||||
from api.infrastructure.dependencies.configs import (
|
||||
app_settings,
|
||||
get_db_settings,
|
||||
get_jwt_settings,
|
||||
)
|
||||
from api.infrastructure.dependencies.protocols import (
|
||||
get_date_time_provider,
|
||||
get_jwt_token_processor,
|
||||
get_password_hasher,
|
||||
get_user_login,
|
||||
)
|
||||
from api.infrastructure.dependencies.repositories import (
|
||||
get_company_repository, get_user_repository)
|
||||
get_company_repository,
|
||||
get_user_repository,
|
||||
)
|
||||
from api.infrastructure.dependencies.usecases import (
|
||||
provide_create_company, provide_create_user,
|
||||
provide_get_companies_by_email)
|
||||
provide_create_company,
|
||||
provide_create_user,
|
||||
provide_get_companies_by_email,
|
||||
)
|
||||
from api.infrastructure.persistence.db_setings import DBSettings
|
||||
from api.infrastructure.settings import Settings
|
||||
|
||||
|
@@ -2,27 +2,23 @@ from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from api.domain.error import DomainValidationError
|
||||
from api.domain.user.error import (UserAlreadyExistsError,
|
||||
UserInvalidCredentialsError,
|
||||
UserIsNotAuthorizedError)
|
||||
from api.domain.user.error import (
|
||||
UserAlreadyExistsError,
|
||||
UserInvalidCredentialsError,
|
||||
UserIsNotAuthorizedError,
|
||||
)
|
||||
from api.infrastructure.persistence.error import TransactionContextManagerError
|
||||
|
||||
|
||||
async def transaction_error_exec_handler(
|
||||
request: Request, exc: TransactionContextManagerError
|
||||
) -> JSONResponse:
|
||||
async def transaction_error_exec_handler(request: Request, exc: TransactionContextManagerError) -> JSONResponse:
|
||||
return JSONResponse(status_code=400, content={"detail": exc.message})
|
||||
|
||||
|
||||
async def validation_error_exc_handler(
|
||||
request: Request, exc: DomainValidationError
|
||||
) -> JSONResponse:
|
||||
async def validation_error_exc_handler(request: Request, exc: DomainValidationError) -> JSONResponse:
|
||||
return JSONResponse(status_code=400, content={"detail": exc.message})
|
||||
|
||||
|
||||
async def user_authentication_error_exc_handler(
|
||||
request: Request, exc: UserIsNotAuthorizedError
|
||||
) -> JSONResponse:
|
||||
async def user_authentication_error_exc_handler(request: Request, exc: UserIsNotAuthorizedError) -> JSONResponse:
|
||||
return JSONResponse(
|
||||
status_code=401,
|
||||
content={"detail": exc.message},
|
||||
@@ -30,9 +26,7 @@ async def user_authentication_error_exc_handler(
|
||||
)
|
||||
|
||||
|
||||
async def user_already_exist_error_exc_handler(
|
||||
request: Request, exc: UserAlreadyExistsError
|
||||
) -> JSONResponse:
|
||||
async def user_already_exist_error_exc_handler(request: Request, exc: UserAlreadyExistsError) -> JSONResponse:
|
||||
return JSONResponse(status_code=409, content={"detail": exc.message})
|
||||
|
||||
|
||||
@@ -47,16 +41,8 @@ def init_exc_handlers(app: FastAPI) -> None:
|
||||
DomainValidationError,
|
||||
validation_error_exc_handler,
|
||||
)
|
||||
app.add_exception_handler(
|
||||
UserIsNotAuthorizedError, user_authentication_error_exc_handler
|
||||
)
|
||||
app.add_exception_handler(
|
||||
UserAlreadyExistsError, user_already_exist_error_exc_handler
|
||||
)
|
||||
app.add_exception_handler(
|
||||
UserInvalidCredentialsError, user_invalid_credentials_error_exc_handler
|
||||
)
|
||||
app.add_exception_handler(UserIsNotAuthorizedError, user_authentication_error_exc_handler)
|
||||
app.add_exception_handler(UserAlreadyExistsError, user_already_exist_error_exc_handler)
|
||||
app.add_exception_handler(UserInvalidCredentialsError, user_invalid_credentials_error_exc_handler)
|
||||
|
||||
app.add_exception_handler(
|
||||
TransactionContextManagerError, transaction_error_exec_handler
|
||||
)
|
||||
app.add_exception_handler(TransactionContextManagerError, transaction_error_exec_handler)
|
||||
|
@@ -8,9 +8,11 @@ from api.app_entrypoint.dependencies import init_dependencies
|
||||
from api.app_entrypoint.error_handlers import init_exc_handlers
|
||||
from api.infrastructure.auth.jwt_settings import JwtSettings
|
||||
from api.infrastructure.dependencies.adapters import create_engine
|
||||
from api.infrastructure.dependencies.configs import (app_settings,
|
||||
get_db_settings,
|
||||
get_jwt_settings)
|
||||
from api.infrastructure.dependencies.configs import (
|
||||
app_settings,
|
||||
get_db_settings,
|
||||
get_jwt_settings,
|
||||
)
|
||||
from api.infrastructure.persistence.db_setings import DBSettings
|
||||
from api.infrastructure.persistence.models import Base
|
||||
from api.infrastructure.settings import Settings
|
||||
|
Reference in New Issue
Block a user