Skip to content

Commit

Permalink
#39 feat : set default drf_yasg setting & make user signup swagger (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored Jun 23, 2024
1 parent 282a308 commit c59cdca
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cognisle/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'users.apps.UsersConfig',
'sslserver',
'lands.apps.LandsConfig',
'drf_yasg',
]

INSTALLED_APPS = DJANGO_APPS+PROJECT_APPS
Expand Down
16 changes: 16 additions & 0 deletions Cognisle/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,24 @@
"""
from django.contrib import admin
from django.urls import path, include
from rest_framework.permissions import AllowAny
from drf_yasg import openapi
from drf_yasg.views import get_schema_view

schema_view = get_schema_view(
openapi.Info(
title="Cognisle",
default_version="v1",
description="Cognisle BE API",
),
public=True,
permission_classes=(AllowAny,),
)

urlpatterns = [
path(r'swagger(?P<format>\.json|\.yaml$)/',schema_view.without_ui(cache_timeout=0),name='schema-json'),
path(r'swagger/',schema_view.with_ui('swagger',cache_timeout=0),name='schema-swagger-ui'),
path(r'redoc/',schema_view.with_ui('redoc',cache_timeout=0),name='schema-redoc'),
path('admin/', admin.site.urls),
path('users/',include('users.urls')),
path('lands/',include('lands.urls')),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ tzdata==2022.2
uritemplate==4.1.1
urllib3==1.26.12
django-redis==5.3.0
twilio==9.0.2
ruamel.yaml
32 changes: 32 additions & 0 deletions users/migrations/0007_rename_discord_id_user_dsid_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.0 on 2024-06-23 09:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0006_alter_user_is_active'),
]

operations = [
migrations.RenameField(
model_name='user',
old_name='discord_id',
new_name='dsId',
),
migrations.RenameField(
model_name='user',
old_name='nickname',
new_name='name',
),
migrations.RemoveField(
model_name='user',
name='phone',
),
migrations.AddField(
model_name='user',
name='dsName',
field=models.CharField(max_length=20, null=True),
),
]
11 changes: 5 additions & 6 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

# Create your models here.
class UserManager(BaseUserManager):
def create_user(self, email, password, discord_id, nickname, **extra_fields):
def create_user(self, email, password, name, **extra_fields):
if not email:
raise ValueError(('THe Email must be set'))
email = self.normalize_email(email)
user = self.model(email=email, discord_id=discord_id, nickname=nickname, **extra_fields)
user = self.model(email=email, name=name, **extra_fields)
user.set_password(password)
user.save()
return user
Expand All @@ -27,10 +27,9 @@ def create_superuser(self, email, password, discord_id, nickname, **extra_fiel

class User(AbstractBaseUser,PermissionsMixin,TimeStampedModel):
email = models.EmailField(max_length=64,unique=True)
discord_id = models.CharField(max_length=64,unique=True)
phone = models.CharField(max_length=15,null=True)
nickname = models.CharField(max_length=20)

dsId = models.CharField(max_length=64,unique=True)
name = models.CharField(max_length=20)
dsName=models.CharField(max_length=20,null=True)
is_active = models.BooleanField(default = True)
is_superuser = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
Expand Down
4 changes: 2 additions & 2 deletions users/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class UserService:
def __init__(self):
pass

def user_sign_up(email:str,password:str, discord_id:str, nickname:str,phone:str):
def user_sign_up(email:str,password:str, dsId:str, name:str,dsName:str):

user=User(email=email, password=password, discord_id=discord_id,nickname=nickname,phone=phone)
user=User(email=email, password=password, dsId=dsId,name=name,dsName=dsName)

user.set_password(password)
user.is_active=False
Expand Down
33 changes: 27 additions & 6 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,38 @@
from rest_framework.response import Response
from rest_framework.permissions import AllowAny, IsAuthenticated
from users.services import UserService
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema

class UserSignUpApi(APIView):
permission_classes=(AllowAny,)

class UserSignUpInputSerializer(serializers.Serializer):
email=serializers.EmailField()
password=serializers.CharField()
discord_id=serializers.CharField()
#phone=serializers.CharField()
nickname=serializers.CharField()
dsId=serializers.CharField()
dsName=serializers.CharField()
name=serializers.CharField()

@swagger_auto_schema(
request_body=UserSignUpInputSerializer,
security=[],
operation_id='유저 회원가입 API',
operation_description="유저 기본 회원가입 API 입니다.",
responses={
"200":openapi.Response(
description="OK",
examples={
"application/json":{
"status":"success",
}
}
),
"400":openapi.Response(
description="Bad Request",
),
}
)
def post(self,request):
serializers = self.UserSignUpInputSerializer(data=request.data)
serializers.is_valid(raise_exception=True)
Expand All @@ -26,9 +47,9 @@ def post(self,request):
UserService.user_sign_up(
email=data.get('email'),
password=data.get('password'),
discord_id=data.get('discord_id'),
nickname=data.get('nickname'),
phone=request.session['verify_phone'],
dsId=data.get('dsId'),
name=data.get('name'),
dsName=data.get('dsName'),
)

return Response({
Expand Down

0 comments on commit c59cdca

Please sign in to comment.