Commit e26fc567 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Add more documentation for metagenedb API

parent bb68022c
Pipeline #28107 failed with stages
in 3 minutes and 35 seconds
......@@ -4,7 +4,7 @@ from rest_framework.routers import DefaultRouter, DynamicRoute, Route
from metagenedb.api.catalog import views
from metagenedb.api.catalog.views.celery_test import celery_test_view, test_task_view
# from metagenedb.api.catalog.views.celery_test import celery_test_view, test_task_view
class CustomRouter(DefaultRouter):
......
from marshmallow.exceptions import ValidationError
from rest_framework import status
from rest_framework.mixins import (
CreateModelMixin, ListModelMixin, RetrieveModelMixin, UpdateModelMixin
)
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.viewsets import GenericViewSet
from metagenedb.common.django_default.permissions import ListAndRetrieveAll
from metagenedb.common.django_default.qparams_validators import PaginatedQueryParams
class QParamsValidationViewSet(ModelViewSet):
class QParamsValidationViewSet(
CreateModelMixin,
ListModelMixin,
RetrieveModelMixin,
UpdateModelMixin,
GenericViewSet
):
query_params_parser = PaginatedQueryParams
def _get_qparams(self, raw_query_params):
......
import logging
from drf_yasg.utils import swagger_auto_schema
from marshmallow.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.status import HTTP_422_UNPROCESSABLE_ENTITY
......@@ -25,6 +26,36 @@ class FunctionViewSet(BulkViewSet):
filterset_class = FunctionFilter
query_params_parser = FunctionQueryParams
@swagger_auto_schema(
tags=['Functions'],
)
def list(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Functions'],
)
def retrieve(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Functions'],
)
def create(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Functions'],
)
def update(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Functions'],
)
def partial_update(self, *args, **kwargs):
super().list(*args, **kwargs)
class KeggOrthologyViewSet(QParamsValidationViewSet):
queryset = KeggOrthology.objects.all()
......@@ -42,6 +73,9 @@ class KeggOrthologyViewSet(QParamsValidationViewSet):
detailed_data = db_data
return detailed_data
@swagger_auto_schema(
tags=['KEGG'],
)
def retrieve(self, request, *args, **kwargs):
try:
query_params = self.query_params_parser().load(request.query_params)
......@@ -58,6 +92,30 @@ class KeggOrthologyViewSet(QParamsValidationViewSet):
returned_data = self._get_external_info(returned_data)
return Response(returned_data)
@swagger_auto_schema(
tags=['KEGG'],
)
def list(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['KEGG'],
)
def create(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['KEGG'],
)
def update(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['KEGG'],
)
def partial_update(self, *args, **kwargs):
super().list(*args, **kwargs)
class EggNOGViewSet(QParamsValidationViewSet):
queryset = EggNOG.objects.all()
......@@ -65,3 +123,33 @@ class EggNOGViewSet(QParamsValidationViewSet):
lookup_field = 'function_id'
filterset_class = EggNOGFilter
query_params_parser = EggNOGQueryParams
@swagger_auto_schema(
tags=['EggNOG'],
)
def list(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['EggNOG'],
)
def retrieve(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['EggNOG'],
)
def create(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['EggNOG'],
)
def update(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['EggNOG'],
)
def partial_update(self, *args, **kwargs):
super().list(*args, **kwargs)
from drf_yasg.utils import swagger_auto_schema
from metagenedb.apps.catalog.models import Gene
from metagenedb.api.catalog.filters import GeneFilter
from metagenedb.api.catalog.qparams_validators.gene import GeneQueryParams
......@@ -12,3 +14,33 @@ class GeneViewSet(BulkViewSet):
filterset_class = GeneFilter
query_params_parser = GeneQueryParams
lookup_field = 'gene_id'
@swagger_auto_schema(
tags=['Genes'],
)
def list(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Genes'],
)
def retrieve(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Genes'],
)
def create(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Genes'],
)
def update(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Genes'],
)
def partial_update(self, *args, **kwargs):
super().list(*args, **kwargs)
from django.shortcuts import get_object_or_404
from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets
from rest_framework.response import Response
......@@ -7,16 +8,23 @@ from metagenedb.apps.catalog.serializers import StatisticsSerializer
class StatisticsViewSet(viewsets.ViewSet):
"""
API View that list or retrieve pre-computed statistics from the catalog.
"""
lookup_field = 'stats_id'
@swagger_auto_schema(
operation_description="List all pre-computed statistics",
operation_summary="API to list all pre-computed statistics.",
tags=['Statistics'],
)
def list(self, request):
queryset = Statistics.objects.all()
serializer = StatisticsSerializer(queryset, many=True)
return Response(serializer.data)
@swagger_auto_schema(
operation_description="Retrieve pre-computed statistics from an ID",
operation_summary="API to retrieve pre-computed statistics.",
tags=['Statistics'],
)
def retrieve(self, request, stats_id=None):
queryset = Statistics.objects.all()
stats = get_object_or_404(queryset, stats_id=stats_id)
......
from drf_yasg.utils import swagger_auto_schema
from metagenedb.api.catalog.filters import TaxonomyFilter
from metagenedb.api.catalog.qparams_validators.taxonomy import TaxonomyQueryParams
from metagenedb.apps.catalog.models import Taxonomy
......@@ -13,3 +15,33 @@ class TaxonomyViewSet(BulkViewSet):
lookup_field = 'tax_id'
filterset_class = TaxonomyFilter
query_params_parser = TaxonomyQueryParams
@swagger_auto_schema(
tags=['Taxonomy'],
)
def list(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Taxonomy'],
)
def retrieve(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Taxonomy'],
)
def create(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Taxonomy'],
)
def update(self, *args, **kwargs):
super().list(*args, **kwargs)
@swagger_auto_schema(
tags=['Taxonomy'],
)
def partial_update(self, *args, **kwargs):
super().list(*args, **kwargs)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment