From 3a1a1a65f29713cef81858f11b59672f22f1680e Mon Sep 17 00:00:00 2001 From: kingmusung Date: Fri, 2 Feb 2024 22:15:11 +0900 Subject: [PATCH] =?UTF-8?q?guest=20api=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- haruProject/config/settings.py | 33 +++++++++++++------------ haruProject/config/urls.py | 1 - haruProject/guest/__init__.py | 0 haruProject/guest/admin.py | 3 --- haruProject/guest/apps.py | 6 ----- haruProject/guest/models.py | 8 ------- haruProject/guest/serializers.py | 11 --------- haruProject/guest/tests.py | 3 --- haruProject/guest/urls.py | 7 ------ haruProject/guest/views.py | 41 -------------------------------- 10 files changed, 16 insertions(+), 97 deletions(-) delete mode 100644 haruProject/guest/__init__.py delete mode 100644 haruProject/guest/admin.py delete mode 100644 haruProject/guest/apps.py delete mode 100644 haruProject/guest/models.py delete mode 100644 haruProject/guest/serializers.py delete mode 100644 haruProject/guest/tests.py delete mode 100644 haruProject/guest/urls.py delete mode 100644 haruProject/guest/views.py diff --git a/haruProject/config/settings.py b/haruProject/config/settings.py index 5fa3b0d..4cb26c5 100644 --- a/haruProject/config/settings.py +++ b/haruProject/config/settings.py @@ -59,7 +59,6 @@ 'diary', 'rest_framework', 'member', - 'guest', 'harucalendar', 'drf_yasg', 'storages', @@ -144,16 +143,16 @@ # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'haru', - 'USER': 'root', - 'PASSWORD': '12345678', - 'HOST': 'db', - 'PORT': '3306', - } -} +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.mysql', +# 'NAME': 'haru', +# 'USER': 'root', +# 'PASSWORD': '12345678', +# 'HOST': 'db', +# 'PORT': '3306', +# } +# } # RDS 설정 # DATABASES = { @@ -169,12 +168,12 @@ # -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': BASE_DIR / 'db.sqlite3', -# } -# } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} # Password validation # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators diff --git a/haruProject/config/urls.py b/haruProject/config/urls.py index d8f9feb..b7285fb 100644 --- a/haruProject/config/urls.py +++ b/haruProject/config/urls.py @@ -24,7 +24,6 @@ path('admin/', admin.site.urls), path('api/v1/calendars/', include('harucalendar.urls')), path('api/v1/diaries/', include('diary.urls')), - path('api/v1/guests/', include('guest.urls')), path('api/v1/static/', include('static.urls')), path('', include("django_prometheus.urls")), diff --git a/haruProject/guest/__init__.py b/haruProject/guest/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/haruProject/guest/admin.py b/haruProject/guest/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/haruProject/guest/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/haruProject/guest/apps.py b/haruProject/guest/apps.py deleted file mode 100644 index ec88744..0000000 --- a/haruProject/guest/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class GuestConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'guest' diff --git a/haruProject/guest/models.py b/haruProject/guest/models.py deleted file mode 100644 index 1031084..0000000 --- a/haruProject/guest/models.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.db import models -from diary.models import Diary - - -class Guest(models.Model): - guest_id = models.AutoField(primary_key=True) - diary = models.ForeignKey(Diary, on_delete=models.CASCADE) - guest_pw = models.CharField(max_length=4) # 비밀번호를 문자열로 저장 diff --git a/haruProject/guest/serializers.py b/haruProject/guest/serializers.py deleted file mode 100644 index d7cb100..0000000 --- a/haruProject/guest/serializers.py +++ /dev/null @@ -1,11 +0,0 @@ -from rest_framework import serializers -from .models import Guest - - -class GuestCreateSerializer(serializers.ModelSerializer): - class Meta: - model = Guest - fields = ['guest_pw', 'diary', 'guest_id'] - - def create(self, validated_data): - return Guest.objects.create(**validated_data) \ No newline at end of file diff --git a/haruProject/guest/tests.py b/haruProject/guest/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/haruProject/guest/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/haruProject/guest/urls.py b/haruProject/guest/urls.py deleted file mode 100644 index cd9b642..0000000 --- a/haruProject/guest/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.urls import path -from .views import GuestCreateView - -urlpatterns = [ - # 기존의 path - path('/', GuestCreateView.as_view(), name='create_guest') -] \ No newline at end of file diff --git a/haruProject/guest/views.py b/haruProject/guest/views.py deleted file mode 100644 index 74b78ed..0000000 --- a/haruProject/guest/views.py +++ /dev/null @@ -1,41 +0,0 @@ -from django.shortcuts import render -from drf_yasg import openapi -from drf_yasg.utils import swagger_auto_schema - -from .models import Guest -from rest_framework.views import APIView -from rest_framework.response import Response -from .serializers import GuestCreateSerializer - - -# 게스트 생성 뷰 -class GuestCreateView(APIView): - @swagger_auto_schema( - request_body=GuestCreateSerializer, - responses={ - 201: openapi.Response("게스트가 성공적으로 생성되었습니다.", GuestCreateSerializer), - 400: "잘못된 요청", - }, - operation_description="새로운 게스트 생성", - ) - def post(self, request, *args, **kwargs): - - guest_pw = request.data.get('guest_pw') - diary_id = kwargs.get('diary_id') # URL 패턴에서 diary_id를 가져오기 - - guest_data = {'guest_pw': guest_pw, 'diary': diary_id} - serializer = GuestCreateSerializer(data=guest_data) - if serializer.is_valid(): - guest = serializer.save() - request.session['guest_id'] = guest.guest_id - - response_data = { - "data": {"guest_id": guest.guest_id}, - "code": "G001", - "status": 201, - "message": "게스트 생성 성공" - } - # 생성된 게스트에 접근하여 추가적인 작업 수행 가능 - return Response({"guest_id": guest.guest_id}, status=201) - else: - return Response(serializer.errors, status=400)