Skip to content

Commit

Permalink
(PC-33423)[API] feat: filter on status in GET offerer headline_offer …
Browse files Browse the repository at this point in the history
…routes
  • Loading branch information
ogeber-pass committed Dec 24, 2024
1 parent 579c811 commit 433c8e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions api/src/pcapi/core/offerers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,18 +886,16 @@ def get_offerer_address_of_offerer(offerer_id: int, offerer_address_id: int) ->

def get_offerer_headline_offer(offerer_id: int) -> offers_models.Offer | None:
try:
# FIXME: ogeber: when offers will be able to have several headline offers, and unicity of the headline
# offer will be on its active status, change this query and add a filter on active headline offer only
offer = (
offers_models.Offer.query.join(models.Venue, offers_models.Offer.venueId == models.Venue.id)
.join(models.Offerer, models.Venue.managingOffererId == models.Offerer.id)
.join(offers_models.HeadlineOffer, offers_models.HeadlineOffer.offerId == offers_models.Offer.id)
.options(
sqla_orm.contains_eager(offers_models.Offer.headlineOffer),
sqla_orm.contains_eager(offers_models.Offer.headlineOffers),
sqla_orm.joinedload(offers_models.Offer.mediations),
sqla_orm.joinedload(offers_models.Offer.product).joinedload(offers_models.Product.productMediations),
)
.filter(models.Offerer.id == offerer_id)
.filter(models.Offerer.id == offerer_id, offers_models.HeadlineOffer.isActive == True)
.one_or_none()
)

Expand Down
3 changes: 3 additions & 0 deletions api/tests/core/offerers/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def test_get_offerer_addresses(self):
class GetOffererHeadlineOfferTest:
def test_return_headline_offer(self):
offer = offers_factories.OfferFactory()
offers_factories.StockFactory(offer=offer)
offers_factories.HeadlineOfferFactory(offer=offer, venue=offer.venue)

headline_offer = repository.get_offerer_headline_offer(offer.venue.managingOffererId)
Expand All @@ -287,7 +288,9 @@ def test_shoud_not_return_several_headline_offer(self):
venue = offerers_factories.VenueFactory(managingOfferer=offerer)
other_venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offer = offers_factories.OfferFactory(venue=venue)
offers_factories.StockFactory(offer=offer)
other_offer = offers_factories.OfferFactory(venue=other_venue)
offers_factories.StockFactory(offer=other_offer)
offers_factories.HeadlineOfferFactory(offer=offer, venue=venue)
offers_factories.HeadlineOfferFactory(offer=other_offer, venue=other_venue)

Expand Down
1 change: 1 addition & 0 deletions api/tests/routes/native/v1/offerers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def test_get_offerer_headline_offer_success(self, client):
offerer = user_offerer.offerer
venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offer = offers_factories.OfferFactory(venue=venue)
offers_factories.StockFactory(offer=offer)
offers_factories.HeadlineOfferFactory(offer=offer, venue=venue)

client = client.with_session_auth(email=pro.email)
Expand Down
4 changes: 4 additions & 0 deletions api/tests/routes/pro/get_offerer_headline_offer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_get_offerer_headline_offer_success(self, client):
offerer = user_offerer.offerer
venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offer = offers_factories.OfferFactory(venue=venue)
offers_factories.StockFactory(offer=offer)
offers_factories.HeadlineOfferFactory(offer=offer, venue=venue)
client = client.with_session_auth(email=pro.email)
offerer_id = offerer.id
Expand Down Expand Up @@ -52,6 +53,7 @@ def test_get_offerer_headline_offer_with_product_mediations(self, client):
offers_factories.ProductMediationFactory(product=product, imageType=TiteliveImageType.VERSO)

offer = offers_factories.OfferFactory(venue=venue, product=product)
offers_factories.StockFactory(offer=offer)
offers_factories.HeadlineOfferFactory(offer=offer, venue=venue)
client = client.with_session_auth(email=pro.email)
offerer_id = offerer.id
Expand Down Expand Up @@ -91,9 +93,11 @@ def test_with_multiple_headline_offer_on_one_offerer_should_fail(self, client):
offerer = user_offerer.offerer
venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offer = offers_factories.OfferFactory(venue=venue)
offers_factories.StockFactory(offer=offer)
offers_factories.HeadlineOfferFactory(offer=offer, venue=venue)
other_venue = offerers_factories.VenueFactory(managingOfferer=offerer)
other_offer = offers_factories.OfferFactory(venue=other_venue)
offers_factories.StockFactory(offer=other_offer)
offers_factories.HeadlineOfferFactory(offer=other_offer, venue=other_venue)
client = client.with_session_auth(email=pro.email)
offerer_id = offerer.id
Expand Down

0 comments on commit 433c8e3

Please sign in to comment.