Skip to content

Commit b5babd3

Browse files
committed
python upgrade, CRUDBase replaced with fastcrud
1 parent bd8963a commit b5babd3

File tree

12 files changed

+26
-653
lines changed

12 files changed

+26
-653
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
- 🏬 Easy redis caching
5656
- 👜 Easy client-side caching
5757
- 🚦 ARQ integration for task queue
58-
- ⚙️ Efficient querying (only queries what's needed) with support for joins
59-
- ⎘ Out of the box pagination support
58+
- ⚙️ Efficient and robust queries with <a href="https://github.com/igorbenav/fastcrud">fastcrud</a>
59+
- ⎘ Out of the box offset and cursor pagination support with <a href="https://github.com/igorbenav/fastcrud">fastcrud</a>
6060
- 🛑 Rate Limiter dependency
6161
- 👮 FastAPI docs behind authentication and hidden based on the environment
6262
- 🦾 Easily extendable
@@ -749,14 +749,15 @@ poetry run alembic upgrade head
749749

750750
### 5.6 CRUD
751751

752-
Inside `app/crud`, create a new `crud_entities.py` inheriting from `CRUDBase` for each new entity:
752+
Inside `app/crud`, create a new `crud_entities.py` inheriting from `FastCRUD` for each new entity:
753753

754754
```python
755-
from app.crud.crud_base import CRUDBase
755+
from fastcrud import FastCRUD
756+
756757
from app.models.entity import Entity
757758
from app.schemas.entity import EntityCreateInternal, EntityUpdate, EntityUpdateInternal, EntityDelete
758759

759-
CRUDEntity = CRUDBase[Entity, EntityCreateInternal, EntityUpdate, EntityUpdateInternal, EntityDelete]
760+
CRUDEntity = FastCRUD[Entity, EntityCreateInternal, EntityUpdate, EntityUpdateInternal, EntityDelete]
760761
crud_entity = CRUDEntity(Entity)
761762
```
762763

@@ -767,7 +768,7 @@ So, for users:
767768
from app.model.user import User
768769
from app.schemas.user import UserCreateInternal, UserUpdate, UserUpdateInternal, UserDelete
769770

770-
CRUDUser = CRUDBase[User, UserCreateInternal, UserUpdate, UserUpdateInternal, UserDelete]
771+
CRUDUser = FastCRUD[User, UserCreateInternal, UserUpdate, UserUpdateInternal, UserDelete]
771772
crud_users = CRUDUser(User)
772773
```
773774

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ redis = "^5.0.1"
3030
arq = "^0.25.0"
3131
gunicorn = "^21.2.0"
3232
bcrypt = "^4.1.1"
33+
fastcrud = "^0.1.5"
3334

3435

3536
[build-system]
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from ...crud.crud_base import CRUDBase
1+
from fastcrud import FastCRUD
2+
23
from ..db.token_blacklist import TokenBlacklist
34
from ..schemas import TokenBlacklistCreate, TokenBlacklistUpdate
45

5-
CRUDTokenBlacklist = CRUDBase[TokenBlacklist, TokenBlacklistCreate, TokenBlacklistUpdate, TokenBlacklistUpdate, None]
6+
CRUDTokenBlacklist = FastCRUD[TokenBlacklist, TokenBlacklistCreate, TokenBlacklistUpdate, TokenBlacklistUpdate, None]
67
crud_token_blacklist = CRUDTokenBlacklist(TokenBlacklist)
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +0,0 @@
1-
from http import HTTPStatus
2-
3-
from fastapi import HTTPException, status
4-
5-
6-
class CustomException(HTTPException):
7-
def __init__(self, status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR, detail: str | None = None):
8-
if not detail:
9-
detail = HTTPStatus(status_code).description
10-
super().__init__(status_code=status_code, detail=detail)
11-
12-
13-
class BadRequestException(CustomException):
14-
def __init__(self, detail: str | None = None):
15-
super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
16-
17-
18-
class NotFoundException(CustomException):
19-
def __init__(self, detail: str | None = None):
20-
super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
21-
22-
23-
class ForbiddenException(CustomException):
24-
def __init__(self, detail: str | None = None):
25-
super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
26-
27-
28-
class UnauthorizedException(CustomException):
29-
def __init__(self, detail: str | None = None):
30-
super().__init__(status_code=status.HTTP_401_UNAUTHORIZED, detail=detail)
31-
32-
33-
class UnprocessableEntityException(CustomException):
34-
def __init__(self, detail: str | None = None):
35-
super().__init__(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=detail)
36-
37-
38-
class DuplicateValueException(CustomException):
39-
def __init__(self, detail: str | None = None):
40-
super().__init__(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=detail)
41-
42-
43-
class RateLimitException(CustomException):
44-
def __init__(self, detail: str | None = None):
45-
super().__init__(status_code=status.HTTP_429_TOO_MANY_REQUESTS, detail=detail)

src/app/core/worker/functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
34
import uvloop
45
from arq.worker import Worker
56

src/app/core/worker/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from arq.connections import RedisSettings
2+
23
from ...core.config import settings
3-
from .functions import sample_background_task, startup, shutdown
4+
from .functions import sample_background_task, shutdown, startup
45

56
REDIS_QUEUE_HOST = settings.REDIS_QUEUE_HOST
67
REDIS_QUEUE_PORT = settings.REDIS_QUEUE_PORT

0 commit comments

Comments
 (0)