From 5ee17eb49d1a0e1422653384dd89e24fc76b848e Mon Sep 17 00:00:00 2001 From: jiyoon607 <6judy611@gmail.com> Date: Sat, 5 Oct 2024 21:08:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Feat:=20=EC=83=81=ED=99=A9=20?= =?UTF-8?q?=EB=B3=84=20=EB=AC=B8=EC=9E=90=20=EB=B0=9C=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sms/urls.py | 7 +++---- sms/views.py => utils/messages.py | 29 ++++++++++++++++++++--------- waiting/tasks.py | 9 +++++++++ 3 files changed, 32 insertions(+), 13 deletions(-) rename sms/views.py => utils/messages.py (68%) diff --git a/sms/urls.py b/sms/urls.py index b3a1c19..bc9fa95 100644 --- a/sms/urls.py +++ b/sms/urls.py @@ -1,12 +1,11 @@ from django.urls import path, include from rest_framework.routers import DefaultRouter -from .views import * app_name = 'sms' -router = DefaultRouter() -router.register(r'sendsms', sendsms, basename='sendsms') +#router = DefaultRouter() +#router.register(r'sendsms', sendsms, basename='sendsms') urlpatterns = [ - path('sms/sendsms', sendsms, name='sendsms') + #path('sms/sendsms', sendsms, name='sendsms') ] \ No newline at end of file diff --git a/sms/views.py b/utils/messages.py similarity index 68% rename from sms/views.py rename to utils/messages.py index ded8624..b5d28ad 100644 --- a/sms/views.py +++ b/utils/messages.py @@ -1,17 +1,25 @@ from rest_framework import status -from rest_framework.decorators import api_view from utils.responses import custom_response from django.conf import settings -import requests +import requests, re SSODAA_BASE_URL = settings.SSODAA_BASE_URL +SEND_PHONE = settings.SEND_PHONE # 문자 발송하기 -@api_view(['POST']) -def sendsms(request): - dest_phone = request.data.get('dest_phone') - msg_body = request.data.get('msg_body') - send_phone = settings.SEND_PHONE +def sendsms(dest_phone, msg_body): + # 데이터 형식 검증 + phone_pattern = re.compile(r'^\d{10,11}$') # 10자리 또는 11자리 숫자만 + if not phone_pattern.match(dest_phone): + return { + "message": "Invalid destination phone number.", + } + + if not isinstance(msg_body, str): + return { + "message": "Invalid message content.", + } + headers = { 'x-api-key': settings.SMS_API_KEY, @@ -22,9 +30,12 @@ def sendsms(request): "token_key": settings.SMS_TOKEN_KEY, "msg_type": 'sms', "dest_phone": dest_phone, - "send_phone": send_phone, + "send_phone": SEND_PHONE, "msg_body": msg_body, } + print(data) + return custom_response(data=data, message="perfect", code=status.HTTP_200_OK) + """ try: url = f"{SSODAA_BASE_URL}/sms/send/sms" response = requests.post(url, json=data, headers=headers) @@ -45,4 +56,4 @@ def sendsms(request): except requests.exceptions.RequestException: return custom_response(message="Failed to send messages.", code=status.HTTP_400_BAD_REQUEST, success=False) - \ No newline at end of file + """ \ No newline at end of file diff --git a/waiting/tasks.py b/waiting/tasks.py index 1004741..bc6b723 100644 --- a/waiting/tasks.py +++ b/waiting/tasks.py @@ -1,5 +1,6 @@ from celery import shared_task from django.utils import timezone +from utils.messages import sendsms @shared_task def check_ready_to_confirm(waiting_id): @@ -10,6 +11,10 @@ def check_ready_to_confirm(waiting_id): # 3분이 지났으면 확인하고 취소 처리 if waiting.is_ready_to_confirm_expired() and waiting.waiting_status == 'ready_to_confirm': waiting.set_time_over_canceled() # 시간 초과로 취소 처리 + # 문자 메시지 발송 + booth_name = waiting.booth.name + phone_number = waiting.user.phone_number + sendsms(phone_number, f"[라인나우] {booth_name} 부스에 입장 확정을 하지 않아, 대기가 취소되었어요") except Waiting.DoesNotExist: pass @@ -22,5 +27,9 @@ def check_confirmed(waiting_id): # 10분이 지났으면 취소 처리 if waiting.is_confirmed_expired(): waiting.set_canceled() # 대기 취소 처리 + # 문자 메시지 발송 + booth_name = waiting.booth.name + phone_number = waiting.user.phone_number + sendsms(phone_number, f"[라인나우] {booth_name} 부스에 입장하지 않아, 대기가 취소되었습니다.") except Waiting.DoesNotExist: pass \ No newline at end of file From 883142d654ceaaf8484d416e465f863b334b30a8 Mon Sep 17 00:00:00 2001 From: jiyoon607 <6judy611@gmail.com> Date: Sun, 6 Oct 2024 16:17:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20msm=20=EC=83=81?= =?UTF-8?q?=ED=99=A9=EB=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/migrations/0001_initial.py | 44 +++++++++++++++++++++++++++++ waiting/tasks.py | 4 +++ 2 files changed, 48 insertions(+) create mode 100644 accounts/migrations/0001_initial.py diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py new file mode 100644 index 0000000..784a795 --- /dev/null +++ b/accounts/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# Generated by Django 5.1.1 on 2024-10-05 23:56 + +import django.contrib.auth.models +import django.contrib.auth.validators +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('phone_number', models.CharField(max_length=20)), + ('nickname', models.CharField(max_length=20)), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/waiting/tasks.py b/waiting/tasks.py index 0859b99..b6857c2 100644 --- a/waiting/tasks.py +++ b/waiting/tasks.py @@ -13,21 +13,25 @@ def check_ready_to_confirm(waiting_id): waiting.set_time_over_canceled() # 시간 초과로 취소 처리 # 문자 메시지 발송 phone_number = waiting.user.phone_number + print(phone_number) sendsms(phone_number, f"[라인나우] 3분 내에 부스 입장을 확정하지 않아, 대기가 취소되었어요") except Waiting.DoesNotExist: pass @shared_task def check_confirmed(waiting_id): + print("기다림은 끝") """10분 후 입장 확정 상태에서 도착하지 않으면 time_over_canceled 상태로 변경""" from .models import Waiting try: + print("데이터가져와") waiting = Waiting.objects.get(pk=waiting_id) # 10분이 지났으면 취소 처리 if waiting.is_confirmed_expired() and waiting.waiting_status == 'confirmed': waiting.set_time_over_canceled() # 시간 초과로 취소 처리 # 문자 메시지 발송 phone_number = waiting.user.phone_number + print(phone_number) sendsms(phone_number, f"[라인나우] 10분 내에 부스에 입장하지 않아, 대기가 취소되었어요") except Waiting.DoesNotExist: pass \ No newline at end of file