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

🩹 Fix: λΆ€μŠ€ 리슀트 & λ””ν…ŒμΌ - λŒ€κΈ° νŒ€ 수, λ‚΄ μ•žμ— λŒ€κΈ° νŒ€ 수, λ‚΄ waiting_id μˆ˜μ • 및 μΆ”κ°€ #104

Merged
merged 1 commit into from
Oct 7, 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
51 changes: 43 additions & 8 deletions booth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ class Meta:
model = BoothMenu
fields = ['name', 'price']

# λΆ€μŠ€ 리슀트
class BoothListSerializer(serializers.ModelSerializer):
thumbnail = serializers.SerializerMethodField()
waiting_count = serializers.SerializerMethodField()
# μ‚¬μš©μž λŒ€κΈ° κ΄€λ ¨
is_waiting = serializers.SerializerMethodField()
waiting_status = serializers.SerializerMethodField()
# λŒ€κΈ° νŒ€ 수 κ΄€λ ¨
total_waiting_teams = serializers.SerializerMethodField()

class Meta:
model = Booth
fields = ['id', 'name', 'description', 'location', 'is_operated', 'thumbnail', 'waiting_count', 'is_waiting', 'waiting_status']
fields = ['id', 'name', 'description', 'location', 'is_operated', 'thumbnail', 'total_waiting_teams', 'is_waiting', 'waiting_status']

def get_thumbnail(self, obj):
# 첫 번째 이미지가 썸넀일 ! !
Expand All @@ -34,8 +36,11 @@ def get_thumbnail(self, obj):
return request.build_absolute_uri(thumbnail.image.url)
return ''

def get_waiting_count(self, obj):
return obj.waitings.count()
def get_total_waiting_teams(self, obj):
return Waiting.objects.filter(
booth=obj,
waiting_status__in=['waiting', 'ready_to_confirm', 'confirmed']
).count()

# μ‚¬μš©μž λŒ€κΈ° κ΄€λ ¨
def get_is_waiting(self, obj):
Expand All @@ -62,20 +67,41 @@ class Meta:
model = BoothImage
fields = ['image']

# λΆ€μŠ€ λ””ν…ŒμΌ
class BoothDetailSerializer(serializers.ModelSerializer):
menu = BoothMenuSerializer(many=True, source='menus')
images = BoothImageSerializer(source='boothimages', many=True)
waiting_count = serializers.SerializerMethodField()
# μ‚¬μš©μž λŒ€κΈ° κ΄€λ ¨
is_waiting = serializers.SerializerMethodField()
waiting_status = serializers.SerializerMethodField()
waiting_id = serializers.SerializerMethodField()
# λŒ€κΈ° νŒ€ 수 κ΄€λ ¨
waiting_teams_ahead = serializers.SerializerMethodField()
total_waiting_teams = serializers.SerializerMethodField()

class Meta:
model = Booth
fields = ['id', 'name', 'description', 'location', 'caution', 'is_operated', 'images', 'menu', 'open_time', 'close_time', 'waiting_count', 'is_waiting', 'waiting_status']
fields = ['id', 'name', 'description', 'location', 'caution', 'is_operated', 'images', 'menu', 'open_time', 'close_time', 'total_waiting_teams', 'waiting_teams_ahead', 'is_waiting', 'waiting_id', 'waiting_status']

def get_waiting_count(self, obj):
return obj.waitings.count()
# λŒ€κΈ° νŒ€ 수 κ΄€λ ¨
def get_waiting_teams_ahead(self, obj):
request = self.context.get('request')
if request and request.user.is_authenticated:
current_waiting = Waiting.objects.filter(user=request.user, booth=obj).order_by('-registered_at').first()
if current_waiting:
# ν˜„μž¬ μœ μ €μ˜ 등둝 μ‹œμ λ³΄λ‹€ 이전에 λ“±λ‘ν•œ μ‚¬λžŒλ“€ (waiting, ready_to_confirm, confirmed μƒνƒœλ§Œ 체크)
return Waiting.objects.filter(
booth=obj,
waiting_status__in=['waiting', 'ready_to_confirm', 'confirmed'],
registered_at__lt=current_waiting.registered_at
).count()
return 0

def get_total_waiting_teams(self, obj):
return Waiting.objects.filter(
booth=obj,
waiting_status__in=['waiting', 'ready_to_confirm', 'confirmed']
).count()

# μ‚¬μš©μž λŒ€κΈ° κ΄€λ ¨
def get_is_waiting(self, obj):
Expand All @@ -88,6 +114,15 @@ def get_is_waiting(self, obj):
).exists()
return False

def get_waiting_id(self, obj):
request = self.context.get('request')
# is_waiting=true일 λ•Œλ§Œ waiting_idλ₯Ό λ°˜ν™˜
if self.get_is_waiting(obj):
waiting = Waiting.objects.filter(user=request.user, booth=obj).order_by('-registered_at').first()
if waiting:
return waiting.id
return None

def get_waiting_status(self, obj):
request = self.context.get('request')
if request and request.user.is_authenticated:
Expand Down
9 changes: 9 additions & 0 deletions booth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def get_booth_count(self, request):
return custom_response({'booth_count': booth_count}, message='Booth count fetched successfully')
except Exception as e:
return custom_response(data=None, message=str(e), code=status.HTTP_500_INTERNAL_SERVER_ERROR, success=False)

def retrieve(self, request, *args, **kwargs):
try:
booth = self.get_object()
serializer = self.get_serializer(booth)
return custom_response(data=serializer.data, message="Booth detail fetched successfully", code=status.HTTP_200_OK)
except Exception as e:
return custom_response(data=None, message=str(e), code=status.HTTP_500_INTERNAL_SERVER_ERROR, success=False)


# μ—λŸ¬ λ„μš°κΈ° μœ„ν•œ ν•¨μˆ˜
@action(detail=False, methods=['get'], url_path='error')
Expand Down
Loading