Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77902bc

Browse files
0.0.1
1 parent 39c63ce commit 77902bc

File tree

35 files changed

+467
-1835
lines changed

35 files changed

+467
-1835
lines changed

‎app/__init__.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Init App Module
3-
"""
1+
import os
42

53
from fastapi import FastAPI
64
from fastapi.responses import JSONResponse
@@ -9,14 +7,16 @@
97
from app.core import exps
108
from app.core.settings import settings
119

10+
os.environ["TZ"] = "UTC"
11+
1212
app = FastAPI(
13-
title=settings.APP_TITLE,
14-
root_path=settings.APP_PATH,
15-
version=settings.APP_VERSION,
13+
title=settings.app_title,
14+
root_path=settings.app_path,
15+
version=settings.app_version,
1616
contact={
17-
'name': 'Fast Code',
18-
'url': 'https://fast-code.pro/',
19-
'email': 'fast.code.auth@gmail.com',
17+
"name": "Fast Code",
18+
"url": "https://fast-code.pro/",
19+
"email": "fast.code.auth@gmail.com",
2020
},
2121
)
2222

@@ -27,5 +27,5 @@
2727
async def exception_handler(request, exc: exps.CustomException):
2828
return JSONResponse(
2929
status_code=exc.status_code,
30-
content={'detail': exc.message},
30+
content={"detail": exc.message},
3131
)

‎app/api/deps.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
from typing import Annotated, AsyncGenerator
66

77
from fastapi import Depends
8-
from fastapi.security import APIKeyHeader
8+
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
99

1010
from app.logic import Logic as _Logic
11-
from app.models.users import User as _User
11+
from app.models.user import User as _User
12+
13+
14+
security = HTTPBearer()
1215

1316

1417
async def get_logic() -> AsyncGenerator[_Logic, None]:
@@ -20,10 +23,10 @@ async def get_logic() -> AsyncGenerator[_Logic, None]:
2023

2124

2225
async def get_user(
23-
token: Annotated[str, Depends(APIKeyHeader(name='access-token'))],
26+
creds: Annotated[HTTPAuthorizationCredentials, Depends(security)],
2427
logic: Logic,
2528
) -> _User | None:
26-
return await logic.users.retrieve_by_token(token)
29+
return await logic.user.retrieve_by_token(creds.credentials)
2730

2831

2932
User = Annotated[_User, Depends(get_user)]

‎app/api/v1/__init__.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
from fastapi import APIRouter
88

9-
from . import auth, users
9+
from . import auth, user
1010

11-
FOLDER_NAME = f'{Path(__file__).parent.name}'
11+
FOLDER_NAME = f"{Path(__file__).parent.name}"
1212

13-
router = APIRouter(prefix=f'/{FOLDER_NAME}', tags=[FOLDER_NAME])
13+
router = APIRouter(prefix=f"/{FOLDER_NAME}", tags=[FOLDER_NAME])
1414
router.include_router(auth.router)
15-
router.include_router(users.router)
15+
router.include_router(user.router)
1616

17-
__all__ = ['router']
17+
__all__ = ["router"]

‎app/api/v1/auth.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fastapi import APIRouter
2+
3+
from app.api import deps
4+
from app.models import auth as auth_models
5+
from app.models import user as user_models
6+
7+
router = APIRouter(prefix="/auth")
8+
9+
10+
@router.post("/token", response_model=auth_models.AccessToken)
11+
async def token(data: user_models.UserCreate, logic: deps.Logic):
12+
"""
13+
Retrieve new access token
14+
"""
15+
return await logic.auth.generate_token(data)

‎app/api/v1/auth/__init__.py‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎app/api/v1/auth/token.py‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎app/api/v1/user.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from fastapi import APIRouter
2+
3+
from app.api import deps
4+
from app.models import user as user_models
5+
6+
router = APIRouter(prefix="/users")
7+
8+
9+
@router.post("", response_model=user_models.UserRetrieve)
10+
async def create(data: user_models.UserCreate, logic: deps.Logic):
11+
"""
12+
Create user
13+
"""
14+
return await logic.user.create(data)
15+
16+
17+
@router.get("", response_model=user_models.UserRetrieve)
18+
async def retrieve(user: deps.User):
19+
"""
20+
Retrieve user
21+
"""
22+
return user

‎app/api/v1/users/__init__.py‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎app/api/v1/users/create.py‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎app/api/v1/users/retrieve.py‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /