Skip to content

Commit

Permalink
api(siae): ajoute le parent dans l'endpoint siae kinds (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Feb 14, 2024
1 parent 6aafd60 commit 28e8563
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions lemarche/api/siaes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def test_should_return_siae_kinds_list(self):
self.assertEqual(len(response.data["results"]), 10)
self.assertTrue("id" in response.data["results"][0])
self.assertTrue("name" in response.data["results"][0])
self.assertTrue("parent" in response.data["results"][0])

def test_should_return_siae_presta_types_list(self):
url = reverse("api:siae-presta-types-list") # anonymous user
Expand Down
14 changes: 11 additions & 3 deletions lemarche/api/siaes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from lemarche.api.siaes.filters import SiaeFilter
from lemarche.api.siaes.serializers import SiaeDetailSerializer, SiaeListSerializer
from lemarche.api.utils import BasicChoiceSerializer, check_user_token
from lemarche.api.utils import BasicChoiceSerializer, BasicChoiceWithParentSerializer, check_user_token
from lemarche.siaes import constants as siae_constants
from lemarche.siaes.models import Siae

Expand Down Expand Up @@ -150,11 +150,19 @@ def _list_return(self, request, queryset, format):


class SiaeKindViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
serializer_class = BasicChoiceSerializer
serializer_class = BasicChoiceWithParentSerializer
queryset = Siae.objects.none()

def get_queryset(self):
siae_kinds = [{"id": id, "name": name} for (id, name) in siae_constants.KIND_CHOICES]
siae_kind_insertion = [
{"id": id, "name": name, "parent": siae_constants.KIND_PARENT_INSERTION_NAME}
for (id, name) in siae_constants.KIND_INSERTION_CHOICES
]
siae_kind_handicap = [
{"id": id, "name": name, "parent": siae_constants.KIND_PARENT_HANDICAP_NAME}
for (id, name) in siae_constants.KIND_HANDICAP_CHOICES
]
siae_kinds = siae_kind_insertion + siae_kind_handicap
return siae_kinds

@extend_schema(summary="Lister tous les types de structures", tags=[Siae._meta.verbose_name_plural])
Expand Down
4 changes: 4 additions & 0 deletions lemarche/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ def custom_preprocessing_hook(endpoints):
class BasicChoiceSerializer(serializers.Serializer):
id = serializers.CharField()
name = serializers.CharField()


class BasicChoiceWithParentSerializer(BasicChoiceSerializer):
parent = serializers.CharField()

0 comments on commit 28e8563

Please sign in to comment.