Skip to content

Commit

Permalink
(PC-32562)[API] chore: use product extraData in native offer response
Browse files Browse the repository at this point in the history
  • Loading branch information
tconte-pass committed Oct 21, 2024
1 parent 39832b1 commit 51d8a7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/src/pcapi/core/offers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def get_offers_details(offer_ids: list[int]) -> BaseQuery:
.load_only(
models.Product.id,
models.Product.description,
models.Product.extraData,
models.Product.last_30_days_booking,
models.Product.thumbCount,
)
Expand Down
16 changes: 6 additions & 10 deletions api/src/pcapi/routes/native/v1/serialization/offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,16 @@ def get(self, key: str, default: Any = None) -> Any:
return [OfferStockResponse.from_orm(stock) for stock in offer.activeStocks]

if key == "extraData":
if not offer.extraData:
extraData = OfferExtraDataResponse() # type: ignore[call-arg]
else:
extraData = OfferExtraDataResponse.parse_obj(offer.extraData)
raw_extra_data = product.extraData if product else offer.extraData or {}
extra_data = OfferExtraDataResponse.parse_obj(offer.extraData)

# insert the durationMinutes in the extraData
extraData.durationMinutes = offer.durationMinutes
extra_data.durationMinutes = offer.durationMinutes

# insert the GLT labels in the extraData
gtl_id = offer.extraData.get("gtl_id") if offer.extraData else None
gtl_id = raw_extra_data.get("gtl_id")
if gtl_id is not None:
extraData.gtlLabels = get_gtl_labels(gtl_id)
extra_data.gtlLabels = get_gtl_labels(gtl_id)

return extraData
return extra_data

return super().get(key, default)

Expand Down

0 comments on commit 51d8a7a

Please sign in to comment.