Skip to content

Commit

Permalink
๐Ÿฉน Fix: ๋ถ€์Šค ๋ฆฌ์ŠคํŠธ & ๋””ํ…Œ์ผ - ๋Œ€๊ธฐ ํŒ€ ์ˆ˜, ๋‚ด ์•ž์— ๋Œ€๊ธฐ ํŒ€ ์ˆ˜, ๋‚ด waiting_id ์ˆ˜์ • ๋ฐ ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
  • Loading branch information
dudtlstm committed Oct 7, 2024
1 parent d33152e commit 25a5931
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
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

0 comments on commit 25a5931

Please sign in to comment.