From d291d22a1bd9bd564328dc766778520a8f07d734 Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Sun, 4 Aug 2024 17:49:37 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=EB=A0=88=EC=8A=A4=ED=86=A0=EB=9E=91?= =?UTF-8?q?=EC=97=90=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20url=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0006_restaurant_image_url.py | 17 +++++++++++++++++ restaurants/models.py | 1 + 2 files changed, 18 insertions(+) create mode 100644 restaurants/migrations/0006_restaurant_image_url.py diff --git a/restaurants/migrations/0006_restaurant_image_url.py b/restaurants/migrations/0006_restaurant_image_url.py new file mode 100644 index 0000000..8bbd7a0 --- /dev/null +++ b/restaurants/migrations/0006_restaurant_image_url.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.14 on 2024-08-04 08:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("restaurants", "0005_restaurant_food_type"), + ] + + operations = [ + migrations.AddField( + model_name="restaurant", + name="image_url", + field=models.URLField(blank=True, max_length=500, null=True), + ), + ] diff --git a/restaurants/models.py b/restaurants/models.py index 522e095..b010332 100644 --- a/restaurants/models.py +++ b/restaurants/models.py @@ -19,6 +19,7 @@ class Restaurant(models.Model): address = models.CharField(max_length=255) latitude = models.DecimalField(max_digits=11, decimal_places=8) longitude = models.DecimalField(max_digits=11, decimal_places=8) + image_url = models.URLField(max_length=500, null=True, blank=True) def rating_average(self): ratings = [self.rating_naver, self.rating_kakao, self.rating_google] From effe665b3238eb42b0663b419527cf8a9dccc688 Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Sun, 4 Aug 2024 18:05:45 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EB=82=B4=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=91=EB=8B=B5=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restaurants/serializers.py | 10 +++++++++- restaurants/views.py | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/restaurants/serializers.py b/restaurants/serializers.py index 7124756..e959175 100644 --- a/restaurants/serializers.py +++ b/restaurants/serializers.py @@ -43,7 +43,15 @@ class RestaurantlistSerializer(serializers.ModelSerializer): class Meta: model = Restaurant - fields = ["id", "name", "food_type", "rating_average", "latitude", "longitude"] + fields = [ + "id", + "name", + "food_type", + "rating_average", + "latitude", + "longitude", + "image_url", + ] def get_rating_average(self, obj): return obj.rating_average() diff --git a/restaurants/views.py b/restaurants/views.py index 6885cb7..61dd7f1 100644 --- a/restaurants/views.py +++ b/restaurants/views.py @@ -7,7 +7,7 @@ RestaurantSerializer, RestaurantListSerializer, SearchHistorySerializer, - UserRestaurantListSerializer, + RestaurantlistSerializer, RestaurantDetailSerializer, ) @@ -70,11 +70,18 @@ def search(request): @api_view(["GET"]) # @login_required def user_restaurant_list(request): - user = User.objects.get(id=21) # 임시 유저 지정, 추후 삭제 - user_restaurants = UserRestaurantsList.objects.filter(user=user) # 추후 삭제 - # user_restaurants = UserRestaurantsList.objects.filter(user=request.user) - serializer = UserRestaurantListSerializer(user_restaurants, many=True) - return Response(serializer.data, status=status.HTTP_200_OK) + try: + user = User.objects.get(id=21) # 임시 유저 지정, 추후 삭제 + user_restaurants = UserRestaurantsList.objects.filter(user=user) # 추후 삭제 + # user_restaurants = UserRestaurantsList.objects.filter(user=request.user) + restaurant_ids = user_restaurants.values_list("restaurant_id", flat=True) + restaurants = Restaurant.objects.filter(id__in=restaurant_ids) + serializer = RestaurantlistSerializer(restaurants, many=True) + return Response({"results": serializer.data}, status=status.HTTP_200_OK) + except User.DoesNotExist: + return Response( + {"message": "Default user not found"}, status=status.HTTP_404_NOT_FOUND + ) @csrf_exempt From 93388aa1b257894511dbc5054b144acdd950eb89 Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Sun, 4 Aug 2024 18:15:47 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=EC=B9=9C=EA=B5=AC=20=EC=8B=9D?= =?UTF-8?q?=EB=8B=B9=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 11 ++++++++++- friends/views.py | 11 +++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/friends/serializers.py b/friends/serializers.py index 7851345..21da8a4 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -52,7 +52,16 @@ class RestaurantlistSerializer(serializers.ModelSerializer): class Meta: model = Restaurant - fields = ["id", "name", "food_type", "rating_average", "latitude", "longitude"] + fields = [ + "id", + "name", + "food_type", + "rating_average", + "address", + "latitude", + "longitude", + "image_url", + ] def get_rating_average(self, obj): return obj.rating_average() diff --git a/friends/views.py b/friends/views.py index e6b551b..8668491 100644 --- a/friends/views.py +++ b/friends/views.py @@ -4,11 +4,11 @@ from rest_framework import status # from django.contrib.auth.decorators import login_required -from restaurants.models import UserRestaurantsList +from restaurants.models import UserRestaurantsList, Restaurant from .serializers import ( FriendSerializer, FriendRequestSerializer, - FriendRestaurantSerializer, + RestaurantlistSerializer, ) from accounts.models import User from .models import Friend @@ -24,9 +24,12 @@ def friend_restaurant_list(request, id): # 친구의 맛집 리스트를 가져옴 friend_restaurants = UserRestaurantsList.objects.filter(user=friend) - serializer = FriendRestaurantSerializer(friend_restaurants, many=True) + restaurant_ids = friend_restaurants.values_list("restaurant_id", flat=True) + restaurants = Restaurant.objects.filter(id__in=restaurant_ids) - return Response({"restaurants": serializer.data}, status=status.HTTP_200_OK) + serializer = RestaurantlistSerializer(restaurants, many=True) + + return Response({"results": serializer.data}, status=status.HTTP_200_OK) except User.DoesNotExist: return Response( {"message": "Friend not found"}, status=status.HTTP_404_NOT_FOUND From 3aa51d4b08658548ae3294eff105ec11fe8be4e5 Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Sun, 4 Aug 2024 18:19:43 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=EC=9D=91=EB=8B=B5=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20=EC=A3=BC=EC=86=8C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 21da8a4..9836516 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -57,7 +57,6 @@ class Meta: "name", "food_type", "rating_average", - "address", "latitude", "longitude", "image_url",