Added jwt, swagger...
This commit is contained in:
0
backend/apps/authentication/__init__.py
Normal file
0
backend/apps/authentication/__init__.py
Normal file
3
backend/apps/authentication/admin.py
Normal file
3
backend/apps/authentication/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
backend/apps/authentication/apps.py
Normal file
5
backend/apps/authentication/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuthenticationConfig(AppConfig):
|
||||
name = 'apps.authentication'
|
||||
0
backend/apps/authentication/migrations/__init__.py
Normal file
0
backend/apps/authentication/migrations/__init__.py
Normal file
3
backend/apps/authentication/models.py
Normal file
3
backend/apps/authentication/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
backend/apps/authentication/tests.py
Normal file
3
backend/apps/authentication/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
14
backend/apps/authentication/urls.py
Normal file
14
backend/apps/authentication/urls.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.urls import include, path
|
||||
from rest_framework_simplejwt.views import (
|
||||
TokenObtainPairView,
|
||||
TokenRefreshView,
|
||||
TokenVerifyView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path('login/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
#path('signup/', ),
|
||||
|
||||
path('refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
path('verify/', TokenVerifyView.as_view(), name='token_verify'),
|
||||
]
|
||||
3
backend/apps/authentication/views.py
Normal file
3
backend/apps/authentication/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -5,14 +5,14 @@ from apps.user.serializers import UserSerializer
|
||||
from apps.user.models import User
|
||||
|
||||
class ShelfSerializer(serializers.ModelSerializer):
|
||||
user = UserSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Shelf
|
||||
fields = ["id", "name", "user"]
|
||||
fields = ["id", "name"]
|
||||
read_only_fields = ["id"]
|
||||
|
||||
|
||||
def create(self, validated_data):
|
||||
# Pobieramy user_id z tokena
|
||||
request = self.context["request"]
|
||||
validated_data["user"] = request.user
|
||||
|
||||
return super().create(validated_data)
|
||||
@@ -3,7 +3,17 @@ from django.shortcuts import render
|
||||
from apps.shelves.models import Shelf
|
||||
from apps.shelves.serializers import ShelfSerializer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
|
||||
class ShelvesViewSet(viewsets.ModelViewSet):
|
||||
queryset = Shelf.objects.select_related("user")
|
||||
serializer_class = ShelfSerializer
|
||||
serializer_class = ShelfSerializer
|
||||
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
return Shelf.objects.filter(user_id=self.request.user.pk)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("shelves", include("apps.shelves.urls"))
|
||||
path("auth", include("apps.authentication.urls")),
|
||||
path("shelves", include("apps.shelves.urls")),
|
||||
|
||||
path('schema/', SpectacularAPIView.as_view(), name='schema'),
|
||||
path('swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
||||
|
||||
]
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from apps.user.models import User
|
||||
|
||||
# Register your models here.
|
||||
class UserAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
Reference in New Issue
Block a user