diff --git a/apis_bibsonomy/api_views.py b/apis_bibsonomy/api_views.py index 16bca63..3c99358 100644 --- a/apis_bibsonomy/api_views.py +++ b/apis_bibsonomy/api_views.py @@ -8,9 +8,23 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework import viewsets, generics from .models import Reference from .utils import BibsonomyEntry +from .serializers import ReferenceSerializer + +class ReferenceList(generics.ListCreateAPIView): + """ + API endpoint that allows references to be viewed. + """ + serializer_class = ReferenceSerializer + permission_classes = [IsAuthenticated] + + def get_queryset(self): + ct = self.kwargs['ct'] + pk = self.kwargs['pk'] + return Reference.objects.filter(content_type = ct, object_id = pk) class SaveBibsonomyEntry(APIView): diff --git a/apis_bibsonomy/serializers.py b/apis_bibsonomy/serializers.py new file mode 100644 index 0000000..4baf944 --- /dev/null +++ b/apis_bibsonomy/serializers.py @@ -0,0 +1,8 @@ +from .models import Reference +from rest_framework import serializers + + +class ReferenceSerializer(serializers.ModelSerializer): + class Meta: + model = Reference + fields = '__all__' diff --git a/apis_bibsonomy/urls.py b/apis_bibsonomy/urls.py index 38bc236..2a9c0b9 100644 --- a/apis_bibsonomy/urls.py +++ b/apis_bibsonomy/urls.py @@ -1,3 +1,4 @@ +from rest_framework.routers import DefaultRouter from django.urls import path from . import api_views from . import autocompletes @@ -6,6 +7,6 @@ urlpatterns = [ path('save_get/', api_views.SaveBibsonomyEntry.as_view(), name='savegetbibsonomyentry'), - path('autocomplete/', autocompletes.BibsonomyAutocomplete.as_view(), name='bibsonomyautocomplete') + path('autocomplete/', autocompletes.BibsonomyAutocomplete.as_view(), name='bibsonomyautocomplete'), + path('references//', api_views.ReferenceList.as_view(), name='referenceslist'), ] -