Skip to content

Commit

Permalink
✨ Feat : 부스 위치 정보반환, 좋아요 기준 top3 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeunho1227 committed May 22, 2024
1 parent 16be098 commit 07ce677
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions booth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Meta:
'thumbnail',
'operator',
'location',
'latitude',
'longitude',
'like_cnt',
'during',
]
Expand Down
11 changes: 9 additions & 2 deletions booth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_serializer_class(self):

def list(self, request, *args, **kwargs):
date = request.query_params.get('date')
queryset = self.filter_queryset(self.get_queryset())
queryset = self.filter_queryset(self.get_queryset().order_by('-like_cnt'))

serializer = self.get_serializer(queryset, many=True, context={'request': request, 'date': date})
return Response(serializer.data)
Expand Down Expand Up @@ -109,4 +109,11 @@ def likes(self, request, pk=None):
def location(self, request, pk=None):
booth = self.get_object()
serializer = self.get_serializer(booth)
return Response(serializer.data)
return Response(serializer.data)

@action(detail=False, methods=['GET'], url_path='top3')
def top3(self, request):
queryset = self.filter_queryset(self.get_queryset())
top3 = queryset.order_by('-like_cnt')[:3]
top3_serializer = BoothListSerializer(top3, many=True, context = {'request': request})
return Response( top3_serializer.data )

0 comments on commit 07ce677

Please sign in to comment.