Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image_url을 S3 기반으로 제공하도록 변경 #88

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading