Skip to content

Commit

Permalink
fix: image_url을 S3 기반으로 제공하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyDimension committed Aug 12, 2024
1 parent 21025d3 commit 2a841e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions friends/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Meta:

class RestaurantlistSerializer(serializers.ModelSerializer):
rating_average = serializers.SerializerMethodField()
image_url = serializers.SerializerMethodField()

class Meta:
model = Restaurant
Expand All @@ -132,6 +133,13 @@ class Meta:
def get_rating_average(self, obj):
return obj.rating_average()

def get_image_url(self, obj):
if obj.image_url: # image_url이 null이 아닌 경우에만 처리
base_url = "https://mugou.s3.ap-southeast-2.amazonaws.com/images/"
image_name = f"{obj.name}.jpg" # 식당 이름을 사용하여 이미지 파일명 생성
return f"{base_url}{image_name}"
return None


class RestaurantSerializer(serializers.ModelSerializer):
# reviews = serializers.SerializerMethodField()
Expand Down
8 changes: 8 additions & 0 deletions restaurants/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Meta:

class RestaurantlistSerializer(serializers.ModelSerializer):
rating_average = serializers.SerializerMethodField()
image_url = serializers.SerializerMethodField()

class Meta:
model = Restaurant
Expand All @@ -56,6 +57,13 @@ class Meta:
def get_rating_average(self, obj):
return obj.rating_average()

def get_image_url(self, obj):
if obj.image_url: # image_url이 null이 아닌 경우에만 처리
base_url = "https://mugou.s3.ap-southeast-2.amazonaws.com/images/"
image_name = f"{obj.name}.jpg" # 식당 이름을 사용하여 이미지 파일명 생성
return f"{base_url}{image_name}"
return None


class UserRestaurantListSerializer(serializers.ModelSerializer):
restaurant = RestaurantlistSerializer()
Expand Down

0 comments on commit 2a841e8

Please sign in to comment.