Skip to content

Commit

Permalink
add re.escape, fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
glebmashanov committed May 31, 2024
1 parent 4db156d commit f46b38c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Visit `http://127.0.0.1:8080/admin`
- Uvicorn

### API Documentation
Visit `/api/docs#/` - добавить чтобы отключить
Visit `/api/docs#/` - **to disable API documentation set value to empty string \' \'**

### Security
There is no security, you have to protect your `/admin` and `/api` additionally
Expand Down
12 changes: 5 additions & 7 deletions backend/app/api/v0/routers/tag_router.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from fastapi_pagination.ext.async_sqlalchemy import paginate
from sqlalchemy.ext.asyncio import AsyncSession
from fastapi_pagination import Page
Expand All @@ -18,23 +20,19 @@
router = APIRouter()


@router.get(
"/", response_model=Page[ListTagResponseSchema], status_code=status.HTTP_200_OK
)
@router.get("/", response_model=Page[ListTagResponseSchema], status_code=status.HTTP_200_OK)
async def get_tags(
query: str = Query(None, min_length=1, max_length=150),
postgres_session: AsyncSession = Depends(get_postgres_session),
):
select_stmt = select(TagModel)
if query:
select_stmt = select_stmt.where(TagModel.name.ilike(f"%{query}%"))
select_stmt = select_stmt.where(TagModel.name.ilike(f"%{re.escape(query)}%"))

return await paginate(postgres_session, select_stmt.order_by(TagModel.created_at))


@router.post(
"/", response_model=CreateTagResponseSchema, status_code=status.HTTP_201_CREATED
)
@router.post("/", response_model=CreateTagResponseSchema, status_code=status.HTTP_201_CREATED)
async def create_tag_url(
data: CreateTagRequestSchema = Body(...),
postgres_session: AsyncSession = Depends(get_postgres_session),
Expand Down

0 comments on commit f46b38c

Please sign in to comment.