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)