-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathcreate_user.py
More file actions
46 lines (40 loc) · 1.65 KB
/
create_user.py
File metadata and controls
46 lines (40 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from inspect import getdoc
from dishka import FromDishka
from dishka.integrations.fastapi import inject
from fastapi import APIRouter
from fastapi_error_map import ErrorAwareRouter
from starlette import status
from app.core.commands.create_user import CreateUser, CreateUserRequest, CreateUserResponse
from app.core.commands.exceptions import (
UsernameAlreadyExistsError,
)
from app.core.common.authorization.exceptions import AuthorizationError
from app.core.common.exceptions import BusinessTypeError
from app.inbound.http.errors.callbacks import log_info
from app.inbound.http.errors.rules import HTTP_503_SERVICE_UNAVAILABLE_RULE
from app.outbound.adapters.exceptions import PasswordHasherBusyError
from app.outbound.auth_ctx.exceptions import AuthenticationError
from app.outbound.exceptions import StorageError
def make_create_user_router() -> APIRouter:
router = ErrorAwareRouter()
@router.post(
"/",
error_map={
AuthenticationError: status.HTTP_401_UNAUTHORIZED,
StorageError: HTTP_503_SERVICE_UNAVAILABLE_RULE,
AuthorizationError: status.HTTP_403_FORBIDDEN,
BusinessTypeError: status.HTTP_400_BAD_REQUEST,
PasswordHasherBusyError: HTTP_503_SERVICE_UNAVAILABLE_RULE,
UsernameAlreadyExistsError: status.HTTP_409_CONFLICT,
},
default_on_error=log_info,
status_code=status.HTTP_201_CREATED,
description=getdoc(CreateUser),
)
@inject
async def create_user(
request: CreateUserRequest,
interactor: FromDishka[CreateUser],
) -> CreateUserResponse:
return await interactor.execute(request)
return router