Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Jan 23, 2025
1 parent dd58cff commit 23cbd9a
Show file tree
Hide file tree
Showing 8 changed files with 524 additions and 35 deletions.
8 changes: 4 additions & 4 deletions backend/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_categories() -> list[str]:
@router.get("/category/{category}", tags=["app"])
def get_category(
category: schemas.MainCategory,
filter_subcategories: list[str] = Query(None),
exclude_subcategories: list[str] = Query(None),
page: int | None = None,
per_page: int | None = None,
locale: str = "en",
Expand All @@ -35,7 +35,7 @@ def get_category(
return response

result = search.get_by_selected_categories(
[category], filter_subcategories, page, per_page, locale
[category], exclude_subcategories, page, per_page, locale
)

return result
Expand All @@ -45,7 +45,7 @@ def get_category(
def get_subcategory(
category: schemas.MainCategory,
subcategory: str,
filter_subcategories: list[str] = Query(None),
exclude_subcategories: list[str] = Query(None),
page: int | None = None,
per_page: int | None = None,
locale: str = "en",
Expand All @@ -58,7 +58,7 @@ def get_subcategory(
return response

result = search.get_by_selected_category_and_subcategory(
category, subcategory, filter_subcategories, page, per_page, locale
category, subcategory, exclude_subcategories, page, per_page, locale
)

return result
Expand Down
29 changes: 17 additions & 12 deletions backend/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def delete_apps(app_id_list):

def get_by_selected_categories(
selected_categories: list[schemas.MainCategory],
filter_subcategories: list[str],
exclude_subcategories: list[str],
page: int | None,
hits_per_page: int | None,
locale: str,
Expand All @@ -105,18 +105,20 @@ def get_by_selected_categories(
f"categories = {category.value}" for category in selected_categories
]

exclude_subcategories_list = [
f"sub_categories NOT IN [{exclude_subcategory}]"
for exclude_subcategory in exclude_subcategories
if exclude_subcategory is not None
]

return _translate_name_and_summary(
locale,
client.index("apps").search(
"",
{
"filter": [
category_list,
(
f"sub_categories NOT IN {filter_subcategories}"
if filter_subcategories is not None
else ""
),
exclude_subcategories_list,
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
Expand All @@ -131,11 +133,18 @@ def get_by_selected_categories(
def get_by_selected_category_and_subcategory(
selected_category: schemas.MainCategory,
selected_subcategory: str,
filter_subcategories: list[str],
exclude_subcategories: list[str],
page: int | None,
hits_per_page: int | None,
locale: str,
):

exclude_subcategories_list = [
f"sub_categories NOT IN [{exclude_subcategory}]"
for exclude_subcategory in exclude_subcategories
if exclude_subcategory is not None
]

return _translate_name_and_summary(
locale,
client.index("apps").search(
Expand All @@ -144,11 +153,7 @@ def get_by_selected_category_and_subcategory(
"filter": [
f"main_categories = {selected_category.value}",
f"sub_categories = {selected_subcategory}",
(
f"sub_categories NOT IN {filter_subcategories}"
if filter_subcategories is not None
else ""
),
exclude_subcategories_list,
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
Expand Down
Loading

0 comments on commit 23cbd9a

Please sign in to comment.