Skip to content

Commit

Permalink
openapi specs
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Nov 13, 2024
1 parent 819df89 commit d678e37
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/specs/web-server/_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async def list_folders(
)
async def list_folders_full_search(
params: Annotated[PageQueryParameters, Depends()],
text: str | None = None,
order_by: Annotated[
Json,
Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,12 @@ paths:
summary: List Folders Full Search
operationId: list_folders_full_search
parameters:
- required: false
schema:
title: Text
type: string
name: text
in: query
- description: Order by field (modified_at|name|description) and direction (asc|desc).
The default sorting order is ascending.
required: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async def list_folders(
else WorkspaceQuery(workspace_scope=WorkspaceScope.PRIVATE)
),
filter_trashed=trashed,
filter_by_text=None,
offset=offset,
limit=limit,
order_by=order_by,
Expand Down Expand Up @@ -199,6 +200,7 @@ async def list_folders_full_search(
app: web.Application,
user_id: UserID,
product_name: ProductName,
text: str | None,
trashed: bool | None,
offset: NonNegativeInt,
limit: int,
Expand All @@ -213,6 +215,7 @@ async def list_folders_full_search(
folder_query=FolderQuery(folder_scope=FolderScope.ALL),
workspace_query=WorkspaceQuery(workspace_scope=WorkspaceScope.ALL),
filter_trashed=trashed,
filter_by_text=text,
offset=offset,
limit=limit,
order_by=order_by,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches
workspace_query: WorkspaceQuery,
# attribute filters
filter_trashed: bool | None,
filter_by_text: str | None,
# pagination
offset: NonNegativeInt,
limit: int,
Expand Down Expand Up @@ -199,6 +200,8 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches
else:
assert folder_query.folder_scope == FolderScope.ROOT # nosec
attributes_filters.append(folders_v2.c.parent_folder_id.is_(None))
if filter_by_text:
attributes_filters.append(folders_v2.c.name.ilike(f"%{filter_by_text}%"))

###
# Combined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async def list_folders_full_search(request: web.Request):
app=request.app,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
text=query_params.text,
trashed=query_params.filters.trashed,
offset=query_params.offset,
limit=query_params.limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from models_library.rest_ordering import OrderBy, OrderDirection
from models_library.rest_pagination import PageQueryParameters
from models_library.users import UserID
from models_library.utils.common_validators import null_or_none_str_to_none_validator
from models_library.utils.common_validators import (
empty_str_to_none_pre_validator,
null_or_none_str_to_none_validator,
)
from models_library.workspaces import WorkspaceID
from pydantic import BaseModel, Extra, Field, Json, validator
from servicelib.aiohttp.requests_validation import RequestParams, StrictRequestParams
Expand Down Expand Up @@ -88,6 +91,17 @@ class Config:
class FolderListFullSearchWithJsonStrQueryParams(
PageQueryParameters, FolderListSortParams, FiltersQueryParameters[FolderFilters]
):
text: str | None = Field(
default=None,
description="Multi column full text search, across all folders and workspaces",
max_length=100,
example="My Project",
)

_empty_is_none = validator("text", allow_reuse=True, pre=True)(
empty_str_to_none_pre_validator
)

class Config:
extra = Extra.forbid

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ async def test_folders_full_search(
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert len(data) == 3

# list full folder search with specific text
url = client.app.router["list_folders_full_search"].url_for()
query_parameters = {"text": "My subfolder"}
url_with_query = url.with_query(**query_parameters)
resp = await client.get(f"{url_with_query}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert len(data) == 1

# Create new user
async with LoggedUser(client) as new_logged_user:
# list full folder search
Expand Down

0 comments on commit d678e37

Please sign in to comment.