Skip to content
Snippets Groups Projects
Commit 82cce05b authored by Chris Li's avatar Chris Li
Browse files

Upload doc and fix profile view.

parent 6b67ed70
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,22 @@ python manage.py runserver 0.0.0.0:8000 # This command could let you test yo
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
- Check migration before run the server:
```script
python manage.py makemigrations
python manage.py migrate
```
- Run the server
```script
python manage.py runserver
```
- Browser the document
Type the link (`http://127.0.0.1:8000/docs/`) in to the browser, and you could see the API document there.
## Support
......
from rest_framework import status
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from core.models.profile import Profile
from core.serializers.profile import ProfileSerializer
......@@ -11,15 +8,5 @@ class ProfileViewSet(generics.RetrieveUpdateAPIView):
permission_classes = (IsAuthenticated,)
serializer_class = ProfileSerializer
def retrieve(self, request, *args, **kwargs):
instance = request.user.profile
serializer = self.get_serializer(instance)
return Response(serializer.data)
def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False)
instance = request.user.profile
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Response(serializer.data)
def get_object(self):
return self.request.user.profile
......@@ -46,8 +46,7 @@ INSTALLED_APPS = [
]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
'DEFAULT_AUTHENTICATION_CLASSES': [
'knox.auth.TokenAuthentication',
],
......
......@@ -3,6 +3,7 @@ from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from rest_framework.documentation import include_docs_urls
router = routers.DefaultRouter()
......@@ -11,6 +12,7 @@ urlpatterns = router.urls
urlpatterns += [
path('', include('core.urls')),
path('admin/', admin.site.urls),
path('docs/', include_docs_urls(title='ECE651 Backend API Document', description='This API document includes all ednpoints that has been implemented.')),
]
urlpatterns += static('media/', document_root=settings.MEDIA_ROOT)
......@@ -33,3 +33,8 @@ dependencies:
- django-rest-knox==4.2.0
- django-rest-passwordreset==1.3.0
- typing-extensions==4.4.0
- coreapi
- markdown
- pygments
- django-filter
- django-guardian
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment