From 73248e0fa62f7ccc923a82e5513a65d5a651841c Mon Sep 17 00:00:00 2001 From: sm4640 Date: Fri, 16 May 2025 03:39:13 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20[#56]=20=EC=B4=88=EB=8C=80?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=84=9C=EB=B9=84=EC=8A=A4(url=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1,=20=EC=BD=94=EB=93=9C=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=EA=B2=80=EC=82=AC,=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=B4=88=EB=8C=80)=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/services.py | 57 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/codes/services.py b/codes/services.py index 0ffe8ad..7b6693c 100644 --- a/codes/services.py +++ b/codes/services.py @@ -10,16 +10,25 @@ from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status -from .models import CertificationCode +from .models import * -from common.models.choiceModels import CertificateCodeUseType +from common.models.choiceModels import CertificateCodeUseType, InviteCodeUseType from common.utils.codeManger import set_expire from solapi import SolapiMessageService from solapi.model import RequestMessage +from users.models import User + +from projects.models import Project, ProjectTeamList + # from .schemas import send_sms_post_schema # Swagger나 drf-spectacular 등에 사용되는 데코레이터 +INVITE_CHOICE_USE_TYPE ={ + 'p': InviteCodeUseType.PROJECT, + 'h': InviteCodeUseType.HACKATHON +} + class CertificateService: @staticmethod def send(code, identifier): @@ -79,4 +88,46 @@ class SmsService(CertificateService): return True except Exception as e: # print(f"메시지 발송 실패: {str(e)}") - return False \ No newline at end of file + return False + + +class InviteService: + + # 종류마다 사용하는 테이블이 다르므로 오버라이딩 + @staticmethod + def add_member(invitee, work): + pass + + # url 생성 + @staticmethod + def create_invite_object_and_url(use_type, identifier, code) -> str: + InviteCode.objects.create( + use_type = INVITE_CHOICE_USE_TYPE[use_type], + code = code, + expire_at = set_expire(10080), + identifier = identifier, + ) + return f"https://{settings.DOMAIN_NAME}/invite?t={use_type}&i={identifier}&c={code}" + + # 코드 유효성 검사 + @staticmethod + def check_code(use_type, identifier, code) -> bool: + if InviteCode.objects.filter( + use_type = INVITE_CHOICE_USE_TYPE[use_type], + identifier = identifier, + code = code, + expire_at__gte=now() + ).exists(): + return True + else: + return False + + +class ProjectInviteService(InviteService): + + # 사용자 초대 + @staticmethod + def add_member(invitee: User, work: Project): + return ProjectTeamList.objects.create(user=invitee, project=work) + +