Skip to content

Commit 8cee723

Browse files
authored
Merge pull request #123 from igorbenav/fastcrud-paginated
Fastcrud paginated
2 parents 07a160e + 8a3342c commit 8cee723

File tree

8 files changed

+17
-98
lines changed

8 files changed

+17
-98
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ First, you may want to take a look at the project structure and understand what
565565
│ ├── api # Folder containing API-related logic.
566566
│ │ ├── __init__.py
567567
│ │ ├── dependencies.py # Defines dependencies for use across API endpoints.
568-
│ │ ├── paginated.py # Utilities for API response pagination.
569568
│ │ │
570569
│ │ └── v1 # Version 1 of the API.
571570
│ │ ├── __init__.py
@@ -1020,10 +1019,10 @@ With the `get_multi` method we get a python `dict` with full suport for paginati
10201019
}
10211020
```
10221021

1023-
And in the endpoint, we can import from `app/api/paginated` the following functions and Pydantic Schema:
1022+
And in the endpoint, we can import from `fastcrud.paginated` the following functions and Pydantic Schema:
10241023

10251024
```python
1026-
from app.api.paginated import (
1025+
from fastcrud.paginated import (
10271026
PaginatedListResponse, # What you'll use as a response_model to validate
10281027
paginated_response, # Creates a paginated response based on the parameters
10291028
compute_offset, # Calculate the offset for pagination ((page - 1) * items_per_page)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ redis = "^5.0.1"
3030
arq = "^0.25.0"
3131
gunicorn = "^21.2.0"
3232
bcrypt = "^4.1.1"
33-
fastcrud = "^0.6.0"
33+
fastcrud = "^0.7.0"
3434

3535

3636
[build-system]

src/app/api/paginated.py

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

src/app/api/v1/login.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from datetime import timedelta
22
from typing import Annotated
33

4-
import fastapi
5-
from fastapi import Depends, Request, Response
4+
from fastapi import APIRouter, Depends, Request, Response
65
from fastapi.security import OAuth2PasswordRequestForm
76
from sqlalchemy.ext.asyncio import AsyncSession
87

@@ -18,7 +17,7 @@
1817
verify_token,
1918
)
2019

21-
router = fastapi.APIRouter(tags=["login"])
20+
router = APIRouter(tags=["login"])
2221

2322

2423
@router.post("/login", response_model=Token)

src/app/api/v1/posts.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Annotated
22

3-
import fastapi
4-
from fastapi import Depends, Request
3+
from fastapi import APIRouter, Depends, Request
4+
from fastcrud.paginated import PaginatedListResponse, compute_offset, paginated_response
55
from sqlalchemy.ext.asyncio import AsyncSession
66

77
from ...api.dependencies import get_current_superuser, get_current_user
8-
from ...api.paginated import PaginatedListResponse, compute_offset, paginated_response
98
from ...core.db.database import async_get_db
109
from ...core.exceptions.http_exceptions import ForbiddenException, NotFoundException
1110
from ...core.utils.cache import cache
@@ -14,7 +13,7 @@
1413
from ...schemas.post import PostCreate, PostCreateInternal, PostRead, PostUpdate
1514
from ...schemas.user import UserRead
1615

17-
router = fastapi.APIRouter(tags=["posts"])
16+
router = APIRouter(tags=["posts"])
1817

1918

2019
@router.post("/{username}/post", response_model=PostRead, status_code=201)

src/app/api/v1/rate_limits.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from typing import Annotated
22

3-
import fastapi
4-
from fastapi import Depends, Request
3+
from fastapi import APIRouter, Depends, Request
4+
from fastcrud.paginated import PaginatedListResponse, compute_offset, paginated_response
55
from sqlalchemy.ext.asyncio import AsyncSession
66

77
from ...api.dependencies import get_current_superuser
8-
from ...api.paginated import PaginatedListResponse, compute_offset, paginated_response
98
from ...core.db.database import async_get_db
109
from ...core.exceptions.http_exceptions import DuplicateValueException, NotFoundException, RateLimitException
1110
from ...crud.crud_rate_limit import crud_rate_limits
1211
from ...crud.crud_tier import crud_tiers
1312
from ...schemas.rate_limit import RateLimitCreate, RateLimitCreateInternal, RateLimitRead, RateLimitUpdate
1413

15-
router = fastapi.APIRouter(tags=["rate_limits"])
14+
router = APIRouter(tags=["rate_limits"])
1615

1716

1817
@router.post("/tier/{tier_name}/rate_limit", dependencies=[Depends(get_current_superuser)], status_code=201)

src/app/api/v1/tiers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from typing import Annotated
22

3-
import fastapi
4-
from fastapi import Depends, Request
3+
from fastapi import APIRouter, Depends, Request
54
from sqlalchemy.ext.asyncio import AsyncSession
5+
from fastcrud.paginated import PaginatedListResponse, compute_offset, paginated_response
66

77
from ...api.dependencies import get_current_superuser
8-
from ...api.paginated import PaginatedListResponse, compute_offset, paginated_response
98
from ...core.db.database import async_get_db
109
from ...core.exceptions.http_exceptions import DuplicateValueException, NotFoundException
1110
from ...crud.crud_tier import crud_tiers
1211
from ...schemas.tier import TierCreate, TierCreateInternal, TierRead, TierUpdate
1312

14-
router = fastapi.APIRouter(tags=["tiers"])
13+
router = APIRouter(tags=["tiers"])
1514

1615

1716
@router.post("/tier", dependencies=[Depends(get_current_superuser)], status_code=201)

src/app/api/v1/users.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Annotated, Any
22

3-
import fastapi
4-
from fastapi import Depends, Request
3+
from fastapi import APIRouter, Depends, Request
54
from sqlalchemy.ext.asyncio import AsyncSession
5+
from fastcrud.paginated import PaginatedListResponse, compute_offset, paginated_response
66

77
from ...api.dependencies import get_current_superuser, get_current_user
8-
from ...api.paginated import PaginatedListResponse, compute_offset, paginated_response
98
from ...core.db.database import async_get_db
109
from ...core.exceptions.http_exceptions import DuplicateValueException, ForbiddenException, NotFoundException
1110
from ...core.security import blacklist_token, get_password_hash, oauth2_scheme
@@ -16,7 +15,7 @@
1615
from ...schemas.tier import TierRead
1716
from ...schemas.user import UserCreate, UserCreateInternal, UserRead, UserTierUpdate, UserUpdate
1817

19-
router = fastapi.APIRouter(tags=["users"])
18+
router = APIRouter(tags=["users"])
2019

2120

2221
@router.post("/user", response_model=UserRead, status_code=201)

0 commit comments

Comments
 (0)