Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat: 대기등록, 운영 종료 문자 추가 #96

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ def update_status(self, request, *args, **kwargs):
for waiting in Waiting.objects.filter(booth=booth, waiting_status='waiting'):
waiting.set_canceled()
waiting.save()
# 취소 처리 Sms 전송 구현 예정

# 취소 처리 문자 메시지 발송
phone_number = waiting.user.phone_number
sendsms(phone_number, f"[라인나우] 대기 등록한 부스의 운영이 종료되어, 대기가 취소되었어요")
# 대기 중인 팀들을 모두 삭제 처리
waiting.delete()

Expand Down
7 changes: 2 additions & 5 deletions utils/sendmessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ def sendsms(dest_phone, msg_body):
"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)
response = response.json()
status_code = int(response.get('code'))

print(response)
if status_code == 200:
content = response.get('content')
data = {
Expand All @@ -56,4 +54,3 @@ def sendsms(dest_phone, msg_body):

except requests.exceptions.RequestException:
return custom_response(message="Failed to send messages.", code=status.HTTP_400_BAD_REQUEST, success=False)
"""
3 changes: 1 addition & 2 deletions waiting/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def check_ready_to_confirm(waiting_id):
pass

@shared_task
def check_confirmed(waiting_id):
def check_confirmed(waiting_id, phone_number):
print("기다림은 끝")
"""10분 후 입장 확정 상태에서 도착하지 않으면 time_over_canceled 상태로 변경"""
from .models import Waiting
Expand All @@ -30,7 +30,6 @@ def check_confirmed(waiting_id):
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:
Expand Down
9 changes: 6 additions & 3 deletions waiting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.db.models import Q
from utils.permissions import IsUser
from .tasks import check_confirmed
from utils.sendmessages import sendsms


class WaitingViewSet(viewsets.GenericViewSet):
Expand Down Expand Up @@ -71,6 +72,9 @@ def register_waiting(self, request, pk=None):
raise CustomException("User not found.")

serializer.save(booth=booth, user=user)
# 문자 메시지 발송
phone_number = user.phone_number
sendsms(phone_number, f"[라인나우] 대기가 등록되었어요 추후 입장 확정 문자를 확인해 주세요!")
return custom_response(data=serializer.data, message="Waiting registered successfully !", code=status.HTTP_201_CREATED)

return custom_response(data=serializer.errors, message="Failed to register waiting.", code=status.HTTP_400_BAD_REQUEST, success=False)
Expand All @@ -90,10 +94,9 @@ def confirm_waiting(self, request, pk=None):
waiting = get_object_or_404(Waiting, pk=pk, user=user)

if waiting.waiting_status == 'ready_to_confirm':
waiting.set_confirmed()

waiting.set_confirmed()
# 10분 후 check_confirmed task 호출
check_confirmed.apply_async((waiting.id,), countdown=600) # 10분 (600초) 후 실행
check_confirmed.apply_async((waiting.id, waiting.user.phone_number), countdown=600) # 10분 (600초) 후 실행

return custom_response(message="Waiting confirmed successfully.", code=status.HTTP_200_OK)
return custom_response(message="Unable to confirm waiting in current status.", code=status.HTTP_400_BAD_REQUEST, success=False)
Expand Down
Loading