From 35f75c005abc349e7bd17398d9805d9b4ec8add7 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:18:02 +0900 Subject: [PATCH 01/13] Rename Serializers --- .../{airport.py => airport_serializer.py} | 0 server/serializers/{dog.py => dog_serializer.py} | 0 server/serializers/organization_serializer.py | 8 ++++++++ server/serializers/review_serializer.py | 15 +++++++++++++++ .../serializers/{user.py => user_serializer.py} | 8 +------- 5 files changed, 24 insertions(+), 7 deletions(-) rename server/serializers/{airport.py => airport_serializer.py} (100%) rename server/serializers/{dog.py => dog_serializer.py} (100%) create mode 100644 server/serializers/organization_serializer.py create mode 100644 server/serializers/review_serializer.py rename server/serializers/{user.py => user_serializer.py} (81%) diff --git a/server/serializers/airport.py b/server/serializers/airport_serializer.py similarity index 100% rename from server/serializers/airport.py rename to server/serializers/airport_serializer.py diff --git a/server/serializers/dog.py b/server/serializers/dog_serializer.py similarity index 100% rename from server/serializers/dog.py rename to server/serializers/dog_serializer.py diff --git a/server/serializers/organization_serializer.py b/server/serializers/organization_serializer.py new file mode 100644 index 0000000..f7412f0 --- /dev/null +++ b/server/serializers/organization_serializer.py @@ -0,0 +1,8 @@ +from rest_framework import serializers +from server.models import Organization + + +class OrganizationSerializer(serializers.ModelSerializer): + class Meta: + model = Organization + fields = "__all__" diff --git a/server/serializers/review_serializer.py b/server/serializers/review_serializer.py new file mode 100644 index 0000000..1e784bd --- /dev/null +++ b/server/serializers/review_serializer.py @@ -0,0 +1,15 @@ +from rest_framework import serializers +from server.models import UserReview, OrganizationReview +from server.serializers import * + + +class UserReviewSerializer(serializers.ModelSerializer): + class Meta: + model = UserReview + fields = "__all__" + + +class OrganizationReviewSerializer(serializers.ModelSerializer): + class Meta: + model = OrganizationReview + fields = "__all__" diff --git a/server/serializers/user.py b/server/serializers/user_serializer.py similarity index 81% rename from server/serializers/user.py rename to server/serializers/user_serializer.py index a00b293..2b5bb5a 100644 --- a/server/serializers/user.py +++ b/server/serializers/user_serializer.py @@ -7,13 +7,7 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = User - fields = [ - "password", - "email", - "phone", - "passport", - "provider", - ] + fields = "__all__" def create(self, validated_data): if validated_data.get("password"): From c2614cee73ed8e673bd37450d73242ef2d5376e8 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:18:31 +0900 Subject: [PATCH 02/13] Rename models --- .../models/{airport.py => airport_model.py} | 0 server/models/{dog.py => dog_model.py} | 5 ++-- server/models/{user.py => user_model.py} | 26 ++++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) rename server/models/{airport.py => airport_model.py} (100%) rename server/models/{dog.py => dog_model.py} (81%) rename server/models/{user.py => user_model.py} (66%) diff --git a/server/models/airport.py b/server/models/airport_model.py similarity index 100% rename from server/models/airport.py rename to server/models/airport_model.py diff --git a/server/models/dog.py b/server/models/dog_model.py similarity index 81% rename from server/models/dog.py rename to server/models/dog_model.py index a490e2f..a396762 100644 --- a/server/models/dog.py +++ b/server/models/dog_model.py @@ -1,11 +1,10 @@ # from django.db import models from djongo import models -from .organization import Organization, OrganizationForm +from .organization_model import AbstractOrganization, OrganizationForm from django.conf import settings from djongo.storage import GridFSStorage - class Dog(models.Model): _id = models.ObjectIdField(primary_key=True) name = models.CharField(max_length=100) @@ -17,7 +16,7 @@ class Dog(models.Model): image = models.ImageField(upload_to="dogs", null=True) organization = models.EmbeddedField( - model_container=Organization, model_form_class=OrganizationForm + model_container=AbstractOrganization, model_form_class=OrganizationForm ) class Meta: diff --git a/server/models/user.py b/server/models/user_model.py similarity index 66% rename from server/models/user.py rename to server/models/user_model.py index cf8eed7..47fe9cf 100644 --- a/server/models/user.py +++ b/server/models/user_model.py @@ -1,12 +1,16 @@ from django.contrib.auth.models import AbstractBaseUser -from django.db import models +from djongo import models from django.contrib.auth.models import UserManager +import uuid -class User(AbstractBaseUser): - +class BaseUser(AbstractBaseUser): + id = models.ObjectIdField(primary_key=True) email = models.EmailField( - max_length=100, unique=True, verbose_name="Email", help_text="이메일" + max_length=100, + unique=True, + verbose_name="Email", + help_text="이메일", ) password = models.CharField( max_length=128, null=True, verbose_name="password", help_text="비밀번호" @@ -28,7 +32,21 @@ class User(AbstractBaseUser): max_length=255, null=True, verbose_name="token", help_text="Refresh Token" ) + class Meta: + abstract = True + + +class User(BaseUser): USERNAME_FIELD = "email" REQUIRED_FIELDS = [] objects = UserManager() + + def __str__(self): + return self.email + + def has_perm(self, perm, obj=None): + return True + + def has_module_perms(self, app_label): + return True From 0c97b70f9287a81ccc41d42deb2c4fcf285ac522 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:19:02 +0900 Subject: [PATCH 03/13] Update Organization abstractClass and basicClass --- .../{organization.py => organization_model.py} | 15 +++++++++++++++ 1 file changed, 15 insertions(+) rename server/models/{organization.py => organization_model.py} (69%) diff --git a/server/models/organization.py b/server/models/organization_model.py similarity index 69% rename from server/models/organization.py rename to server/models/organization_model.py index 7b5b860..9e3b16a 100644 --- a/server/models/organization.py +++ b/server/models/organization_model.py @@ -30,6 +30,21 @@ class Meta: class Organization(models.Model): + _id = models.ObjectIdField() + name = models.CharField(max_length=100) + ceo = models.CharField(max_length=100) + description = models.TextField() + phone = models.CharField(max_length=100) + images = models.ArrayField(model_container=Image, model_form_class=ImageForm) + donation = models.CharField(max_length=100) + fax = models.CharField(max_length=100) + email = models.CharField(max_length=100) + sns = models.ArrayField(model_container=SNS, model_form_class=SNSForm) + objects = models.DjongoManager() + + +class AbstractOrganization(models.Model): + _id = models.ObjectIdField() name = models.CharField(max_length=100) ceo = models.CharField(max_length=100) description = models.TextField() From 978ab91892072df631e82e23140c5958cf1b0b39 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:19:13 +0900 Subject: [PATCH 04/13] Add Review Model --- server/models/organization_review_model.py | 11 +++++++++++ server/models/user_review_model.py | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 server/models/organization_review_model.py create mode 100644 server/models/user_review_model.py diff --git a/server/models/organization_review_model.py b/server/models/organization_review_model.py new file mode 100644 index 0000000..0cd208b --- /dev/null +++ b/server/models/organization_review_model.py @@ -0,0 +1,11 @@ +from djongo import models +from server.models import BaseUser, Organization + + +class OrganizationReview(models.Model): + _id = models.ObjectIdField(primary_key=True) + comment = models.CharField(max_length=500) + image = models.CharField(max_length=500, default="") + createdAt = models.DateField(auto_now_add=True) + organization = models.EmbeddedField(model_container=Organization) + user = models.EmbeddedField(model_container=BaseUser) diff --git a/server/models/user_review_model.py b/server/models/user_review_model.py new file mode 100644 index 0000000..5b4eebf --- /dev/null +++ b/server/models/user_review_model.py @@ -0,0 +1,13 @@ +from djongo import models +from server.models import BaseUser, AbstractOrganization + + +class UserReview(models.Model): + _id = models.ObjectIdField(primary_key=True) + comment = models.CharField(max_length=500) + image = models.CharField(max_length=1000, default="") + createdAt = models.DateField(auto_now_add=True) + organization = models.EmbeddedField(model_container=AbstractOrganization) + user = models.EmbeddedField(model_container=BaseUser) + + objects = models.DjongoManager() From a86b920561cb4fb4158da5fde26dd1cdc7eee1b0 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:19:55 +0900 Subject: [PATCH 05/13] Update init file --- server/models/__init__.py | 11 +++++++---- server/serializers/__init__.py | 8 +++++--- server/views/__init__.py | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/models/__init__.py b/server/models/__init__.py index 6d299d6..04aa8fb 100644 --- a/server/models/__init__.py +++ b/server/models/__init__.py @@ -1,4 +1,7 @@ -from .airport import * -from .user import * -from .dog import * -from .organization import * +from .airport_model import * +from .user_model import * +from .dog_model import * +from .organization_model import * + +from .user_review_model import * +from .organization_review_model import * diff --git a/server/serializers/__init__.py b/server/serializers/__init__.py index afb2c52..40f4e0a 100644 --- a/server/serializers/__init__.py +++ b/server/serializers/__init__.py @@ -1,3 +1,5 @@ -from .airport import * -from .user import * -from .dog import * +from .airport_serializer import * +from .user_serializer import * +from .organization_serializer import * +from .dog_serializer import * +from .review_serializer import * diff --git a/server/views/__init__.py b/server/views/__init__.py index afb2c52..bd14c2b 100644 --- a/server/views/__init__.py +++ b/server/views/__init__.py @@ -1,3 +1,4 @@ from .airport import * from .user import * from .dog import * +from .review import * From 158f9641d9451e4ee000a6c70c2630d5f3562509 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:24:30 +0900 Subject: [PATCH 06/13] Rename module path --- server/views/airport.py | 3 +-- server/views/dog.py | 9 +++++---- server/views/user.py | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/server/views/airport.py b/server/views/airport.py index c0dcc13..70306fb 100644 --- a/server/views/airport.py +++ b/server/views/airport.py @@ -1,4 +1,4 @@ -from server.serializers.airport import * +from server.serializers.airport_serializer import * from rest_framework.response import Response from rest_framework.views import APIView from drf_yasg import openapi @@ -31,7 +31,6 @@ class AirportAPIView(APIView): def get_object(self, name): queryset = Airport.objects.all() - name_match = queryset.filter(name__contains=name) country_match = queryset.filter(country__contains=name) IATA_match = queryset.filter(IATA__contains=name) diff --git a/server/views/dog.py b/server/views/dog.py index 0fb28f0..65f0c39 100644 --- a/server/views/dog.py +++ b/server/views/dog.py @@ -1,5 +1,5 @@ -from server.models.dog import Dog -from server.serializers.dog import * +from server.models.dog_model import Dog +from server.serializers.dog_serializer import * from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.permissions import IsAuthenticated @@ -47,12 +47,13 @@ def get(self, request): } return Response(response_object) + class DogImageAPIView(APIView): def post(self, request): - dog_serializer = DogImageSerializer(data = request.data) + dog_serializer = DogImageSerializer(data=request.data) print(dog_serializer) if dog_serializer.is_valid(): dog_serializer.save() return Response({"message": "success"}) else: - return Response ({"message": "fail"}) + return Response({"message": "fail"}) diff --git a/server/views/user.py b/server/views/user.py index d492517..606cd3a 100644 --- a/server/views/user.py +++ b/server/views/user.py @@ -16,6 +16,7 @@ class SignupView(APIView): @swagger_auto_schema( + security=[], request_body=openapi.Schema( type=openapi.TYPE_OBJECT, properties={ @@ -61,6 +62,7 @@ def post(self, request): @swagger_auto_schema( methods=["POST"], + security=[], request_body=openapi.Schema( type=openapi.TYPE_OBJECT, properties={ @@ -116,6 +118,7 @@ def signin(request): @swagger_auto_schema( methods=["POST"], + security=[], request_body=openapi.Schema( type=openapi.TYPE_OBJECT, properties={ @@ -169,10 +172,11 @@ def kakao(request): @swagger_auto_schema( methods=["POST"], + security=[], request_body=openapi.Schema( type=openapi.TYPE_OBJECT, properties={ - "token": openapi.Schema(type=openapi.TYPE_STRING, description="리프레시 토큰"), + "token": openapi.Schema(type=openapi.IN_HEADER, description="리프레시 토큰"), }, ), responses={ From 171e43c8491468f6de6abfbbd31a629425093332 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:24:42 +0900 Subject: [PATCH 07/13] Update API URL --- server/urls.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/urls.py b/server/urls.py index 3bd4814..e8f2c1d 100644 --- a/server/urls.py +++ b/server/urls.py @@ -7,8 +7,9 @@ path("user/kakao", views.kakao), path("refresh", views.refresh), path("airport/", views.AirportAPIView.as_view()), - path('dog/list/', views.DogAPIView.as_view()), - path('dog/description/', views.DogDescriptionAPIView.as_view()), - path('dog/image/', views.DogImageAPIView.as_view()), + path("dog/list/", views.DogAPIView.as_view()), + path("dog/description/", views.DogDescriptionAPIView.as_view()), + path("dog/image/", views.DogImageAPIView.as_view()), path("upload/test", views.upload_test), + path("review/user", views.UserReviewAPIView.as_view()), ] From cecba345fb558ec17223224c4127981cb7701f97 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:25:11 +0900 Subject: [PATCH 08/13] Update JWT Middleware --- config/authentication.py | 7 +++---- server/utils/jwt.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/config/authentication.py b/config/authentication.py index c4f51cf..75d46e5 100644 --- a/config/authentication.py +++ b/config/authentication.py @@ -16,11 +16,10 @@ def authenticate(self, request): jwt_token, os.getenv("JWT_SECRET_KEY"), algorithms=["HS256"] ) id = decoded.get("id") - if token_type is "Bearer": + if token_type == "Bearer": user = User.objects.get(id=id) - # else: - # TODO : organization BigAutoField id 추가 - # user = Organization.objects.get(id=id) + else: + user = Organization.objects.get(id=id) return (user, None) except jwt.exceptions.DecodeError: raise exceptions.AuthenticationFailed( diff --git a/server/utils/jwt.py b/server/utils/jwt.py index 3a04972..b0e99a2 100644 --- a/server/utils/jwt.py +++ b/server/utils/jwt.py @@ -7,7 +7,7 @@ def generate_access_token(user): access_token_payload = { "id": user.id, - "exp": datetime.datetime.utcnow() + datetime.timedelta(days=0, minutes=5), + "exp": datetime.datetime.utcnow() + datetime.timedelta(days=1), "iat": datetime.datetime.utcnow(), } access_token = jwt.encode( From d1335aca6ac2c1db84d0218022c4c3e39004eaa7 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:25:29 +0900 Subject: [PATCH 09/13] Update Swagger Setting --- config/settings.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/settings.py b/config/settings.py index 87faaf7..1971eba 100644 --- a/config/settings.py +++ b/config/settings.py @@ -168,3 +168,14 @@ DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage" MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" + + +# Swagger + +SWAGGER_SETTINGS = { + "SHOW_REQUEST_HEADERS": True, + "SECURITY_DEFINITIONS": { + "Bearer": {"type": "apiKey", "name": "Authorization", "in": "header"} + }, + "JSON_EDITOR": True, +} From 0bb7e85ce288d316840e201a8556b5b86fe1d9e2 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:25:43 +0900 Subject: [PATCH 10/13] Add User Review API --- server/views/review.py | 136 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 server/views/review.py diff --git a/server/views/review.py b/server/views/review.py new file mode 100644 index 0000000..f11462b --- /dev/null +++ b/server/views/review.py @@ -0,0 +1,136 @@ +from rest_framework import status +from rest_framework.parsers import MultiPartParser +from server.serializers import * +from rest_framework.response import Response +from rest_framework.views import APIView +from rest_framework.permissions import IsAuthenticated +from drf_yasg.utils import swagger_auto_schema +from drf_yasg import openapi +from bson import ObjectId +from server.utils import success_util, error_collection +from server.utils.upload import upload_image +from django.forms.models import model_to_dict +from server.utils.json_util import jsonify + + +class UserReviewAPIView(APIView): + permission_classes = [IsAuthenticated] + parser_classes = (MultiPartParser,) + + @swagger_auto_schema( + operation_description="해당 유저 리뷰 불러오기, header에 액세스토큰을 넣어야한다.", + manual_parameters=[ + openapi.Parameter( + name="accessToken", + in_=openapi.IN_HEADER, + type=openapi.TYPE_STRING, + required=True, + description="액세스토큰", + ), + ], + responses={ + 200: success_util.SUCCESS_GET_USER_REVIEW.as_obj(), + }, + ) + def get(self, request): + user_id = request.user.id + user_reviews = UserReview.objects.filter(user={"id": user_id}) + user_reviews = list(model_to_dict(review) for review in user_reviews) + user_review_data = user_reviews + user_review_len = len(user_review_data) + response_object = { + "success": True, + "message": f"{user_review_len}개의 리뷰를 불러왔습니다.", + "data": jsonify(user_review_data), + } + return Response(response_object) + + def post_image(self, request): + image = request.FILES["image"] + try: + public_uri = upload_image(image, "user_review") + return public_uri + except: + return False + + @swagger_auto_schema( + operation_description="유저 리뷰 작성 API, 리뷰 시 header에 액세스토큰을 넣어야하고, 코멘트, 이미지, 기관 ID를 바디로 보내야 한다.", + manual_parameters=[ + openapi.Parameter( + name="accessToken", + in_=openapi.IN_HEADER, + type=openapi.TYPE_STRING, + required=True, + description="액세스토큰", + ), + openapi.Parameter( + name="image", + in_=openapi.IN_FORM, + type=openapi.TYPE_FILE, + required=True, + description="이미지 파일", + ), + openapi.Parameter( + name="comment", + in_=openapi.IN_FORM, + type=openapi.TYPE_STRING, + required=True, + description="리뷰 내용", + ), + openapi.Parameter( + name="org_id", + in_=openapi.IN_FORM, + type=openapi.TYPE_STRING, + required=True, + description="기관_id", + ), + ], + responses={ + 200: success_util.SUCCESS_ADD_USER_REVIEW.as_obj(), + 400: error_collection.REVIEW_400_NULL_REQUEST_DATA.as_md() + + error_collection.REVIEW_400_ADD_REVIEW_FAILED.as_md(), + }, + ) + def post(self, request): + user_id = request.user.id + if not request.data.get("comment") or not request.data.get("org_id"): + response_object = { + "success": False, + "message": "누락된 정보(코멘트, 기관ID)가 있습니다. 확인해주세요.", + "code": "REVIEW_400_NULL_REQUEST_DATA", + } + return Response(response_object, status=status.HTTP_400_BAD_REQUEST) + + data = {"comment": request.data["comment"]} + if request.data.get("image"): + image_save = self.post_image(request) + data["image"] = image_save + + user_data = User.objects.get(id=user_id) + user_data = model_to_dict(user_data) + user_data["id"] = user_id + del user_data["password"] + org_id = request.data["org_id"] + organization_data = Organization.objects.get(_id=ObjectId(org_id)) + organization_data = model_to_dict(organization_data) + data["user"] = user_data + data["organization"] = organization_data + serializer = UserReviewSerializer(data=data) + if serializer.is_valid(): + new_review = serializer.save() + return Response( + { + "success": True, + "message": "리뷰가 성공적으로 작성되었습니다.", + "data": jsonify(model_to_dict(new_review)), + } + ) + else: + print(serializer.errors) + return Response( + { + "success": False, + "message": "리뷰 저장 시 문제가 발생했습니다.", + "code": "REVIEW_400_ADD_REVIEW_FAILED", + } + ) From dc10e1890400515bbc6f62eb9aed4e49a8426ccb Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:26:02 +0900 Subject: [PATCH 11/13] Add json_util --- server/utils/json_util.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 server/utils/json_util.py diff --git a/server/utils/json_util.py b/server/utils/json_util.py new file mode 100644 index 0000000..960c00f --- /dev/null +++ b/server/utils/json_util.py @@ -0,0 +1,13 @@ +import json +from bson import ObjectId + + +class JSONEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, ObjectId): + return str(o) + return json.JSONEncoder.default(self, o) + + +def jsonify(data): + return json.loads(json.dumps(data, cls=JSONEncoder)) From b953bfb74877321d4d8db521ab4e1d59ac9a0747 Mon Sep 17 00:00:00 2001 From: ziho Date: Fri, 13 Aug 2021 20:26:25 +0900 Subject: [PATCH 12/13] Update swagger success, error collection --- server/utils/error_collection.py | 12 ++++ server/utils/success_util.py | 119 +++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/server/utils/error_collection.py b/server/utils/error_collection.py index af2b5ef..532056b 100644 --- a/server/utils/error_collection.py +++ b/server/utils/error_collection.py @@ -54,3 +54,15 @@ def as_md(self): status=status.HTTP_403_FORBIDDEN, message="refresh_token이 만료되었습니다.", ) + +REVIEW_400_NULL_REQUEST_DATA = ErrorCollection( + code="REVIEW_400_NULL_REQUEST_DATA", + status=status.HTTP_400_BAD_REQUEST, + message="누락된 정보(이미지, 코멘트, 기관ID)가 있습니다. 확인해주세요.", +) + +REVIEW_400_ADD_REVIEW_FAILED = ErrorCollection( + code="REVIEW_400_ADD_REVIEW_FAILED", + status=status.HTTP_400_BAD_REQUEST, + message="리뷰 저장 시 문제가 발생했습니다.", +) diff --git a/server/utils/success_util.py b/server/utils/success_util.py index 354e7a6..31ab7d1 100644 --- a/server/utils/success_util.py +++ b/server/utils/success_util.py @@ -1,4 +1,7 @@ from drf_yasg import openapi +from drf_yasg.openapi import Items + +from server.models import * class Success(object): @@ -70,3 +73,119 @@ def as_obj(self): "email": openapi.Schema(type=openapi.TYPE_STRING, description="이메일"), }, ) + +SUCCESS_ADD_USER_REVIEW = Success( + message="리뷰가 성공적으로 작성되었습니다.", + data={ + "_id": openapi.Schema(type=openapi.TYPE_STRING, description="리뷰 id"), + "comment": openapi.Schema(type=openapi.TYPE_STRING, description="리뷰 내용"), + "image": openapi.Schema( + type=openapi.TYPE_STRING, + description="리뷰 내용", + ), + "organization": openapi.Schema( + type=openapi.TYPE_OBJECT, + description="기관 정보", + properties={ + "_id": openapi.Schema(type=openapi.TYPE_STRING, description="기관 id"), + "name": openapi.Schema(type=openapi.TYPE_STRING, description="기관명"), + "ceo": openapi.Schema(type=openapi.TYPE_STRING, description="CEO"), + "description": openapi.Schema( + type=openapi.TYPE_STRING, description="기관 설명" + ), + "phone": openapi.Schema( + type=openapi.TYPE_STRING, description="기관 전화번호" + ), + "images": openapi.Schema( + type=openapi.TYPE_ARRAY, + description="이미지", + items=Items( + type=openapi.TYPE_STRING, + ), + ), + "donation": openapi.Schema( + type=openapi.TYPE_STRING, description="후원계좌" + ), + "fax": openapi.Schema(type=openapi.TYPE_STRING, description="팩스"), + "email": openapi.Schema(type=openapi.TYPE_STRING, description="이메일"), + "sns": openapi.Schema( + type=openapi.TYPE_ARRAY, + description="SNS", + items=Items( + type=openapi.TYPE_OBJECT, + ), + ), + }, + ), + "user": openapi.Schema( + type=openapi.TYPE_OBJECT, + description="유저 정보", + properties={ + "id": openapi.Schema(type=openapi.TYPE_INTEGER, description="유저 id"), + "email": openapi.Schema(type=openapi.TYPE_STRING, description="이메일"), + "phone": openapi.Schema(type=openapi.TYPE_STRING, description="전화번호"), + "passport": openapi.Schema( + type=openapi.TYPE_BOOLEAN, description="여권 인증유무", default=False + ), + }, + ), + }, +) + +SUCCESS_GET_USER_REVIEW = Success( + message="리뷰를 성공적으로 불러왔습니다.", + data={ + "_id": openapi.Schema(type=openapi.TYPE_STRING, description="리뷰 id"), + "comment": openapi.Schema(type=openapi.TYPE_STRING, description="리뷰 내용"), + "image": openapi.Schema( + type=openapi.TYPE_STRING, + description="리뷰 내용", + ), + "organization": openapi.Schema( + type=openapi.TYPE_OBJECT, + description="기관 정보", + properties={ + "_id": openapi.Schema(type=openapi.TYPE_STRING, description="기관 id"), + "name": openapi.Schema(type=openapi.TYPE_STRING, description="기관명"), + "ceo": openapi.Schema(type=openapi.TYPE_STRING, description="CEO"), + "description": openapi.Schema( + type=openapi.TYPE_STRING, description="기관 설명" + ), + "phone": openapi.Schema( + type=openapi.TYPE_STRING, description="기관 전화번호" + ), + "images": openapi.Schema( + type=openapi.TYPE_ARRAY, + description="이미지", + items=Items( + type=openapi.TYPE_STRING, + ), + ), + "donation": openapi.Schema( + type=openapi.TYPE_STRING, description="후원계좌" + ), + "fax": openapi.Schema(type=openapi.TYPE_STRING, description="팩스"), + "email": openapi.Schema(type=openapi.TYPE_STRING, description="이메일"), + "sns": openapi.Schema( + type=openapi.TYPE_ARRAY, + description="SNS", + items=Items( + type=openapi.TYPE_OBJECT, + ), + ), + }, + ), + "user": openapi.Schema( + type=openapi.TYPE_OBJECT, + description="유저 정보", + properties={ + "id": openapi.Schema(type=openapi.TYPE_INTEGER, description="유저 id"), + "email": openapi.Schema(type=openapi.TYPE_STRING, description="이메일"), + "phone": openapi.Schema(type=openapi.TYPE_STRING, description="전화번호"), + "passport": openapi.Schema( + type=openapi.TYPE_BOOLEAN, description="여권 인증유무", default=False + ), + }, + ), + }, +) From df79d1bd8a0a07de4ad143ea1f8fac41a5078ea9 Mon Sep 17 00:00:00 2001 From: ziho Date: Sun, 15 Aug 2021 18:51:22 +0900 Subject: [PATCH 13/13] Update organization model --- server/models/organization_model.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/server/models/organization_model.py b/server/models/organization_model.py index 9e3b16a..3fcfafd 100644 --- a/server/models/organization_model.py +++ b/server/models/organization_model.py @@ -3,7 +3,7 @@ class Image(models.Model): - url = models.URLField(max_length=200) + url = models.URLField(max_length=1000) class Meta: abstract = True @@ -29,20 +29,6 @@ class Meta: fields = ("sns", "name") -class Organization(models.Model): - _id = models.ObjectIdField() - name = models.CharField(max_length=100) - ceo = models.CharField(max_length=100) - description = models.TextField() - phone = models.CharField(max_length=100) - images = models.ArrayField(model_container=Image, model_form_class=ImageForm) - donation = models.CharField(max_length=100) - fax = models.CharField(max_length=100) - email = models.CharField(max_length=100) - sns = models.ArrayField(model_container=SNS, model_form_class=SNSForm) - objects = models.DjongoManager() - - class AbstractOrganization(models.Model): _id = models.ObjectIdField() name = models.CharField(max_length=100) @@ -59,6 +45,10 @@ class Meta: abstract = True +class Organization(AbstractOrganization): + objects = models.DjongoManager() + + class OrganizationForm(forms.ModelForm): class Meta: model = Organization