Skip to content

Commit

Permalink
Fix exclude filter not working and misleading name
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Feb 1, 2025
1 parent 9dc818b commit e1ee4cb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
8 changes: 4 additions & 4 deletions backend/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 @@ -38,7 +38,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 @@ -48,7 +48,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 @@ -61,7 +61,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
28 changes: 16 additions & 12 deletions backend/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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 @@ -124,18 +124,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
]

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 @@ -150,11 +152,17 @@ 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
]

return _translate_name_and_summary(
locale,
client.index("apps").search(
Expand All @@ -163,11 +171,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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export type GetCategoryCategoryCategoryGetParams = {
filter_subcategories?: string[]
exclude_subcategories?: string[]
page?: number | null
per_page?: number | null
locale?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export type GetSubcategoryCategoryCategorySubcategoriesSubcategoryGetParams = {
filter_subcategories?: string[]
exclude_subcategories?: string[]
page?: number | null
per_page?: number | null
locale?: string
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const CATEGORY_URL = (
page?: number,
per_page?: number,
locale?: string,
exclude_subcategories?: string[],
): string => {
const result = new URLSearchParams()

Expand All @@ -158,6 +159,10 @@ export const CATEGORY_URL = (
if (locale) {
result.append("locale", locale)
}

if (exclude_subcategories) {
result.append("exclude_subcategories", exclude_subcategories.join(","))
}
return `${BASE_URI}/category/${category}?${result.toString()}`
}

Expand All @@ -167,6 +172,7 @@ export const SUBCATEGORY_URL = (
page?: number,
per_page?: number,
locale?: string,
exclude_subcategories?: string[],
): string => {
const result = new URLSearchParams()

Expand All @@ -181,6 +187,10 @@ export const SUBCATEGORY_URL = (
if (locale) {
result.append("locale", locale)
}

if (exclude_subcategories) {
result.append("exclude_subcategories", exclude_subcategories.join(","))
}
return `${BASE_URI}/category/${category}/subcategories/${subcategory}?${result.toString()}`
}

Expand Down
15 changes: 13 additions & 2 deletions frontend/src/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ export async function fetchCategory(
locale: string,
page?: number,
per_page?: number,
exclude_subcategories?: string[],
): Promise<MeilisearchResponse<AppsIndex>> {
const appListRes = await fetch(CATEGORY_URL(category, page, per_page, locale))
const appListRes = await fetch(
CATEGORY_URL(category, page, per_page, locale, exclude_subcategories),
)
const response: MeilisearchResponse<AppsIndex> = await appListRes.json()

console.log(
Expand All @@ -184,9 +187,17 @@ export async function fetchSubcategory(
locale: string,
page?: number,
per_page?: number,
exclude_subcategories?: string[],
): Promise<MeilisearchResponse<AppsIndex>> {
const appListRes = await fetch(
SUBCATEGORY_URL(category, subcategory, page, per_page, locale),
SUBCATEGORY_URL(
category,
subcategory,
page,
per_page,
locale,
exclude_subcategories,
),
)
const response: MeilisearchResponse<AppsIndex> = await appListRes.json()

Expand Down

0 comments on commit e1ee4cb

Please sign in to comment.