Skip to content

Commit

Permalink
(PC-29215)[API] fix: undo making native category nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
thconte committed Sep 26, 2024
1 parent ee27c76 commit 15a7e1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions api/src/pcapi/core/categories/subcategories_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def get_show_nodes() -> list[ShowGenre]:
label="Musique en ligne",
parents=[SEARCH_GROUP_CD_VINYLE_MUSIQUE_EN_LIGNE.id],
)
NATIVE_CATEGORY_NONE = NativeCategory(technical_name="NATIVE_CATEGORY_NONE", label="None", parents=[])
NATIVE_CATEGORY_PARTITIONS_DE_MUSIQUE = NativeCategory(
technical_name="PARTITIONS_DE_MUSIQUE",
label="Partitions de musique",
Expand Down Expand Up @@ -617,7 +618,7 @@ class EacFormat(Enum):
class Subcategory:
id: str
category: categories.Category
native_category: NativeCategory | None
native_category: NativeCategory
pro_label: str
app_label: str
search_group_name: str
Expand Down Expand Up @@ -655,8 +656,8 @@ def category_id(self) -> str:
return self.category.id

@property
def native_category_id(self) -> str | None:
return self.native_category.id if self.native_category else None
def native_category_id(self) -> str:
return self.native_category.id

@property
def is_offline_only(self) -> bool:
Expand Down Expand Up @@ -1302,7 +1303,7 @@ def is_online_only(self) -> bool:
CARTE_JEUNES = Subcategory(
id="CARTE_JEUNES",
category=categories.CARTE_JEUNES,
native_category=None,
native_category=NATIVE_CATEGORY_NONE,
pro_label="Carte jeunes",
app_label="Carte jeunes",
search_group_name=SEARCH_GROUP_CARTES_JEUNES.id,
Expand Down
3 changes: 2 additions & 1 deletion api/src/pcapi/core/search/backends/algolia.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from pcapi import settings
from pcapi.core.categories import categories
from pcapi.core.categories import subcategories_v2
from pcapi.core.educational.academies import get_academy_from_department
import pcapi.core.educational.api.offer as educational_api_offer
import pcapi.core.educational.models as educational_models
Expand Down Expand Up @@ -526,7 +527,7 @@ def serialize_offer(cls, offer: offers_models.Offer, last_30_days_bookings: int)

search_groups = (
offer.subcategory.native_category.parents
if offer.subcategory.native_category
if offer.subcategory.native_category != subcategories_v2.NATIVE_CATEGORY_NONE
else [offer.subcategory.search_group_name]
)

Expand Down
1 change: 1 addition & 0 deletions api/tests/routes/native/openapi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ def test_public_api(client):
"LUDOTHEQUE",
"MATERIELS_CREATIFS",
"MUSIQUE_EN_LIGNE",
"NATIVE_CATEGORY_NONE",
"PARTITIONS_DE_MUSIQUE",
"PODCAST",
"PRATIQUES_ET_ATELIERS_ARTISTIQUES",
Expand Down

0 comments on commit 15a7e1c

Please sign in to comment.