user-registration-fastapi 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- user_registration_fastapi/__init__.py +17 -0
- user_registration_fastapi/dependencies.py +21 -0
- user_registration_fastapi/router.py +51 -0
- user_registration_fastapi/schemas.py +23 -0
- user_registration_fastapi-0.1.0.dist-info/METADATA +13 -0
- user_registration_fastapi-0.1.0.dist-info/RECORD +7 -0
- user_registration_fastapi-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from user_registration_fastapi.dependencies import (
|
|
2
|
+
RegistrationServiceDependency,
|
|
3
|
+
get_registration_service,
|
|
4
|
+
)
|
|
5
|
+
from user_registration_fastapi.router import router
|
|
6
|
+
from user_registration_fastapi.schemas import (
|
|
7
|
+
RegisterUserRequest,
|
|
8
|
+
RegisterUserResponse,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"router",
|
|
13
|
+
"get_registration_service",
|
|
14
|
+
"RegistrationServiceDependency",
|
|
15
|
+
"RegisterUserRequest",
|
|
16
|
+
"RegisterUserResponse",
|
|
17
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
from fastapi import Depends
|
|
6
|
+
|
|
7
|
+
from user_registration.registration import RegistrationService
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_registration_service() -> RegistrationService:
|
|
11
|
+
"""
|
|
12
|
+
Application must override this dependency.
|
|
13
|
+
The adapter does not know how the repository, hasher, validator, or database are configured.
|
|
14
|
+
"""
|
|
15
|
+
raise RuntimeError("RegistrationService dependency has not been configured")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
RegistrationServiceDependency = Annotated[
|
|
19
|
+
RegistrationService,
|
|
20
|
+
Depends(get_registration_service)
|
|
21
|
+
]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, HTTPException, status
|
|
4
|
+
|
|
5
|
+
from user_registration.models import RegistrationRequest
|
|
6
|
+
from user_registration.registration import RegistrationStatus
|
|
7
|
+
|
|
8
|
+
from user_registration_fastapi.dependencies import RegistrationServiceDependency
|
|
9
|
+
from user_registration_fastapi.schemas import RegisterUserRequest, RegisterUserResponse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
router = APIRouter(prefix="/users", tags=["users"])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@router.post("/register", response_model=RegisterUserResponse, status_code=status.HTTP_201_CREATED)
|
|
16
|
+
def register_user(payload: RegisterUserRequest, service: RegistrationServiceDependency) -> RegisterUserResponse:
|
|
17
|
+
result = service.register(
|
|
18
|
+
RegistrationRequest(
|
|
19
|
+
username=payload.username,
|
|
20
|
+
email=payload.email,
|
|
21
|
+
password=payload.password
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if result.status is RegistrationStatus.VALIDATION_ERROR:
|
|
26
|
+
raise HTTPException(
|
|
27
|
+
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
|
28
|
+
detail=list(result.errors)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if result.status is RegistrationStatus.DUPLICATE:
|
|
32
|
+
raise HTTPException(
|
|
33
|
+
status_code=status.HTTP_409_CONFLICT,
|
|
34
|
+
detail=list(result.errors)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
if result.status is RegistrationStatus.PERSISTENCE_ERROR:
|
|
38
|
+
raise HTTPException(
|
|
39
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
40
|
+
detail="Unable to register user"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
if result.user_id is None:
|
|
44
|
+
raise HTTPException(
|
|
45
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
46
|
+
detail="Registration completed without a user ID"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return RegisterUserResponse(
|
|
50
|
+
user_id=result.user_id
|
|
51
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RegisterUserRequest(BaseModel):
|
|
9
|
+
"""
|
|
10
|
+
HTTP representation of RegistrationRequest
|
|
11
|
+
"""
|
|
12
|
+
model_config = ConfigDict(extra="forbid")
|
|
13
|
+
|
|
14
|
+
username: str = Field(min_length=1, max_length=50)
|
|
15
|
+
email: str = Field(min_length=3, max_length=320)
|
|
16
|
+
password: str = Field(min_length=1)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RegisterUserResponse(BaseModel):
|
|
20
|
+
"""
|
|
21
|
+
HTTP representation of a successful registration.
|
|
22
|
+
"""
|
|
23
|
+
user_id: UUID
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: user-registration-fastapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: FastAPI adapter for user-registration.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: fastapi<1.0,>=0.115
|
|
7
|
+
Requires-Dist: user-registration<1.0.0,>=0.1.0
|
|
8
|
+
Provides-Extra: dev
|
|
9
|
+
Requires-Dist: httpx<1.0,>=0.28; extra == 'dev'
|
|
10
|
+
Requires-Dist: mypy>=1.13; extra == 'dev'
|
|
11
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
12
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
13
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
user_registration_fastapi/__init__.py,sha256=wY0pB-_bO9dGd0mK2cXltnPnJlUwayB_C87OnGVpRQE,426
|
|
2
|
+
user_registration_fastapi/dependencies.py,sha256=mAx_O0yz0lJzBMBYttUKgqytSZzcgPiLOPlQGqeoRWM,567
|
|
3
|
+
user_registration_fastapi/router.py,sha256=5qJOfBVxSmoyk5nixDwnyFArVKlkUxvBONJTmbqgUnc,1697
|
|
4
|
+
user_registration_fastapi/schemas.py,sha256=1kF5zE0El83vtFXnvG_l6mXutCNBrqbm13Yi7JI3pZ0,536
|
|
5
|
+
user_registration_fastapi-0.1.0.dist-info/METADATA,sha256=Uq3sEtYoqrJNE90Dui2DeKS7lz5LTCv-WFPetjVw6pY,464
|
|
6
|
+
user_registration_fastapi-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
7
|
+
user_registration_fastapi-0.1.0.dist-info/RECORD,,
|