Skip to content

Commit

Permalink
Merge pull request #3796 from betagouv/payload-reduction
Browse files Browse the repository at this point in the history
Réduction de la taille de la réponse à la liste de `actionableCanteens`
  • Loading branch information
alemangui authored Apr 8, 2024
2 parents 93930ba + 066c7af commit a611b0c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions api/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ManagingTeamSerializer,
CanteenPreviewSerializer,
SatelliteCanteenSerializer,
CanteenActionsListSerializer,
CanteenActionsSerializer,
CanteenStatusSerializer,
CanteenTeledeclarationSerializer,
Expand Down
14 changes: 14 additions & 0 deletions api/serializers/canteen.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ class Meta:
fields = ("id", "managers", "manager_invitations")


class CanteenActionsListSerializer(serializers.ModelSerializer):
action = serializers.CharField(allow_null=True)

class Meta:
model = Canteen
fields = (
"id",
"name",
"action",
"production_type",
)
read_only_fields = fields


class CanteenActionsSerializer(serializers.ModelSerializer):
# TODO: is it worth moving the job of fetching the specific diag required to the front?
diagnostics = FullDiagnosticSerializer(many=True, read_only=True, source="diagnostic_set")
Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_canteens.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def test_get_canteen_actions(self):
for index, (canteen, action) in zip(range(len(expected_actions)), expected_actions):
self.assertEqual(returned_canteens[index]["id"], canteen.id)
self.assertEqual(returned_canteens[index]["action"], action)
self.assertIn("sectors", returned_canteens[index])
self.assertIn("productionType", returned_canteens[index])
self.assertTrue(body["hasPendingActions"])

@override_settings(ENABLE_TELEDECLARATION=True)
Expand Down
7 changes: 3 additions & 4 deletions api/views/canteen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CanteenPreviewSerializer,
ManagingTeamSerializer,
SatelliteCanteenSerializer,
CanteenActionsListSerializer,
CanteenActionsSerializer,
CanteenStatusSerializer,
ElectedCanteenSerializer,
Expand Down Expand Up @@ -1189,7 +1190,7 @@ def post(self, request, canteen_pk, satellite_pk):
class ActionableCanteensListView(ListAPIView):
permission_classes = [IsAuthenticated]
model = Canteen
serializer_class = CanteenActionsSerializer
serializer_class = CanteenActionsListSerializer
pagination_class = CanteenActionsPagination
filter_backends = [
django_filters.DjangoFilterBackend,
Expand Down Expand Up @@ -1250,9 +1251,7 @@ def annotate_actions(queryset, year):
)

# prep complete diag action
complete_diagnostics = Diagnostic.objects.filter(
pk=OuterRef("diagnostic_for_year"), value_total_ht__gt=0, diagnostic_type__isnull=False
)
complete_diagnostics = Diagnostic.objects.filter(pk=OuterRef("diagnostic_for_year"), value_total_ht__gt=0)
user_canteens = user_canteens.annotate(has_complete_diag=Exists(Subquery(complete_diagnostics)))
# prep TD action
tds = Teledeclaration.objects.filter(
Expand Down

0 comments on commit a611b0c

Please sign in to comment.