Skip to content

Commit

Permalink
Merge pull request #76 from dudtlstm/fix/waiting
Browse files Browse the repository at this point in the history
🩹 Fix: 나의 대기 상세에 해당 부스 전체 대기 팀 수 추가 & 3분/10분 더한 필드로 수정
  • Loading branch information
dudtlstm authored Oct 4, 2024
2 parents b9bba27 + c1d9bc1 commit 58eab82
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions waiting/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand All @@ -41,57 +42,56 @@ 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):
booth = BoothSerializer(read_only=True)
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(
booth=obj.booth,
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):
Expand Down

0 comments on commit 58eab82

Please sign in to comment.