Skip to content

Commit

Permalink
Swagger refactor (#1516)
Browse files Browse the repository at this point in the history
* Files refactor

* Added actions to the v1 files
  • Loading branch information
Tansito authored Oct 15, 2024
1 parent cf655f2 commit b1050b4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 61 deletions.
77 changes: 77 additions & 0 deletions gateway/api/v1/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Files view api for V1.
"""

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import permissions
from rest_framework.decorators import action

from api.permissions import IsOwner
from api import views
Expand All @@ -14,3 +17,77 @@ class FilesViewSet(views.FilesViewSet):
"""

permission_classes = [permissions.IsAuthenticated, IsOwner]

@swagger_auto_schema(
operation_description="List of available for user files",
manual_parameters=[
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
def list(self, request):
return super().list(request)

@swagger_auto_schema(
operation_description="Download a specific file",
manual_parameters=[
openapi.Parameter(
"file",
openapi.IN_QUERY,
description="file name",
type=openapi.TYPE_STRING,
required=True,
),
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
@action(methods=["GET"], detail=False)
def download(self, request):
return super().download(request)

@swagger_auto_schema(
operation_description="Deletes file uploaded or produced by the programs",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(
type=openapi.TYPE_STRING, description="file name"
),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["DELETE"], detail=False)
def delete(self, request):
return super().delete(request)

@swagger_auto_schema(
operation_description="Upload selected file",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(type=openapi.TYPE_FILE, description="file name"),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["POST"], detail=False)
def upload(self, request):
return super().upload(request)
61 changes: 0 additions & 61 deletions gateway/api/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import os
from wsgiref.util import FileWrapper

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from django.conf import settings
from django.http import StreamingHttpResponse

Expand Down Expand Up @@ -69,18 +67,6 @@ def check_user_has_provider(self, user, provider_name):
"""check if user has the provider"""
return provider_name in self.list_user_providers(user)

@swagger_auto_schema(
operation_description="List of available for user files",
manual_parameters=[
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
def list(self, request):
"""List of available for user files."""
response = Response(
Expand Down Expand Up @@ -115,25 +101,6 @@ def list(self, request):

return Response({"results": files})

@swagger_auto_schema(
operation_description="List of available for user files",
manual_parameters=[
openapi.Parameter(
"file",
openapi.IN_QUERY,
description="file name",
type=openapi.TYPE_STRING,
required=True,
),
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
@action(methods=["GET"], detail=False)
def download(self, request): # pylint: disable=invalid-name
"""Download selected file."""
Expand Down Expand Up @@ -179,21 +146,6 @@ def download(self, request): # pylint: disable=invalid-name
response["Content-Disposition"] = f"attachment; filename={filename}"
return response

@swagger_auto_schema(
operation_description="Deletes file uploaded or produced by the programs",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(
type=openapi.TYPE_STRING, description="file name"
),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["DELETE"], detail=False)
def delete(self, request): # pylint: disable=invalid-name
"""Deletes file uploaded or produced by the programs,"""
Expand Down Expand Up @@ -230,19 +182,6 @@ def delete(self, request): # pylint: disable=invalid-name
)
return response

@swagger_auto_schema(
operation_description="Upload selected file",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(type=openapi.TYPE_FILE, description="file name"),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["POST"], detail=False)
def upload(self, request): # pylint: disable=invalid-name
"""Upload selected file."""
Expand Down

0 comments on commit b1050b4

Please sign in to comment.