Skip to content

Commit

Permalink
fix: 응답에 식당 추가 여부 포함
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfla committed Aug 14, 2024
1 parent cdfaeb9 commit b19072d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions restaurants/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class RestaurantDetailSerializer(serializers.ModelSerializer):
reviews = serializers.SerializerMethodField()
rating_average = serializers.SerializerMethodField()
image_url = serializers.SerializerMethodField()
isExist = serializers.SerializerMethodField()

class Meta:
model = Restaurant
Expand All @@ -91,6 +92,12 @@ def get_reviews(self, obj):
def get_rating_average(self, obj):
return str(obj.rating_average())

def get_isExist(self, obj):
request = self.context.get("request")
return UserRestaurantsList.objects.filter(
user=request.user, restaurant=obj
).exists()

def get_image_url(self, obj):
if obj.image_url: # image_url이 null이 아닌 경우에만 처리
base_url = "https://mugou.s3.ap-southeast-2.amazonaws.com/images/"
Expand Down
4 changes: 3 additions & 1 deletion restaurants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def add_remove_restaurant(request, pk):
def restaurant_detail(request, pk):
try:
restaurant = Restaurant.objects.prefetch_related("reviews").get(pk=pk)
serializer = RestaurantDetailSerializer(restaurant)
serializer = RestaurantDetailSerializer(
restaurant, context={"request": request}
)
return Response(serializer.data)
except Restaurant.DoesNotExist:
return Response(
Expand Down

0 comments on commit b19072d

Please sign in to comment.