From c1d9bc12e5f09ed9ad28545785cc374ee05d8165 Mon Sep 17 00:00:00 2001 From: dudtlstm Date: Sat, 5 Oct 2024 03:58:02 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix:=20=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=20=EC=83=81=EC=84=B8=EC=97=90=20=ED=95=B4?= =?UTF-8?q?=EB=8B=B9=20=EB=B6=80=EC=8A=A4=20=EC=A0=84=EC=B2=B4=20=EB=8C=80?= =?UTF-8?q?=EA=B8=B0=20=ED=8C=80=20=EC=88=98=20=EC=B6=94=EA=B0=80=20&=203?= =?UTF-8?q?=EB=B6=84/10=EB=B6=84=20=EB=8D=94=ED=95=9C=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- waiting/serializers.py | 68 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/waiting/serializers.py b/waiting/serializers.py index a59de41..feb9754 100644 --- a/waiting/serializers.py +++ b/waiting/serializers.py @@ -3,6 +3,7 @@ from booth.models import Booth from django.contrib.auth.models import User from django.utils import timezone +from datetime import timedelta # 나의 대기에서 부스 정보 확인용 !! - 아래의 시리얼라이저에서 사용됨 !! class BoothSerializer(serializers.ModelSerializer): @@ -27,12 +28,12 @@ class WaitingSerializer(serializers.ModelSerializer): username = serializers.CharField(source='user.username', read_only=True) registered_at = serializers.DateTimeField(read_only=True) waiting_teams_ahead = serializers.SerializerMethodField() # 내 앞에 있는 팀 수를 위한 필드 추가 - confirm_remaining_time = serializers.SerializerMethodField() # 3분 타이머 추가 - arrival_remaining_time = serializers.SerializerMethodField() # 10분 타이머 추가 + confirm_due_time = serializers.SerializerMethodField() # 3분 더한 시간 반환 + arrival_due_time = serializers.SerializerMethodField() # 10분 더한 시간 반환 class Meta: model = Waiting - fields = ['id', 'username', 'booth','party_size', 'waiting_status', 'registered_at', 'ready_to_confirm_at', 'confirmed_at', 'canceled_at', 'waiting_teams_ahead', 'confirm_remaining_time', 'arrival_remaining_time'] + fields = ['id', 'username', 'booth','party_size', 'waiting_status', 'registered_at', 'ready_to_confirm_at', 'confirmed_at', 'canceled_at', 'waiting_teams_ahead', 'confirm_due_time', 'arrival_due_time'] def get_waiting_teams_ahead(self, obj): return Waiting.objects.filter( @@ -41,21 +42,17 @@ def get_waiting_teams_ahead(self, obj): waiting_status='waiting' ).count() - # 3분 타이머 필드 - def get_confirm_remaining_time(self, obj): - if obj.waiting_status == 'ready_to_confirm' and obj.ready_to_confirm_at: - elapsed_time = (timezone.now() - obj.ready_to_confirm_at).total_seconds() - minutes, seconds = divmod(max(0, 180 - elapsed_time), 60) - return f'{int(minutes)}:{int(seconds)}' - return "00:00" + # 3분 더한 시간 반환 + def get_confirm_due_time(self, obj): + if obj.ready_to_confirm_at: + return obj.ready_to_confirm_at + timedelta(minutes=3) + return None - # 10분 타이머 필드 - def get_arrival_remaining_time(self, obj): - if obj.waiting_status == 'confirmed' and obj.confirmed_at: - elapsed_time = (timezone.now() - obj.confirmed_at).total_seconds() - minutes, seconds = divmod(max(0, 600 - elapsed_time), 60) - return f'{int(minutes)}:{int(seconds)}' - return "00:00" + # 10분 더한 시간 반환 + def get_arrival_due_time(self, obj): + if obj.confirmed_at: + return obj.confirmed_at + timedelta(minutes=10) + return None # 나의 웨이팅 디테일 class WaitingDetailSerializer(serializers.ModelSerializer): @@ -63,12 +60,13 @@ class WaitingDetailSerializer(serializers.ModelSerializer): username = serializers.CharField(source='user.username', read_only=True) registered_at = serializers.DateTimeField(read_only=True) waiting_teams_ahead = serializers.SerializerMethodField() - confirm_remaining_time = serializers.SerializerMethodField() # 3분 타이머 추가 - arrival_remaining_time = serializers.SerializerMethodField() # 10분 타이머 추가 + total_waiting_teams = serializers.SerializerMethodField() + confirm_due_time = serializers.SerializerMethodField() # 3분 더한 시간 반환 + arrival_due_time = serializers.SerializerMethodField() # 10분 더한 시간 반환 class Meta: model = Waiting - fields = ['id', 'username', 'booth', 'party_size', 'waiting_status', 'registered_at', 'ready_to_confirm_at', 'confirmed_at', 'canceled_at', 'waiting_teams_ahead', 'confirm_remaining_time', 'arrival_remaining_time'] + fields = ['id', 'username', 'booth', 'party_size', 'waiting_status', 'registered_at', 'ready_to_confirm_at', 'confirmed_at', 'canceled_at', 'waiting_teams_ahead', 'total_waiting_teams', 'confirm_due_time', 'arrival_due_time'] def get_waiting_teams_ahead(self, obj): return Waiting.objects.filter( @@ -76,22 +74,24 @@ def get_waiting_teams_ahead(self, obj): created_at__lt=obj.created_at, waiting_status='waiting' ).count() + + def get_total_waiting_teams(self, obj): + return Waiting.objects.filter( + booth=obj.booth, + waiting_status='waiting' + ).count() - # 3분 타이머 필드 - def get_confirm_remaining_time(self, obj): - if obj.waiting_status == 'ready_to_confirm' and obj.ready_to_confirm_at: - elapsed_time = (timezone.now() - obj.ready_to_confirm_at).total_seconds() - minutes, seconds = divmod(max(0, 180 - elapsed_time), 60) - return f'{int(minutes)}:{int(seconds)}' - return "00:00" + # 3분 더한 시간 반환 + def get_confirm_due_time(self, obj): + if obj.ready_to_confirm_at: + return obj.ready_to_confirm_at + timedelta(minutes=3) + return None - # 10분 타이머 필드 - def get_arrival_remaining_time(self, obj): - if obj.waiting_status == 'confirmed' and obj.confirmed_at: - elapsed_time = (timezone.now() - obj.confirmed_at).total_seconds() - minutes, seconds = divmod(max(0, 600 - elapsed_time), 60) - return f'{int(minutes)}:{int(seconds)}' - return "00:00" + # 10분 더한 시간 반환 + def get_arrival_due_time(self, obj): + if obj.confirmed_at: + return obj.confirmed_at + timedelta(minutes=10) + return None # 웨이팅 등록 관련 시리얼라이저 class WaitingCreateSerializer(serializers.ModelSerializer):