Skip to content

Commit

Permalink
merge conflict, dangling master
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalGawor committed Apr 5, 2024
2 parents dd6aff7 + dab2cac commit 85328cb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions dogapi/dogapi/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from doglib import DOG
from doglib import expand_datatype as doglib_expand_datatype
from doglib.pid import pid_factory as dog_pid_factory

dog = DOG()
Expand Down
30 changes: 27 additions & 3 deletions dogapi/dogapi/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@
from rest_framework.request import Request
from typing import List

from .models import dog
from .schemas import pid_queryparam
from .utils import parse_queryparam, QueryparamParsingError

from .models import dog, doglib_expand_datatype
from .schemas import pid_queryparam
from .utils import QueryparamParsingError

logging.config.dictConfig(settings.LOGGING)
logger = logging.getLogger(__name__)


def parse_queryparam(request: Request, param_name: str) -> List[str]:
"""
Parses queryparameters from direct API call (PHP-like format ?param[]=val1&param[]=val2, both with and without [])
and via Swagger UI (?param=val1,val2)
"""
query_param_candidates = request.GET.getlist(param_name)
# Swagger UI returns a 1 element list with comma separated values of parameter, e.g. ["string,string,string"]
param_candidates = [param for param_candidate in query_param_candidates for param in param_candidate.split(',')]
return param_candidates


@extend_schema(parameters=[pid_queryparam],
description="Fetches all PIDs referenced in the metadata by resource type. For response object \
specification please consult examples.",
Expand Down Expand Up @@ -331,3 +342,16 @@ def is_pid(request: Request) -> Response:
except QueryparamParsingError as err:
ret = Response(err, status=400)
return ret


@permission_classes([AllowAny])
@api_view(['GET'])
def expand_datatype(request: Request) -> Response:
data_types = parse_queryparam(request, 'data_type')
expanded_datatypes: dict = {}
for data_type in data_types:
expanded_datatypes.update(doglib_expand_datatype(data_type))
if expanded_datatypes:
return Response(expanded_datatypes, status=200)
else:
return Response(f"MIME data type(s) {data_types} is either not correct or has been not recognised", status=400)
14 changes: 14 additions & 0 deletions dogconfig/dogproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
from drf_spectacular.views import SpectacularAPIView, SpectacularJSONAPIView
from rest_framework.permissions import AllowAny

<<<<<<< HEAD
from dogapi.views_api import fetch, identify, is_pid, sniff
from dogui.views_ui import home
=======
from dogapi.views_api import fetch, identify, sniff, expand_datatype
>>>>>>> main


urlpatterns = [
<<<<<<< HEAD
re_path(r'api/openapi.yml', SpectacularAPIView.as_view(), name='openapi_schema_yml'),
re_path(r'api/openapi.json', SpectacularJSONAPIView.as_view(), name='openapi_schema_json'),

Expand All @@ -19,4 +24,13 @@
path('api/ispid/', is_pid, name='is pid'),
path('', home, name='main'),
path('__debug__/', include('debug_toolbar.urls')),
=======
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('fetch/', fetch, name='fetch'),
path('identify/', identify, name='identify'),
path('sniff/', sniff, name='sniff'),
path('expanddatatype/', expand_datatype, name='expand data type'),
>>>>>>> main
]

0 comments on commit 85328cb

Please sign in to comment.