Fakultas Ilmu Komputer UI

Commit 2842358a authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140382397] #7 Add so swag~ swagger plugin

parent 392705bc
......@@ -35,6 +35,7 @@ INSTALLED_APPS = [
'core',
'rest_framework',
'django_nose',
'rest_framework_swagger'
]
MIDDLEWARE = [
......
......@@ -13,17 +13,22 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.conf.urls import include
from django.conf.urls import url
from django.contrib import admin
from rest_framework import routers
from rest_framework_swagger.views import get_swagger_view
from kape.views.user import UserViewSet
schema_view = get_swagger_view()
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
urlpatterns = [
url(r'^api/api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/$', schema_view),
url(r"^api/", include(router.urls)),
url(r'^admin/', admin.site.urls),
url(r'', include('core.urls')),
url(r'^api/api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
from django.contrib.auth.models import User
from rest_framework import serializers, viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
# Serializers define the API representation.
......@@ -13,3 +15,11 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
@list_route(methods=['get'])
def me(self, request):
user = self.request.user
serializer = UserSerializer(user, context={"request": request})
return Response(serializer.data)
......@@ -8,4 +8,5 @@ pyparsing==2.1.10
six==1.10.0
gunicorn
django-nose
coverage
\ No newline at end of file
coverage
django-rest-swagger
\ No newline at end of file
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