Skip to content

Commit

Permalink
fix(API): Proofs: improve API documentation for upload (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Oct 2, 2024
1 parent dd9a239 commit 0168a0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions open_prices/api/proofs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class Meta:
exclude = ["source"] # ProofSerializer.Meta.exclude


class ProofUploadSerializer(serializers.ModelSerializer):
file = serializers.FileField(required=True, use_url=False)

class Meta:
model = Proof
fields = ["file"] + Proof.CREATE_FIELDS


class ProofCreateSerializer(serializers.ModelSerializer):
class Meta:
model = Proof
Expand Down
16 changes: 11 additions & 5 deletions open_prices/api/proofs/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema
from rest_framework import filters, mixins, status, viewsets
from rest_framework.decorators import action, parser_classes
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.decorators import action
from rest_framework.parsers import MultiPartParser
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -11,6 +12,7 @@
ProofCreateSerializer,
ProofFullSerializer,
ProofUpdateSerializer,
ProofUploadSerializer,
)
from open_prices.common.authentication import CustomAuthentication
from open_prices.proofs.models import Proof
Expand All @@ -26,7 +28,6 @@ class ProofViewSet(
):
authentication_classes = [CustomAuthentication]
permission_classes = [IsAuthenticated]
# parser_classes = [FormParser, MultiPartParser]
http_method_names = ["get", "post", "patch", "delete"] # disable "put"
queryset = Proof.objects.none()
serializer_class = ProofFullSerializer
Expand All @@ -49,8 +50,13 @@ def get_serializer_class(self):
return ProofUpdateSerializer
return self.serializer_class

@action(detail=False, methods=["POST"], url_path="upload")
@parser_classes([FormParser, MultiPartParser])
@extend_schema(request=ProofUploadSerializer, responses=ProofFullSerializer)
@action(
detail=False,
methods=["POST"],
url_path="upload",
parser_classes=[MultiPartParser],
)
def upload(self, request: Request) -> Response:
# build proof
if not request.data.get("file"):
Expand Down

0 comments on commit 0168a0f

Please sign in to comment.