Skip to content

Commit

Permalink
feat: add a basic api endpoint for references
Browse files Browse the repository at this point in the history
Closes: #49
  • Loading branch information
b1rger committed May 15, 2024
1 parent d63bb05 commit d196ba2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apis_bibsonomy/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import viewsets

from .models import Reference
from .serializers import ReferenceSerializer
from .utils import BibsonomyEntry, get_bibtex_from_url


Expand Down Expand Up @@ -125,3 +127,8 @@ def delete(self, request, format=None):
ref = Reference.objects.get(pk=request.data.get("pk"))
ref.delete()
return Response(status=status.HTTP_204_NO_CONTENT)


class ReferenceViewSet(viewsets.ModelViewSet):
queryset = Reference.objects.all()
serializer_class = ReferenceSerializer
8 changes: 8 additions & 0 deletions apis_bibsonomy/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Reference


class ReferenceSerializer(serializers.ModelSerializer):
class Meta:
model = Reference
fields = '__all__'
8 changes: 6 additions & 2 deletions apis_bibsonomy/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from rest_framework.routers import DefaultRouter
from django.urls import path
from rest_framework import routers
from django.urls import include, path
from . import api_views, views
from . import autocompletes

app_name = 'apis_bibsonomy'

router = routers.DefaultRouter()
router.register(r'references', api_views.ReferenceViewSet)

urlpatterns = [
path('save_get/', api_views.SaveBibsonomyEntry.as_view(), name='savegetbibsonomyentry'),
path('autocomplete/', autocompletes.BibsonomyAutocomplete.as_view(), name='bibsonomyautocomplete'),
Expand All @@ -14,4 +17,5 @@
path('referenceson/<int:contenttype>/<int:pk>', views.ReferenceOnListView.as_view(), name="referenceonlist"),
path('referenceson/<int:contenttype>/<int:pk>/modal', views.ReferenceOnListViewModal.as_view(), name="referenceonlistmodal"),
path('referenceson/<int:contenttype>/<int:pk>/partial', views.ReferenceOnListViewPartial.as_view(), name="referenceonlistpartial"),
path("api/", include(router.urls)),
]

0 comments on commit d196ba2

Please sign in to comment.