Skip to content
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

feat: django-rest-framework #8053

Draft
wants to merge 28 commits into
base: feat/rpc-api
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5186823
chore: add django-rest-framework/drf-spectacular
jennifer-richards Oct 11, 2024
283cf2b
chore: set up drf and auth/authz
jennifer-richards Oct 11, 2024
b664548
chore: spectacular setup
jennifer-richards Oct 11, 2024
622958c
chore: add drf-standardized-errors
jennifer-richards Oct 12, 2024
b42219b
refactor: rpc_person -> PersonViewSet
jennifer-richards Oct 12, 2024
0ad57d0
refactor: rpc_subject_person -> SubjectPersonView
jennifer-richards Oct 12, 2024
3e4bf37
refactor: rpc_persons -> RpcPersonsView
jennifer-richards Oct 15, 2024
73e14e2
refactor: rpc_draft -> DraftViewSet
jennifer-richards Oct 15, 2024
7c2733a
refactor: drafts_by_names -> DraftsByNameView
jennifer-richards Oct 15, 2024
11f8cc1
refactor: submitted_to_rpc -> DraftViewSet
jennifer-richards Oct 15, 2024
14c3bfe
refactor: rfc_original_stream -> RfcViewSet
jennifer-richards Oct 15, 2024
6d49bb8
refactor: create_demo_person -> DemoViewSet
jennifer-richards Oct 15, 2024
82e2b24
refactor: create_demo_draft -> DemoViewSet
jennifer-richards Oct 16, 2024
e327111
fix: instantiate AnonymousUser class
jennifer-richards Oct 16, 2024
29e0cfa
refactor: move RpcPersonView into PersonViewSet
jennifer-richards Oct 16, 2024
88c0917
fix: adjust URLs
jennifer-richards Oct 16, 2024
99e8fb0
chore: remove unused imports
jennifer-richards Oct 16, 2024
efa2d3d
style: Black
jennifer-richards Oct 16, 2024
9eb8cbe
chore: Remove unused code
jennifer-richards Oct 16, 2024
b002c19
refactor: use serializer for parsing
jennifer-richards Oct 16, 2024
c50977f
chore: drf-standardized-errors settings
jennifer-richards Oct 16, 2024
dd7f9fd
chore: adjust drf-spectacular settings
jennifer-richards Oct 16, 2024
28b1e04
chore: generated API schema for comparison
jennifer-richards Oct 16, 2024
8600744
refactor: serializers_rpc module
jennifer-richards Oct 16, 2024
2a0182f
style: unnecessary parentheses
jennifer-richards Oct 16, 2024
1f6f549
fix: bad subject ID is really a 404
jennifer-richards Oct 16, 2024
3eaffa6
chore: fix comment
jennifer-richards Oct 16, 2024
ac4c006
Merge branch 'feat/rpc-api' into rpc-api-drf
jennifer-richards Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: move RpcPersonView into PersonViewSet
Changes response to a list instead of dict
  • Loading branch information
jennifer-richards committed Oct 16, 2024
commit 29e0cfaa167ddf265719e28ee95e999432b92448
32 changes: 13 additions & 19 deletions ietf/api/views_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,26 @@ def to_representation(self, instance):
summary="Find person by ID",
description="Returns a single person",
),
batch=extend_schema(
operation_id="get_persons",
summary="Get a batch of persons",
description="returns a dict of person pks to person names",
request=list[int],
responses=PersonSerializer(many=True),
)
)
class PersonViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
queryset = Person.objects.all()
serializer_class = PersonSerializer
api_key_endpoint = "ietf.api.views_rpc"
lookup_url_kwarg = "person_id"

@action(detail=False, methods=["post"], serializer_class=PersonSerializer)
def batch(self, request):
"""Get a batch of rpc person names"""
pks = json.loads(request.data)
return Response(self.get_serializer(Person.objects.filter(pk__in=pks), many=True).data)


class SubjectPersonView(APIView):
api_key_endpoint = "ietf.api.views_rpc"
Expand Down Expand Up @@ -97,25 +110,6 @@ def get(self, request, subject_id: str):
raise Http404


class RpcPersonsView(APIView):
api_key_endpoint = "ietf.api.views_rpc"

@extend_schema(
operation_id="get_persons",
summary="Get a batch of persons",
description="returns a dict of person pks to person names",
request=list[int],
responses=dict[str, str],
)
def post(self, request):
"""Get a batch of rpc person names"""
pks = json.loads(request.body)
response = dict()
for p in Person.objects.filter(pk__in=pks):
response[str(p.pk)] = p.plain_name()
return Response(response)


class DocumentAuthorSerializer(serializers.ModelSerializer):
"""Serializer for a Person in a response"""
plain_name = serializers.SerializerMethodField()
Expand Down