Skip to content

Commit e0454cc

Browse files
committed
а-ля-я тесты и аля рефакторинг
1 parent 4b6cccd commit e0454cc

36 files changed

+317
-361
lines changed

.env.dist

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ APP_TITLE="FastAPI Template"
33
APP_VERSION="1.0.0"
44
APP_SECRET_KEY="123abc"
55

6-
POSTGRES_DB="postgres"
7-
POSTGRES_HOST="postgres"
8-
POSTGRES_PORT=5432
9-
POSTGRES_USER="postgres"
10-
POSTGRES_PASSWORD="postgres"
6+
DB="postgres"
7+
DB_HOST="postgres"
8+
DB_PORT=5432
9+
DB_USER="postgres"
10+
DB_PASSWORD="postgres"
11+
DB_DRIVERNAME="postgresql+asyncpg"

.github/workflows/generate-swagger-and-commit-to-docs.yml

-40
This file was deleted.

.github/workflows/get-tree-and-commit-to-readme.yml

-34
This file was deleted.

.github/workflows/reformat-code-and-commit.yml

-33
This file was deleted.

README.md

+18-73
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,20 @@
1-
# FastAPI
2-
3-
## File Structure
4-
```
5-
.
6-
├── __init__.py
7-
├── api
8-
│   ├── __init__.py
9-
│   ├── deps.py
10-
│   └── v1
11-
│   ├── __init__.py
12-
│   ├── auth
13-
│   │   ├── __init__.py
14-
│   │   └── token.py
15-
│   └── users
16-
│   ├── __init__.py
17-
│   ├── create.py
18-
│   └── retrieve.py
19-
├── core
20-
│   ├── __init__.py
21-
│   ├── db.py
22-
│   ├── exps.py
23-
│   └── settings.py
24-
├── logic
25-
│   ├── __init__.py
26-
│   ├── auth
27-
│   │   ├── __init__.py
28-
│   │   └── auth.py
29-
│   ├── logic.py
30-
│   ├── security
31-
│   │   ├── __init__.py
32-
│   │   ├── jwt.py
33-
│   │   ├── pwd.py
34-
│   │   └── security.py
35-
│   └── users
36-
│   ├── __init__.py
37-
│   └── users.py
38-
├── models
39-
│   ├── __init__.py
40-
│   ├── auth
41-
│   │   ├── __init__.py
42-
│   │   └── token.py
43-
│   ├── base.py
44-
│   ├── types
45-
│   │   ├── __init__.py
46-
│   │   └── unix.py
47-
│   └── users
48-
│   ├── __init__.py
49-
│   └── user.py
50-
└── repositories
51-
├── __init__.py
52-
├── base.py
53-
└── user.py
1+
# FastAPI
542

55-
14 directories, 34 files
56-
```
3+
## Create a `.env` file based on `.env.dist` and make all the necessary customizations
574

58-
## Create a `.env` file based on `.env.dist` and make all the necessary customizations
59-
60-
### To run the application in a docker container, run the command
61-
62-
`docker-compose up -d`
63-
64-
### To run the application without a docker container, complete follow these steps
65-
66-
1. Install dependencies.
67-
68-
`poetry install` or `pip install -r requirements.txt`
69-
2. Run application.
70-
71-
`poetry run fastapi dev app` or `make dev`
72-
73-
### Make documentation
74-
75-
`make help`
5+
### To run the application in a docker container, run the command
6+
7+
`docker-compose up -d`
8+
9+
### To run the application without a docker container, complete follow these steps
10+
11+
1. Install dependencies.
12+
13+
`poetry install` or `pip install -r requirements.txt`
14+
2. Run application.
15+
16+
`poetry run fastapi dev app` or `make dev`
17+
18+
### Make documentation
19+
20+
`make help`

app/api/deps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from fastapi.security import APIKeyHeader
99

1010
from app.logic import Logic as _Logic
11-
from app.models.users.user import User as _User
11+
from app.models.users import User as _User
1212

1313

1414
async def get_logic() -> AsyncGenerator[_Logic, None]:

app/api/v1/auth/token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from app.api import deps
44
from app.models.auth import AccessToken
5-
from app.models.users.user import UserCreate
5+
from app.models.users import UserCreate
66

77
router = APIRouter(prefix='/token')
88

app/api/v1/users/create.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter
22

33
from app.api import deps
4-
from app.models.users.user import UserCreate, UserRead
4+
from app.models.users import UserCreate, UserRead
55

66
router = APIRouter(prefix='/create')
77

app/api/v1/users/retrieve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fastapi import APIRouter
66

77
from app.api import deps
8-
from app.models.users.user import UserRead
8+
from app.models.users import UserRead
99

1010
router = APIRouter()
1111

app/core/db.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(
2424
async def __set_async_engine(self) -> None:
2525
if self.__engine is None:
2626
self.__engine = create_async_engine(
27-
settings.pg_dsn.unicode_string(), echo=False, future=True
27+
settings.db_dsn, echo=False, future=True
2828
)
2929

3030
async def __set_async_session(self) -> None:

app/core/settings.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,39 @@
22
Settings
33
"""
44

5-
from pydantic import PostgresDsn
65
from pydantic_settings import BaseSettings, SettingsConfigDict
6+
from sqlalchemy import URL
77

88

99
class Settings(BaseSettings):
1010
model_config = SettingsConfigDict(
11-
env_file='.env', env_file_encoding='utf-8', case_sensitive=True
11+
env_file=".env", env_file_encoding="utf-8", case_sensitive=True
1212
)
1313

1414
# APP
15-
APP_PATH: str = '/api'
16-
APP_TITLE: str = 'FastAPI Template'
17-
APP_VERSION: str = 'beta'
18-
APP_SECRET_KEY: str = 'abc'
15+
APP_PATH: str = "/api"
16+
APP_TITLE: str = "FastAPI Template"
17+
APP_VERSION: str = "beta"
18+
APP_SECRET_KEY: str = "abc"
1919

2020
# DATABASE
21-
POSTGRES_DB: str = 'postgres'
22-
POSTGRES_HOST: str = '127.0.0.1'
23-
POSTGRES_PORT: int = 5432
24-
POSTGRES_USER: str = 'postgres'
25-
POSTGRES_PASSWORD: str = 'postgres'
21+
DB: str = "postgres"
22+
DB_HOST: str = "localhost"
23+
DB_PORT: int = 5432
24+
DB_USER: str = ""
25+
DB_PASSWORD: str = ""
26+
DB_DRIVERNAME: str = "postgresql+asyncpg"
2627

2728
@property
28-
def pg_dsn(self) -> PostgresDsn:
29-
return PostgresDsn.build(
30-
scheme='postgresql+asyncpg',
31-
username=self.POSTGRES_USER,
32-
password=self.POSTGRES_PASSWORD,
33-
host=self.POSTGRES_HOST,
34-
port=self.POSTGRES_PORT,
35-
path=self.POSTGRES_DB,
36-
)
29+
def db_dsn(self) -> str:
30+
return URL.create(
31+
drivername=self.DB_DRIVERNAME,
32+
username=self.DB_USER,
33+
password=self.DB_PASSWORD,
34+
host=self.DB_HOST,
35+
port=self.DB_PORT,
36+
database=self.DB,
37+
).render_as_string(hide_password=False)
3738

3839

3940
settings = Settings()

app/logic/auth/auth.py renamed to app/logic/auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from app.core import exps
44
from app.models.auth import AccessToken
5-
from app.models.users.user import UserCreate
5+
from app.models.users import UserCreate
66

77
if TYPE_CHECKING:
88
from app.logic import Logic

app/logic/auth/__init__.py

-3
This file was deleted.

app/logic/logic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def __init__(self, db: Database):
1717

1818
@classmethod
1919
@asynccontextmanager
20-
async def create(cls) -> AsyncGenerator['Logic', None]:
20+
async def create(cls) -> AsyncGenerator["Logic", None]:
2121
async with Database() as db:
2222
yield cls(db)

app/logic/users/users.py renamed to app/logic/users.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import TYPE_CHECKING
22

33
from app.core import exps
4-
from app.models.users.user import User, UserCreate
4+
from app.models.users import User, UserCreate
55

66
if TYPE_CHECKING:
77
from app.logic import Logic

app/logic/users/__init__.py

-3
This file was deleted.

app/models/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Database Models Module
33
"""
44

5-
from . import users
5+
from . import auth, users
66

7-
__all__ = [
8-
'users',
9-
]
7+
__all__ = ['users', 'auth']
File renamed without changes.

app/models/auth/__init__.py

-3
This file was deleted.

app/models/base.py

-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,3 @@ class TimestampModel(SQLModel):
3636
nullable=True,
3737
sa_column_kwargs={'onupdate': datetime_utc_now},
3838
)
39-
40-
class Config:
41-
arbitrary_types_allowed = True
File renamed without changes.

app/models/users/__init__.py

-4
This file was deleted.

0 commit comments

Comments
 (0)