-
Notifications
You must be signed in to change notification settings - Fork 45
(PC-32268)[API] feat: Return individual or collective statistics only if offerer is concerned - V2 #14992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PC-32268)[API] feat: Return individual or collective statistics only if offerer is concerned - V2 #14992
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| from .yearly_revenue import YearlyAggregatedCollectiveRevenueQuery | ||
| from .yearly_revenue import YearlyAggregatedIndividualRevenueQuery | ||
| from .yearly_revenue import YearlyAggregatedRevenueModel | ||
| from .yearly_revenue import YearlyAggregatedRevenueQuery |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| from flask_login import login_required | ||
|
|
||
| from pcapi.connectors.clickhouse import queries as clickhouse_queries | ||
| from pcapi.core.offers.repository import venues_have_individual_and_collective_offers | ||
| from pcapi.models.api_errors import ApiErrors | ||
| from pcapi.routes.apis import private_api | ||
| from pcapi.routes.serialization.statistics_serialize import StatisticsModel | ||
|
|
@@ -26,5 +27,11 @@ def get_statistics(query: StatisticsQueryModel) -> StatisticsModel: | |
| status_code=422, | ||
| ) | ||
| check_user_has_access_to_venues(current_user, venue_ids) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je vois que tu as fait une seconde PR pour le même ticket, du coup je me permet de remettre ici le warning concernant cette fonction que j’ai soulevé dans la première There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ce qu’on cherche à faire c’est, est-ce que pour un user donné, la liste des venue_ids demandées sont toutes bien liées aux structures auquel appartient notre utilisateur ? (données de sanbox) pass_culture>
SELECT '{13, 14, 15}' <@ ARRAY_AGG(venue.id) FROM venue
JOIN offerer ON offerer.id = venue."managingOffererId"
JOIN user_offerer ON user_offerer."offererId" = offerer.id
WHERE user_offerer."userId"=1
GROUP BY user_offerer."userId";
+----------+
| ?column? |
|----------|
| True |
+----------+
SELECT 1
Time: 0.084s
pass_culture>
SELECT '{1, 13, 14, 15}' <@ ARRAY_AGG(venue.id) FROM venue
JOIN offerer ON offerer.id = venue."managingOffererId"
JOIN user_offerer ON user_offerer."offererId" = offerer.id
WHERE user_offerer."userId"=1
GROUP BY user_offerer."userId";
+----------+
| ?column? |
|----------|
| False |
+----------+
SELECT 1
Time: 0.008s
db.session.execute(
sa.select(
sa.cast(postgresql.array(venue_ids), postgresql.ARRAY(postgresql.BIGINT)).contained_by(
sa.func.array_agg(Venue.id)
)
)
.select_from(Venue)
.join(Offerer)
.join(UserOfferer)
.where(UserOfferer.userId == current_user)
.group_by(UserOfferer.userId)
).scalar() |
||
| result = clickhouse_queries.YearlyAggregatedRevenueQuery().execute(tuple(venue_ids)) | ||
| venues_have_individual, venues_have_collective = venues_have_individual_and_collective_offers(venue_ids) | ||
| if not venues_have_individual: | ||
| result = clickhouse_queries.YearlyAggregatedCollectiveRevenueQuery().execute(tuple(venue_ids)) | ||
| elif not venues_have_collective: | ||
| result = clickhouse_queries.YearlyAggregatedIndividualRevenueQuery().execute(tuple(venue_ids)) | ||
| else: | ||
| result = clickhouse_queries.YearlyAggregatedRevenueQuery().execute(tuple(venue_ids)) | ||
| return StatisticsModel.from_query(income_by_year=result.income_by_year) | ||
Uh oh!
There was an error while loading. Please reload this page.