diff --git a/src/config/settings.py b/src/config/settings.py index 76e8191..2f7fd98 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -153,4 +153,13 @@ # Rest Framework -REST_FRAMEWORK = {"DEFAULT_AUTHENTICATION_CLASSES": ("rest_framework_simplejwt.authentication.JWTAuthentication",)} +REST_FRAMEWORK = { + "DEFAULT_AUTHENTICATION_CLASSES": ("rest_framework_simplejwt.authentication.JWTAuthentication",), +} + +# Swagger +SWAGGER_SETTINGS = { + "SECURITY_DEFINITIONS": { + "Bearer": {"type": "apiKey", "name": "Authorization", "in": "header"}, + }, +} diff --git a/src/users/serializers.py b/src/users/serializers.py index f8542ff..ce5366b 100644 --- a/src/users/serializers.py +++ b/src/users/serializers.py @@ -1,9 +1,9 @@ from django.contrib.auth import get_user_model from django.contrib.auth.password_validation import validate_password -from rest_framework.serializers import ModelSerializer +from rest_framework import serializers -class UserSignUpSerializer(ModelSerializer): +class UserSignUpSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() fields = ("username", "password") @@ -19,3 +19,25 @@ def create(self, validated_data): user.set_password(raw_password) user.save() return user + + +class SignInRequestSerializer(serializers.Serializer): + username = serializers.CharField() + password = serializers.CharField() + + def create(self, validated_data): + raise NotImplementedError() + + def update(self, instance, validated_data): + raise NotImplementedError() + + +class SignInResponseSerializer(serializers.Serializer): + access = serializers.CharField() + refresh = serializers.CharField() + + def create(self, validated_data): + raise NotImplementedError() + + def update(self, instance, validated_data): + raise NotImplementedError() diff --git a/src/users/urls.py b/src/users/urls.py index 4a2c781..8283408 100644 --- a/src/users/urls.py +++ b/src/users/urls.py @@ -1,9 +1,8 @@ from django.urls import path -from rest_framework_simplejwt.views import TokenObtainPairView -from users.views import SignUpAPIView +from users.views import SignInAPIView, SignUpAPIView urlpatterns = [ path("signup/", view=SignUpAPIView.as_view(), name="signup"), - path("signin/", view=TokenObtainPairView.as_view(), name="signin"), + path("signin/", view=SignInAPIView.as_view(), name="signin"), ] diff --git a/src/users/views.py b/src/users/views.py index 9828bbf..af4da48 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -2,8 +2,13 @@ from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework_simplejwt.views import TokenObtainPairView -from users.serializers import UserSignUpSerializer +from users.serializers import ( + SignInRequestSerializer, + SignInResponseSerializer, + UserSignUpSerializer, +) class SignUpAPIView(APIView): @@ -26,9 +31,15 @@ def post(self, request): ) -class SignInAPIView(APIView): +class SignInAPIView(TokenObtainPairView): @swagger_auto_schema( operation_summary="사용자 로그인", + request_body=SignInRequestSerializer, + responses={ + status.HTTP_200_OK: SignInResponseSerializer, + status.HTTP_400_BAD_REQUEST: "error", + status.HTTP_401_UNAUTHORIZED: "unauthorized", + }, ) - def post(self, request): - return + def post(self, request, *args, **kwargs): + return super().post(request, *args, **kwargs)