diff --git a/booth/serializers.py b/booth/serializers.py index 22495be..2a1b7d2 100644 --- a/booth/serializers.py +++ b/booth/serializers.py @@ -82,6 +82,8 @@ class Meta: 'thumbnail', 'operator', 'location', + 'latitude', + 'longitude', 'like_cnt', 'during', ] diff --git a/booth/views.py b/booth/views.py index 97cf580..ff982ed 100644 --- a/booth/views.py +++ b/booth/views.py @@ -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) @@ -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) \ No newline at end of file + 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 ) \ No newline at end of file