Skip to content

Commit 0234a91

Browse files
committed
docs updated, mypy types fixed
1 parent bcebc43 commit 0234a91

File tree

9 files changed

+45
-45
lines changed

9 files changed

+45
-45
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ So you may skip to [5. Extending](#5-extending).
269269
### 4.2 From Scratch
270270

271271
#### 4.2.1. Packages
272-
In the `src` directory, run to install required packages:
272+
In the `root` directory (`FastAPI-boilerplate` if you didn't change anything), run to install required packages:
273273
```sh
274274
poetry install
275275
```
@@ -330,9 +330,9 @@ redis:alpine
330330
```
331331

332332
#### 4.2.4. Running the API
333-
While in the `src` folder, run to start the application with uvicorn server:
333+
While in the `root` folder, run to start the application with uvicorn server:
334334
```sh
335-
poetry run uvicorn app.main:app --reload
335+
poetry run uvicorn src.app.main:app --reload
336336
```
337337
> [!TIP]
338338
> The --reload flag enables auto-reload once you change (and save) something in the project
@@ -345,7 +345,7 @@ poetry run uvicorn app.main:app --reload
345345
346346
If you are using docker compose, you should uncomment this part of the docker-compose.yml:
347347
```
348-
# #-------- uncomment to create first superuser --------
348+
#-------- uncomment to create first superuser --------
349349
# create_superuser:
350350
# build:
351351
# context: .
@@ -391,9 +391,9 @@ docker-compose stop create_superuser
391391
```
392392

393393
#### 4.3.2 From Scratch
394-
While in the `src` folder, run (after you started the application at least once to create the tables):
394+
While in the `root` folder, run (after you started the application at least once to create the tables):
395395
```sh
396-
poetry run python -m scripts.create_first_superuser
396+
poetry run python -m src.scripts.create_first_superuser
397397
```
398398

399399
### 4.3.3 Creating the first tier
@@ -1139,9 +1139,9 @@ async def get_task(task_id: str):
11391139
And finally run the worker in parallel to your fastapi application.
11401140

11411141
If you are using `docker compose`, the worker is already running.
1142-
If you are doing it from scratch, run while in the `src` folder:
1142+
If you are doing it from scratch, run while in the `root` folder:
11431143
```sh
1144-
poetry run arq app.worker.WorkerSettings
1144+
poetry run arq src.app.worker.WorkerSettings
11451145
```
11461146
### 5.11 Rate Limiting
11471147
To limit how many times a user can make a request in a certain interval of time (very useful to create subscription plans or just to protect your API against DDOS), you may just use the `rate_limiter` dependency:
@@ -1301,14 +1301,14 @@ docker compose up
13011301
```
13021302

13031303
If you are doing it from scratch, ensure your postgres and your redis are running, then
1304-
while in the `src` folder, run to start the application with uvicorn server:
1304+
while in the `root` folder, run to start the application with uvicorn server:
13051305
```sh
1306-
poetry run uvicorn app.main:app --reload
1306+
poetry run uvicorn src.app.main:app --reload
13071307
```
13081308

13091309
And for the worker:
13101310
```sh
1311-
poetry run arq app.worker.WorkerSettings
1311+
poetry run arq src.app.worker.WorkerSettings
13121312
```
13131313

13141314
## 6. Running in Production
@@ -1366,7 +1366,7 @@ To run with NGINX, you start by uncommenting the following part in your `docker-
13661366
# docker-compose.yml
13671367

13681368
...
1369-
# #-------- uncomment to run with nginx --------
1369+
#-------- uncomment to run with nginx --------
13701370
# nginx:
13711371
# image: nginx:latest
13721372
# ports:
@@ -1501,20 +1501,20 @@ Now, to run:
15011501
### 7.1 Docker Compose
15021502
First you need to uncomment the following part in the `docker-compose.yml` file:
15031503
```
1504-
# #-------- uncomment to run tests --------
1504+
#-------- uncomment to run tests --------
15051505
# pytest:
15061506
# build:
15071507
# context: .
15081508
# dockerfile: Dockerfile
15091509
# env_file:
1510-
# - ./src/.env
1510+
# - ./src/.env
15111511
# depends_on:
15121512
# - db
15131513
# - create_superuser
15141514
# - redis
1515-
# command: python -m pytest
1515+
# command: python -m pytest ./tests
15161516
# volumes:
1517-
# - ./src:/code/src
1517+
# - .:/code
15181518
```
15191519

15201520
You'll get:
@@ -1525,14 +1525,14 @@ You'll get:
15251525
context: .
15261526
dockerfile: Dockerfile
15271527
env_file:
1528-
- ./src/.env
1528+
- ./src/.env
15291529
depends_on:
15301530
- db
15311531
- create_superuser
15321532
- redis
1533-
command: python -m pytest
1533+
command: python -m pytest ./tests
15341534
volumes:
1535-
- ./src:/code/src
1535+
- .:/code
15361536
```
15371537

15381538
Start the Docker Compose services:
@@ -1548,7 +1548,7 @@ docker-compose run --rm pytest
15481548

15491549
### 7.2 From Scratch
15501550

1551-
While in the `src` folder, run:
1551+
While in the `root` folder, run:
15521552
```sh
15531553
poetry run python -m pytest
15541554
```
@@ -1557,7 +1557,7 @@ poetry run python -m pytest
15571557
Contributions are appreciated, even if just reporting bugs, documenting stuff or answering questions. To contribute with a feature:
15581558
1. Fork it (https://github.com/igormagalhaesr/FastAPI-boilerplate)
15591559
2. Create your feature branch (`git checkout -b feature/fooBar`)
1560-
3. Test your changes while in the src folder `poetry run python -m pytest`
1560+
3. Test your changes while in the root folder `poetry run python -m pytest`
15611561
4. Commit your changes (`git commit -am 'Add some fooBar'`)
15621562
5. Push to the branch (`git push origin feature/fooBar`)
15631563
6. Create a new Pull Request

src/app/api/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def get_current_user(
3636
raise UnauthorizedException("User not authenticated.")
3737

3838
if "@" in token_data.username_or_email:
39-
user: dict = await crud_users.get(db=db, email=token_data.username_or_email, is_deleted=False)
39+
user: dict | None = await crud_users.get(db=db, email=token_data.username_or_email, is_deleted=False)
4040
else:
4141
user = await crud_users.get(db=db, username=token_data.username_or_email, is_deleted=False)
4242

src/app/api/v1/posts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def read_posts(
5050
db: Annotated[AsyncSession, Depends(async_get_db)],
5151
page: int = 1,
5252
items_per_page: int = 10
53-
) -> PaginatedListResponse[PostRead]:
53+
) -> dict:
5454
db_user = await crud_users.get(db=db, schema_to_select=UserRead, username=username, is_deleted=False)
5555
if not db_user:
5656
raise NotFoundException("User not found")
@@ -65,7 +65,7 @@ async def read_posts(
6565
)
6666

6767
return paginated_response(
68-
crud_data=posts_data,
68+
crud_data=posts_data["data"],
6969
page=page,
7070
items_per_page=items_per_page
7171
)
@@ -78,7 +78,7 @@ async def read_post(
7878
username: str,
7979
id: int,
8080
db: Annotated[AsyncSession, Depends(async_get_db)]
81-
) -> PostRead:
81+
) -> dict:
8282
db_user = await crud_users.get(db=db, schema_to_select=UserRead, username=username, is_deleted=False)
8383
if db_user is None:
8484
raise NotFoundException("User not found")

src/app/api/v1/rate_limits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def read_rate_limits(
4848
db: Annotated[AsyncSession, Depends(async_get_db)],
4949
page: int = 1,
5050
items_per_page: int = 10
51-
) -> PaginatedListResponse[RateLimitRead]:
51+
) -> dict:
5252
db_tier = await crud_tiers.get(db=db, name=tier_name)
5353
if not db_tier:
5454
raise NotFoundException("Tier not found")
@@ -62,7 +62,7 @@ async def read_rate_limits(
6262
)
6363

6464
return paginated_response(
65-
crud_data=rate_limits_data,
65+
crud_data=rate_limits_data["data"],
6666
page=page,
6767
items_per_page=items_per_page
6868
)
@@ -74,7 +74,7 @@ async def read_rate_limit(
7474
tier_name: str,
7575
id: int,
7676
db: Annotated[AsyncSession, Depends(async_get_db)]
77-
) -> RateLimitRead:
77+
) -> dict:
7878
db_tier = await crud_tiers.get(db=db, name=tier_name)
7979
if not db_tier:
8080
raise NotFoundException("Tier not found")

src/app/api/v1/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def create_task(message: str) -> Dict[str, str]:
2424
Dict[str, str]
2525
A dictionary containing the ID of the created task.
2626
"""
27-
job = await queue.pool.enqueue_job("sample_background_task", message)
27+
job = await queue.pool.enqueue_job("sample_background_task", message) # type: ignore
2828
return {"id": job.job_id}
2929

3030

src/app/api/v1/tiers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def read_tiers(
3939
db: Annotated[AsyncSession, Depends(async_get_db)],
4040
page: int = 1,
4141
items_per_page: int = 10
42-
) -> PaginatedListResponse[TierRead]:
42+
) -> dict:
4343
tiers_data = await crud_tiers.get_multi(
4444
db=db,
4545
offset=compute_offset(page, items_per_page),
@@ -48,7 +48,7 @@ async def read_tiers(
4848
)
4949

5050
return paginated_response(
51-
crud_data=tiers_data,
51+
crud_data=tiers_data["data"],
5252
page=page,
5353
items_per_page=items_per_page
5454
)
@@ -59,7 +59,7 @@ async def read_tier(
5959
request: Request,
6060
name: str,
6161
db: Annotated[AsyncSession, Depends(async_get_db)]
62-
) -> TierRead:
62+
) -> dict:
6363
db_tier = await crud_tiers.get(db=db, schema_to_select=TierRead, name=name)
6464
if db_tier is None:
6565
raise NotFoundException("Tier not found")

src/app/api/v1/users.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ async def read_users(
4747
db: Annotated[AsyncSession, Depends(async_get_db)],
4848
page: int = 1,
4949
items_per_page: int = 10
50-
) -> PaginatedListResponse[UserRead]:
50+
) -> dict:
5151
users_data = await crud_users.get_multi(
5252
db=db,
5353
offset=compute_offset(page, items_per_page),
5454
limit=items_per_page,
55-
schema_to_select=UserRead,
55+
schema_to_select=UserRead,
5656
is_deleted=False
5757
)
58-
58+
5959
return paginated_response(
60-
crud_data=users_data,
60+
crud_data=users_data["data"],
6161
page=page,
6262
items_per_page=items_per_page
6363
)
@@ -76,7 +76,7 @@ async def read_user(
7676
request: Request,
7777
username: str,
7878
db: Annotated[AsyncSession, Depends(async_get_db)]
79-
) -> UserRead:
79+
) -> dict:
8080
db_user = await crud_users.get(db=db, schema_to_select=UserRead, username=username, is_deleted=False)
8181
if db_user is None:
8282
raise NotFoundException("User not found")
@@ -144,7 +144,7 @@ async def erase_db_user(
144144
if not db_user:
145145
raise NotFoundException("User not found")
146146

147-
db_user = await crud_users.db_delete(db=db, username=username)
147+
await crud_users.db_delete(db=db, username=username)
148148
await blacklist_token(token=token, db=db)
149149
return {"message": "User deleted from the database"}
150150

@@ -155,7 +155,7 @@ async def read_user_rate_limits(
155155
username: str,
156156
db: Annotated[AsyncSession, Depends(async_get_db)]
157157
) -> Dict[str, Any]:
158-
db_user: dict = await crud_users.get(db=db, username=username, schema_to_select=UserRead)
158+
db_user: dict | None = await crud_users.get(db=db, username=username, schema_to_select=UserRead)
159159
if db_user is None:
160160
raise NotFoundException("User not found")
161161

@@ -182,7 +182,7 @@ async def read_user_tier(
182182
request: Request,
183183
username: str,
184184
db: Annotated[AsyncSession, Depends(async_get_db)]
185-
) -> Union[UserRead, TierRead]:
185+
) -> dict | None:
186186
db_user = await crud_users.get(db=db, username=username, schema_to_select=UserRead)
187187
if db_user is None:
188188
raise NotFoundException("User not found")
@@ -195,7 +195,7 @@ async def read_user_tier(
195195
db=db,
196196
join_model=Tier,
197197
join_prefix="tier_",
198-
schema_to_select=UserRead,
198+
schema_to_select=UserRead,
199199
join_schema_to_select=TierRead,
200200
username=username
201201
)

src/app/core/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_password_hash(password: str) -> str:
2929

3030
async def authenticate_user(username_or_email: str, password: str, db: AsyncSession) -> Union[Dict[str, Any], Literal[False]]:
3131
if "@" in username_or_email:
32-
db_user: dict = await crud_users.get(db=db, email=username_or_email, is_deleted=False)
32+
db_user: dict | None = await crud_users.get(db=db, email=username_or_email, is_deleted=False)
3333
else:
3434
db_user = await crud_users.get(db=db, username=username_or_email, is_deleted=False)
3535

src/app/core/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def create_redis_cache_pool() -> None:
4040

4141

4242
async def close_redis_cache_pool() -> None:
43-
await cache.client.aclose()
43+
await cache.client.aclose() # type: ignore
4444

4545

4646
# -------------- queue --------------
@@ -51,7 +51,7 @@ async def create_redis_queue_pool() -> None:
5151

5252

5353
async def close_redis_queue_pool() -> None:
54-
await queue.pool.aclose()
54+
await queue.pool.aclose() # type: ignore
5555

5656

5757
# -------------- rate limit --------------
@@ -61,7 +61,7 @@ async def create_redis_rate_limit_pool() -> None:
6161

6262

6363
async def close_redis_rate_limit_pool() -> None:
64-
await rate_limit.client.aclose()
64+
await rate_limit.client.aclose() # type: ignore
6565

6666

6767
# -------------- application --------------

0 commit comments

Comments
 (0)