From 242487cabd202f01b15e1e4460cf593c6d36b693 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 01/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/friends/views.py b/friends/views.py index 121f247..6117877 100644 --- a/friends/views.py +++ b/friends/views.py @@ -2,6 +2,10 @@ from rest_framework.decorators import api_view from rest_framework.views import APIView +# from rest_framework.authentication import TokenAuthentication +# from rest_framework.permissions import IsAuthenticated +from rest_framework.views import APIView + # from rest_framework.authentication import TokenAuthentication # from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -14,6 +18,7 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, + # RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer From 2005d9798028cffaef42d22e167c6f41be50b4df Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 02/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/views.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/friends/views.py b/friends/views.py index 6117877..b7f6e66 100644 --- a/friends/views.py +++ b/friends/views.py @@ -2,10 +2,6 @@ from rest_framework.decorators import api_view from rest_framework.views import APIView -# from rest_framework.authentication import TokenAuthentication -# from rest_framework.permissions import IsAuthenticated -from rest_framework.views import APIView - # from rest_framework.authentication import TokenAuthentication # from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -18,7 +14,6 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, - # RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer @@ -221,4 +216,4 @@ def decline_request(self, request, friend_id): friend_request.state = "declined" friend_request.save() - return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) + return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) \ No newline at end of file From bf8bb11c17f36380ebf2262a0d181e12aebf03ec Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 03:02:32 +0900 Subject: [PATCH 03/28] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/models.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/friends/models.py b/friends/models.py index 41e315d..cd13ef2 100644 --- a/friends/models.py +++ b/friends/models.py @@ -1,8 +1,6 @@ from django.db import models from accounts.models import User -# Create your models here. - class Friend(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="friends") From 0b2e8a1b1ae5820d94c7e140f5906c9a23ce45b5 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Tue, 6 Aug 2024 01:59:33 +0900 Subject: [PATCH 04/28] =?UTF-8?q?fix:=20settings.py=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mustgou/settings.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mustgou/settings.py b/mustgou/settings.py index c5c34b0..8a599fd 100644 --- a/mustgou/settings.py +++ b/mustgou/settings.py @@ -115,11 +115,11 @@ }, ] -REST_FRAMEWORK = { - "DEFAULT_AUTHENTICATION_CLASSES": [ - "rest_framework.authentication.TokenAuthentication", - ] -} +# REST_FRAMEWORK = { +# "DEFAULT_AUTHENTICATION_CLASSES": [ +# "rest_framework.authentication.TokenAuthentication", +# ] +# } CORS_ALLOWED_ORIGINS = config("CORS_ALLOWED_ORIGINS", default="").split(",") @@ -151,7 +151,7 @@ LANGUAGE_CODE = "en-us" -TIME_ZONE = "UTC" +TIME_ZONE = "Asia/Seoul" USE_I18N = True From 0d5bd01ed73d1b0792b1b4ef279469d3734f5121 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Tue, 6 Aug 2024 02:19:22 +0900 Subject: [PATCH 05/28] =?UTF-8?q?fix:=20=EC=84=B8=ED=8C=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=84=9C=EB=B2=84=20=EC=8B=9C=EA=B0=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20=EC=84=B8=EC=85=98=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20DRF=EC=97=90=EC=84=9C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=9C=A0=EC=A7=80=EB=A5=BC=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=9D=B8=EC=A6=9D=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mustgou/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mustgou/settings.py b/mustgou/settings.py index 8a599fd..ba164c0 100644 --- a/mustgou/settings.py +++ b/mustgou/settings.py @@ -115,6 +115,7 @@ }, ] +# DRF 로그인 유지를 위해 주석처리 # REST_FRAMEWORK = { # "DEFAULT_AUTHENTICATION_CLASSES": [ # "rest_framework.authentication.TokenAuthentication", From aee195dfccb405c614fdacdaf1eb32b107917139 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 06/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 6 ++++++ friends/urls.py | 2 ++ friends/views.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 13aee59..4c9c395 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,6 +132,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/urls.py b/friends/urls.py index b4822af..ff39b23 100644 --- a/friends/urls.py +++ b/friends/urls.py @@ -11,4 +11,6 @@ path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), path("friends/", views.friend_list, name="friend-list"), path("friend-recommend/", views.friend_recommend, name="friend-recommend"), + # 추가 기능을 테스트하기 위한 url으로 실제로는 /friend 안에서 모두 진행됨 + path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), ] diff --git a/friends/views.py b/friends/views.py index b7f6e66..121f247 100644 --- a/friends/views.py +++ b/friends/views.py @@ -216,4 +216,4 @@ def decline_request(self, request, friend_id): friend_request.state = "declined" friend_request.save() - return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) \ No newline at end of file + return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) From 56a9cfa5edf2e9b0080edac68b996f1c0093d777 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 07/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 124 ++++++++++++++++++++++++++++++++++++++++- friends/urls.py | 2 + 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 4c9c395..2569a85 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,10 +132,132 @@ def get_rating_average(self, obj): return obj.rating_average() +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ["id", "name", "profile_img", "reliability"] + + class FriendRequestSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="from_user.id") + name = serializers.CharField(source="from_user.name") + profile_img = serializers.URLField(source="from_user.profile_img.url") + reliability = serializers.IntegerField(source="from_user.reliability") + common_restaurant_count = serializers.SerializerMethodField() + + class Meta: + model = FriendRequest + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + ] + + def get_common_restaurant_count(self, obj): + try: + user = obj.from_user + # friend_user = self.context.get('request').user + friend_user = User.objects.get(id=21) + + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=friend_user).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + except User.DoesNotExist: + return 0 + + +class FriendRecommendSerializer(serializers.ModelSerializer): + common_restaurant_count = serializers.SerializerMethodField() + common_restaurants = serializers.SerializerMethodField() + + class Meta: + model = User + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + "common_restaurants", + ] + + def get_common_restaurant_count(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=obj).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + + def get_common_restaurants(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = UserRestaurantsList.objects.filter( + user=obj, restaurant_id__in=user_restaurants + ).values("restaurant__name", "restaurant__image_url")[:2] + return friend_restaurants + + def to_representation(self, instance): + representation = super().to_representation(instance) + include_restaurants = self.context.get("include_restaurants", False) + if not include_restaurants: + representation.pop("common_restaurants") + return representation + + +class FriendSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="friend.id") + name = serializers.CharField(source="friend.name") + profile_img = serializers.URLField(source="friend.profile_img.url") + reliability = serializers.IntegerField(source="friend.reliability") + class Meta: model = Friend - fields = "__all__" + fields = [ + "id", + "name", + "profile_img", + "reliability", + ] + + +class RestaurantlistSerializer(serializers.ModelSerializer): + rating_average = serializers.SerializerMethodField() + + class Meta: + model = Restaurant + fields = [ + "id", + "name", + "food_type", + "rating_average", + "latitude", + "longitude", + "image_url", + ] + + def get_rating_average(self, obj): + return obj.rating_average() class RestaurantSerializer(serializers.ModelSerializer): diff --git a/friends/urls.py b/friends/urls.py index ff39b23..34eb923 100644 --- a/friends/urls.py +++ b/friends/urls.py @@ -13,4 +13,6 @@ path("friend-recommend/", views.friend_recommend, name="friend-recommend"), # 추가 기능을 테스트하기 위한 url으로 실제로는 /friend 안에서 모두 진행됨 path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), + path("friends/", views.friend_list, name="friend-list"), + path("friend-recommend/", views.friend_recommend, name="friend-recommend"), ] From f2e470076800882a878e43344062b94085b50ae9 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Fri, 2 Aug 2024 01:10:12 +0900 Subject: [PATCH 08/28] =?UTF-8?q?fix:=20=EC=8A=88=ED=8D=BC=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20=EC=96=B4=EB=93=9C=EB=AF=BC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/accounts/admin.py b/accounts/admin.py index 0603e0c..cbb2053 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -15,3 +15,6 @@ class CustomUserAdmin(UserAdmin): ) admin.site.register(User, CustomUserAdmin) +from .models import User + +admin.site.register(User) From 3b9ca8387caa3d47706bc32678407edf422e1ed5 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Fri, 2 Aug 2024 16:05:54 +0900 Subject: [PATCH 09/28] =?UTF-8?q?feat:=20admin=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=20friends=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/friends/admin.py b/friends/admin.py index 7156a9b..6ab74c3 100644 --- a/friends/admin.py +++ b/friends/admin.py @@ -12,3 +12,6 @@ class FriendRequestAdmin(admin.ModelAdmin): admin.site.register(Friend, FriendAdmin) admin.site.register(FriendRequest, FriendRequestAdmin) +from .models import Friend + +admin.site.register(Friend) From a7fffa3d62af4c0bc2047816d6ed91ce5d74644a Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:07:02 +0900 Subject: [PATCH 10/28] =?UTF-8?q?chore:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/admin.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/accounts/admin.py b/accounts/admin.py index cbb2053..0603e0c 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -15,6 +15,3 @@ class CustomUserAdmin(UserAdmin): ) admin.site.register(User, CustomUserAdmin) -from .models import User - -admin.site.register(User) From 5a83b56b5f273c37e70b0d5d58dae2e3b0696d0f Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 11/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/admin.py | 3 --- friends/serializers.py | 6 ++++++ friends/urls.py | 4 ---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/friends/admin.py b/friends/admin.py index 6ab74c3..7156a9b 100644 --- a/friends/admin.py +++ b/friends/admin.py @@ -12,6 +12,3 @@ class FriendRequestAdmin(admin.ModelAdmin): admin.site.register(Friend, FriendAdmin) admin.site.register(FriendRequest, FriendRequestAdmin) -from .models import Friend - -admin.site.register(Friend) diff --git a/friends/serializers.py b/friends/serializers.py index 2569a85..10a5f81 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -260,6 +260,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/urls.py b/friends/urls.py index 34eb923..b4822af 100644 --- a/friends/urls.py +++ b/friends/urls.py @@ -11,8 +11,4 @@ path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), path("friends/", views.friend_list, name="friend-list"), path("friend-recommend/", views.friend_recommend, name="friend-recommend"), - # 추가 기능을 테스트하기 위한 url으로 실제로는 /friend 안에서 모두 진행됨 - path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), - path("friends/", views.friend_list, name="friend-list"), - path("friend-recommend/", views.friend_recommend, name="friend-recommend"), ] From 1ac9ded56af2df934d62765f15ab8cf199b523bc Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 12/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 134 ----------------------------------------- friends/views.py | 1 + 2 files changed, 1 insertion(+), 134 deletions(-) diff --git a/friends/serializers.py b/friends/serializers.py index 10a5f81..13aee59 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,140 +132,6 @@ def get_rating_average(self, obj): return obj.rating_average() -class UserSerializer(serializers.ModelSerializer): - class Meta: - model = User - fields = ["id", "name", "profile_img", "reliability"] - - -class FriendRequestSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="from_user.id") - name = serializers.CharField(source="from_user.name") - profile_img = serializers.URLField(source="from_user.profile_img.url") - reliability = serializers.IntegerField(source="from_user.reliability") - common_restaurant_count = serializers.SerializerMethodField() - - class Meta: - model = FriendRequest - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - ] - - def get_common_restaurant_count(self, obj): - try: - user = obj.from_user - # friend_user = self.context.get('request').user - friend_user = User.objects.get(id=21) - - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=friend_user).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - except User.DoesNotExist: - return 0 - - -class FriendRecommendSerializer(serializers.ModelSerializer): - common_restaurant_count = serializers.SerializerMethodField() - common_restaurants = serializers.SerializerMethodField() - - class Meta: - model = User - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - "common_restaurants", - ] - - def get_common_restaurant_count(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=obj).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - - def get_common_restaurants(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = UserRestaurantsList.objects.filter( - user=obj, restaurant_id__in=user_restaurants - ).values("restaurant__name", "restaurant__image_url")[:2] - return friend_restaurants - - def to_representation(self, instance): - representation = super().to_representation(instance) - include_restaurants = self.context.get("include_restaurants", False) - if not include_restaurants: - representation.pop("common_restaurants") - return representation - - -class FriendSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="friend.id") - name = serializers.CharField(source="friend.name") - profile_img = serializers.URLField(source="friend.profile_img.url") - reliability = serializers.IntegerField(source="friend.reliability") - - class Meta: - model = Friend - fields = [ - "id", - "name", - "profile_img", - "reliability", - ] - - -class RestaurantlistSerializer(serializers.ModelSerializer): - rating_average = serializers.SerializerMethodField() - - class Meta: - model = Restaurant - fields = [ - "id", - "name", - "food_type", - "rating_average", - "latitude", - "longitude", - "image_url", - ] - - def get_rating_average(self, obj): - return obj.rating_average() - - -class FriendRequestSerializer(serializers.ModelSerializer): - class Meta: - model = Friend - fields = "__all__" - - class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/views.py b/friends/views.py index 121f247..ff749bc 100644 --- a/friends/views.py +++ b/friends/views.py @@ -14,6 +14,7 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, + RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer From c949aeff52d230fc1d27bcdf32e76697ea288839 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 13/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/friends/serializers.py b/friends/serializers.py index 13aee59..4c9c395 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,6 +132,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() From a126bc2d7c31608a90e15c9b46c6f8bd1e04b84c Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 14/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 118 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 4c9c395..bb4caa9 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -133,9 +133,125 @@ def get_rating_average(self, obj): class FriendRequestSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="from_user.id") + name = serializers.CharField(source="from_user.name") + profile_img = serializers.URLField(source="from_user.profile_img.url") + reliability = serializers.IntegerField(source="from_user.reliability") + common_restaurant_count = serializers.SerializerMethodField() + + class Meta: + model = FriendRequest + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + ] + + def get_common_restaurant_count(self, obj): + try: + user = obj.from_user + # friend_user = self.context.get('request').user + friend_user = User.objects.get(id=21) + + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=friend_user).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + except User.DoesNotExist: + return 0 + + +class FriendRecommendSerializer(serializers.ModelSerializer): + common_restaurant_count = serializers.SerializerMethodField() + common_restaurants = serializers.SerializerMethodField() + + class Meta: + model = User + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + "common_restaurants", + ] + + def get_common_restaurant_count(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=obj).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + + def get_common_restaurants(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = UserRestaurantsList.objects.filter( + user=obj, restaurant_id__in=user_restaurants + ).values("restaurant__name", "restaurant__image_url")[:2] + return friend_restaurants + + def to_representation(self, instance): + representation = super().to_representation(instance) + include_restaurants = self.context.get("include_restaurants", False) + if not include_restaurants: + representation.pop("common_restaurants") + return representation + + +class FriendSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="friend.id") + name = serializers.CharField(source="friend.name") + profile_img = serializers.URLField(source="friend.profile_img.url") + reliability = serializers.IntegerField(source="friend.reliability") + class Meta: model = Friend - fields = "__all__" + fields = [ + "id", + "name", + "profile_img", + "reliability", + ] + + +class RestaurantlistSerializer(serializers.ModelSerializer): + rating_average = serializers.SerializerMethodField() + + class Meta: + model = Restaurant + fields = [ + "id", + "name", + "food_type", + "rating_average", + "latitude", + "longitude", + "image_url", + ] + + def get_rating_average(self, obj): + return obj.rating_average() class RestaurantSerializer(serializers.ModelSerializer): From 5f0b8a2c885608d5f63c728593185ea6faa1d76a Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 15/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 6 ++++++ friends/views.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index bb4caa9..e0d6254 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -254,6 +254,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/views.py b/friends/views.py index ff749bc..6117877 100644 --- a/friends/views.py +++ b/friends/views.py @@ -2,6 +2,10 @@ from rest_framework.decorators import api_view from rest_framework.views import APIView +# from rest_framework.authentication import TokenAuthentication +# from rest_framework.permissions import IsAuthenticated +from rest_framework.views import APIView + # from rest_framework.authentication import TokenAuthentication # from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -14,7 +18,7 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, - RestaurantSerializer, + # RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer From 8c3858010472b0e94ad58010a0f0e72f41f6fb88 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 16/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 128 ----------------------------------------- friends/views.py | 7 +-- 2 files changed, 1 insertion(+), 134 deletions(-) diff --git a/friends/serializers.py b/friends/serializers.py index e0d6254..13aee59 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,134 +132,6 @@ def get_rating_average(self, obj): return obj.rating_average() -class FriendRequestSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="from_user.id") - name = serializers.CharField(source="from_user.name") - profile_img = serializers.URLField(source="from_user.profile_img.url") - reliability = serializers.IntegerField(source="from_user.reliability") - common_restaurant_count = serializers.SerializerMethodField() - - class Meta: - model = FriendRequest - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - ] - - def get_common_restaurant_count(self, obj): - try: - user = obj.from_user - # friend_user = self.context.get('request').user - friend_user = User.objects.get(id=21) - - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=friend_user).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - except User.DoesNotExist: - return 0 - - -class FriendRecommendSerializer(serializers.ModelSerializer): - common_restaurant_count = serializers.SerializerMethodField() - common_restaurants = serializers.SerializerMethodField() - - class Meta: - model = User - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - "common_restaurants", - ] - - def get_common_restaurant_count(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=obj).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - - def get_common_restaurants(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = UserRestaurantsList.objects.filter( - user=obj, restaurant_id__in=user_restaurants - ).values("restaurant__name", "restaurant__image_url")[:2] - return friend_restaurants - - def to_representation(self, instance): - representation = super().to_representation(instance) - include_restaurants = self.context.get("include_restaurants", False) - if not include_restaurants: - representation.pop("common_restaurants") - return representation - - -class FriendSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="friend.id") - name = serializers.CharField(source="friend.name") - profile_img = serializers.URLField(source="friend.profile_img.url") - reliability = serializers.IntegerField(source="friend.reliability") - - class Meta: - model = Friend - fields = [ - "id", - "name", - "profile_img", - "reliability", - ] - - -class RestaurantlistSerializer(serializers.ModelSerializer): - rating_average = serializers.SerializerMethodField() - - class Meta: - model = Restaurant - fields = [ - "id", - "name", - "food_type", - "rating_average", - "latitude", - "longitude", - "image_url", - ] - - def get_rating_average(self, obj): - return obj.rating_average() - - -class FriendRequestSerializer(serializers.ModelSerializer): - class Meta: - model = Friend - fields = "__all__" - - class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/views.py b/friends/views.py index 6117877..b7f6e66 100644 --- a/friends/views.py +++ b/friends/views.py @@ -2,10 +2,6 @@ from rest_framework.decorators import api_view from rest_framework.views import APIView -# from rest_framework.authentication import TokenAuthentication -# from rest_framework.permissions import IsAuthenticated -from rest_framework.views import APIView - # from rest_framework.authentication import TokenAuthentication # from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -18,7 +14,6 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, - # RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer @@ -221,4 +216,4 @@ def decline_request(self, request, friend_id): friend_request.state = "declined" friend_request.save() - return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) + return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) \ No newline at end of file From 339e0b179f1d212e67629b3e11e2593138fc9719 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:07:02 +0900 Subject: [PATCH 17/28] =?UTF-8?q?chore:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/accounts/admin.py b/accounts/admin.py index 0603e0c..03e4a1a 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.admin import UserAdmin from .models import User From ee1d0b5ad51a51e3b5e54671253d1197df8a0358 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 18/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 6 ++++++ friends/urls.py | 2 ++ friends/views.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 13aee59..4c9c395 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,6 +132,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/urls.py b/friends/urls.py index b4822af..ff39b23 100644 --- a/friends/urls.py +++ b/friends/urls.py @@ -11,4 +11,6 @@ path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), path("friends/", views.friend_list, name="friend-list"), path("friend-recommend/", views.friend_recommend, name="friend-recommend"), + # 추가 기능을 테스트하기 위한 url으로 실제로는 /friend 안에서 모두 진행됨 + path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), ] diff --git a/friends/views.py b/friends/views.py index b7f6e66..121f247 100644 --- a/friends/views.py +++ b/friends/views.py @@ -216,4 +216,4 @@ def decline_request(self, request, friend_id): friend_request.state = "declined" friend_request.save() - return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) \ No newline at end of file + return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) From 8495a0d07f80632c4b30a7f418dc5f59778388cc Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 19/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 124 ++++++++++++++++++++++++++++++++++++++++- friends/urls.py | 2 + 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 4c9c395..2569a85 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,10 +132,132 @@ def get_rating_average(self, obj): return obj.rating_average() +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ["id", "name", "profile_img", "reliability"] + + class FriendRequestSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="from_user.id") + name = serializers.CharField(source="from_user.name") + profile_img = serializers.URLField(source="from_user.profile_img.url") + reliability = serializers.IntegerField(source="from_user.reliability") + common_restaurant_count = serializers.SerializerMethodField() + + class Meta: + model = FriendRequest + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + ] + + def get_common_restaurant_count(self, obj): + try: + user = obj.from_user + # friend_user = self.context.get('request').user + friend_user = User.objects.get(id=21) + + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=friend_user).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + except User.DoesNotExist: + return 0 + + +class FriendRecommendSerializer(serializers.ModelSerializer): + common_restaurant_count = serializers.SerializerMethodField() + common_restaurants = serializers.SerializerMethodField() + + class Meta: + model = User + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + "common_restaurants", + ] + + def get_common_restaurant_count(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=obj).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + + def get_common_restaurants(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = UserRestaurantsList.objects.filter( + user=obj, restaurant_id__in=user_restaurants + ).values("restaurant__name", "restaurant__image_url")[:2] + return friend_restaurants + + def to_representation(self, instance): + representation = super().to_representation(instance) + include_restaurants = self.context.get("include_restaurants", False) + if not include_restaurants: + representation.pop("common_restaurants") + return representation + + +class FriendSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="friend.id") + name = serializers.CharField(source="friend.name") + profile_img = serializers.URLField(source="friend.profile_img.url") + reliability = serializers.IntegerField(source="friend.reliability") + class Meta: model = Friend - fields = "__all__" + fields = [ + "id", + "name", + "profile_img", + "reliability", + ] + + +class RestaurantlistSerializer(serializers.ModelSerializer): + rating_average = serializers.SerializerMethodField() + + class Meta: + model = Restaurant + fields = [ + "id", + "name", + "food_type", + "rating_average", + "latitude", + "longitude", + "image_url", + ] + + def get_rating_average(self, obj): + return obj.rating_average() class RestaurantSerializer(serializers.ModelSerializer): diff --git a/friends/urls.py b/friends/urls.py index ff39b23..34eb923 100644 --- a/friends/urls.py +++ b/friends/urls.py @@ -13,4 +13,6 @@ path("friend-recommend/", views.friend_recommend, name="friend-recommend"), # 추가 기능을 테스트하기 위한 url으로 실제로는 /friend 안에서 모두 진행됨 path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), + path("friends/", views.friend_list, name="friend-list"), + path("friend-recommend/", views.friend_recommend, name="friend-recommend"), ] From 60dfd67f9ca560e91bb3284bcdeb663be46b70ab Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Fri, 2 Aug 2024 01:10:12 +0900 Subject: [PATCH 20/28] =?UTF-8?q?fix:=20=EC=8A=88=ED=8D=BC=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20=EC=96=B4=EB=93=9C=EB=AF=BC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/accounts/admin.py b/accounts/admin.py index 03e4a1a..215836a 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -16,3 +16,6 @@ class CustomUserAdmin(UserAdmin): ) admin.site.register(User, CustomUserAdmin) +from .models import User + +admin.site.register(User) From 1ecf00468e7c265f6ca7a0bc022d5f587536dcfb Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Fri, 2 Aug 2024 16:05:54 +0900 Subject: [PATCH 21/28] =?UTF-8?q?feat:=20admin=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=20friends=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/friends/admin.py b/friends/admin.py index 7156a9b..6ab74c3 100644 --- a/friends/admin.py +++ b/friends/admin.py @@ -12,3 +12,6 @@ class FriendRequestAdmin(admin.ModelAdmin): admin.site.register(Friend, FriendAdmin) admin.site.register(FriendRequest, FriendRequestAdmin) +from .models import Friend + +admin.site.register(Friend) From 0342c69b16e9d2fe838f13b1efd983a8c130c5a5 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:07:02 +0900 Subject: [PATCH 22/28] =?UTF-8?q?chore:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/admin.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/accounts/admin.py b/accounts/admin.py index 215836a..03e4a1a 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -16,6 +16,3 @@ class CustomUserAdmin(UserAdmin): ) admin.site.register(User, CustomUserAdmin) -from .models import User - -admin.site.register(User) From a51d529f4728f8c4456b856ee1cb7456f5480105 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 23/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/admin.py | 3 --- friends/serializers.py | 6 ++++++ friends/urls.py | 4 ---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/friends/admin.py b/friends/admin.py index 6ab74c3..7156a9b 100644 --- a/friends/admin.py +++ b/friends/admin.py @@ -12,6 +12,3 @@ class FriendRequestAdmin(admin.ModelAdmin): admin.site.register(Friend, FriendAdmin) admin.site.register(FriendRequest, FriendRequestAdmin) -from .models import Friend - -admin.site.register(Friend) diff --git a/friends/serializers.py b/friends/serializers.py index 2569a85..10a5f81 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -260,6 +260,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/urls.py b/friends/urls.py index 34eb923..b4822af 100644 --- a/friends/urls.py +++ b/friends/urls.py @@ -11,8 +11,4 @@ path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), path("friends/", views.friend_list, name="friend-list"), path("friend-recommend/", views.friend_recommend, name="friend-recommend"), - # 추가 기능을 테스트하기 위한 url으로 실제로는 /friend 안에서 모두 진행됨 - path("friend-request/", views.FriendRequestView.as_view(), name="friend-request"), - path("friends/", views.friend_list, name="friend-list"), - path("friend-recommend/", views.friend_recommend, name="friend-recommend"), ] From 541dd7c42aa839d9c2e8bed8695372abca57ed18 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 24/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 134 ----------------------------------------- friends/views.py | 1 + 2 files changed, 1 insertion(+), 134 deletions(-) diff --git a/friends/serializers.py b/friends/serializers.py index 10a5f81..13aee59 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,140 +132,6 @@ def get_rating_average(self, obj): return obj.rating_average() -class UserSerializer(serializers.ModelSerializer): - class Meta: - model = User - fields = ["id", "name", "profile_img", "reliability"] - - -class FriendRequestSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="from_user.id") - name = serializers.CharField(source="from_user.name") - profile_img = serializers.URLField(source="from_user.profile_img.url") - reliability = serializers.IntegerField(source="from_user.reliability") - common_restaurant_count = serializers.SerializerMethodField() - - class Meta: - model = FriendRequest - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - ] - - def get_common_restaurant_count(self, obj): - try: - user = obj.from_user - # friend_user = self.context.get('request').user - friend_user = User.objects.get(id=21) - - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=friend_user).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - except User.DoesNotExist: - return 0 - - -class FriendRecommendSerializer(serializers.ModelSerializer): - common_restaurant_count = serializers.SerializerMethodField() - common_restaurants = serializers.SerializerMethodField() - - class Meta: - model = User - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - "common_restaurants", - ] - - def get_common_restaurant_count(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=obj).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - - def get_common_restaurants(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = UserRestaurantsList.objects.filter( - user=obj, restaurant_id__in=user_restaurants - ).values("restaurant__name", "restaurant__image_url")[:2] - return friend_restaurants - - def to_representation(self, instance): - representation = super().to_representation(instance) - include_restaurants = self.context.get("include_restaurants", False) - if not include_restaurants: - representation.pop("common_restaurants") - return representation - - -class FriendSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="friend.id") - name = serializers.CharField(source="friend.name") - profile_img = serializers.URLField(source="friend.profile_img.url") - reliability = serializers.IntegerField(source="friend.reliability") - - class Meta: - model = Friend - fields = [ - "id", - "name", - "profile_img", - "reliability", - ] - - -class RestaurantlistSerializer(serializers.ModelSerializer): - rating_average = serializers.SerializerMethodField() - - class Meta: - model = Restaurant - fields = [ - "id", - "name", - "food_type", - "rating_average", - "latitude", - "longitude", - "image_url", - ] - - def get_rating_average(self, obj): - return obj.rating_average() - - -class FriendRequestSerializer(serializers.ModelSerializer): - class Meta: - model = Friend - fields = "__all__" - - class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/views.py b/friends/views.py index 121f247..ff749bc 100644 --- a/friends/views.py +++ b/friends/views.py @@ -14,6 +14,7 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, + RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer From 256e66a301ad081b8a2610fd45ab6a3b884ec6a3 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 25/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/friends/serializers.py b/friends/serializers.py index 13aee59..4c9c395 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,6 +132,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() From 347c20e7476323896791b13d30bd32a2a9ed307a Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 26/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 118 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index 4c9c395..bb4caa9 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -133,9 +133,125 @@ def get_rating_average(self, obj): class FriendRequestSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="from_user.id") + name = serializers.CharField(source="from_user.name") + profile_img = serializers.URLField(source="from_user.profile_img.url") + reliability = serializers.IntegerField(source="from_user.reliability") + common_restaurant_count = serializers.SerializerMethodField() + + class Meta: + model = FriendRequest + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + ] + + def get_common_restaurant_count(self, obj): + try: + user = obj.from_user + # friend_user = self.context.get('request').user + friend_user = User.objects.get(id=21) + + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=friend_user).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + except User.DoesNotExist: + return 0 + + +class FriendRecommendSerializer(serializers.ModelSerializer): + common_restaurant_count = serializers.SerializerMethodField() + common_restaurants = serializers.SerializerMethodField() + + class Meta: + model = User + fields = [ + "id", + "name", + "profile_img", + "reliability", + "common_restaurant_count", + "common_restaurants", + ] + + def get_common_restaurant_count(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = set( + UserRestaurantsList.objects.filter(user=obj).values_list( + "restaurant_id", flat=True + ) + ) + return len(user_restaurants.intersection(friend_restaurants)) + + def get_common_restaurants(self, obj): + user = self.context.get("user") + user_restaurants = set( + UserRestaurantsList.objects.filter(user=user).values_list( + "restaurant_id", flat=True + ) + ) + friend_restaurants = UserRestaurantsList.objects.filter( + user=obj, restaurant_id__in=user_restaurants + ).values("restaurant__name", "restaurant__image_url")[:2] + return friend_restaurants + + def to_representation(self, instance): + representation = super().to_representation(instance) + include_restaurants = self.context.get("include_restaurants", False) + if not include_restaurants: + representation.pop("common_restaurants") + return representation + + +class FriendSerializer(serializers.ModelSerializer): + id = serializers.IntegerField(source="friend.id") + name = serializers.CharField(source="friend.name") + profile_img = serializers.URLField(source="friend.profile_img.url") + reliability = serializers.IntegerField(source="friend.reliability") + class Meta: model = Friend - fields = "__all__" + fields = [ + "id", + "name", + "profile_img", + "reliability", + ] + + +class RestaurantlistSerializer(serializers.ModelSerializer): + rating_average = serializers.SerializerMethodField() + + class Meta: + model = Restaurant + fields = [ + "id", + "name", + "food_type", + "rating_average", + "latitude", + "longitude", + "image_url", + ] + + def get_rating_average(self, obj): + return obj.rating_average() class RestaurantSerializer(serializers.ModelSerializer): From dad6544cdd4b61f572e426ea8d83af5980cb0a55 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:12:29 +0900 Subject: [PATCH 27/28] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=88=98=EB=9D=BD/=EA=B1=B0=EC=A0=88=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 6 ++++++ friends/views.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/friends/serializers.py b/friends/serializers.py index bb4caa9..e0d6254 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -254,6 +254,12 @@ def get_rating_average(self, obj): return obj.rating_average() +class FriendRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Friend + fields = "__all__" + + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/views.py b/friends/views.py index ff749bc..6117877 100644 --- a/friends/views.py +++ b/friends/views.py @@ -2,6 +2,10 @@ from rest_framework.decorators import api_view from rest_framework.views import APIView +# from rest_framework.authentication import TokenAuthentication +# from rest_framework.permissions import IsAuthenticated +from rest_framework.views import APIView + # from rest_framework.authentication import TokenAuthentication # from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -14,7 +18,7 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, - RestaurantSerializer, + # RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer From 59caa0fd8c4cb9ba28619c303bf3c8ab2e20c594 Mon Sep 17 00:00:00 2001 From: ybkang1108 Date: Mon, 5 Aug 2024 02:25:15 +0900 Subject: [PATCH 28/28] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 128 ----------------------------------------- friends/views.py | 7 +-- 2 files changed, 1 insertion(+), 134 deletions(-) diff --git a/friends/serializers.py b/friends/serializers.py index e0d6254..13aee59 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -132,134 +132,6 @@ def get_rating_average(self, obj): return obj.rating_average() -class FriendRequestSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="from_user.id") - name = serializers.CharField(source="from_user.name") - profile_img = serializers.URLField(source="from_user.profile_img.url") - reliability = serializers.IntegerField(source="from_user.reliability") - common_restaurant_count = serializers.SerializerMethodField() - - class Meta: - model = FriendRequest - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - ] - - def get_common_restaurant_count(self, obj): - try: - user = obj.from_user - # friend_user = self.context.get('request').user - friend_user = User.objects.get(id=21) - - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=friend_user).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - except User.DoesNotExist: - return 0 - - -class FriendRecommendSerializer(serializers.ModelSerializer): - common_restaurant_count = serializers.SerializerMethodField() - common_restaurants = serializers.SerializerMethodField() - - class Meta: - model = User - fields = [ - "id", - "name", - "profile_img", - "reliability", - "common_restaurant_count", - "common_restaurants", - ] - - def get_common_restaurant_count(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = set( - UserRestaurantsList.objects.filter(user=obj).values_list( - "restaurant_id", flat=True - ) - ) - return len(user_restaurants.intersection(friend_restaurants)) - - def get_common_restaurants(self, obj): - user = self.context.get("user") - user_restaurants = set( - UserRestaurantsList.objects.filter(user=user).values_list( - "restaurant_id", flat=True - ) - ) - friend_restaurants = UserRestaurantsList.objects.filter( - user=obj, restaurant_id__in=user_restaurants - ).values("restaurant__name", "restaurant__image_url")[:2] - return friend_restaurants - - def to_representation(self, instance): - representation = super().to_representation(instance) - include_restaurants = self.context.get("include_restaurants", False) - if not include_restaurants: - representation.pop("common_restaurants") - return representation - - -class FriendSerializer(serializers.ModelSerializer): - id = serializers.IntegerField(source="friend.id") - name = serializers.CharField(source="friend.name") - profile_img = serializers.URLField(source="friend.profile_img.url") - reliability = serializers.IntegerField(source="friend.reliability") - - class Meta: - model = Friend - fields = [ - "id", - "name", - "profile_img", - "reliability", - ] - - -class RestaurantlistSerializer(serializers.ModelSerializer): - rating_average = serializers.SerializerMethodField() - - class Meta: - model = Restaurant - fields = [ - "id", - "name", - "food_type", - "rating_average", - "latitude", - "longitude", - "image_url", - ] - - def get_rating_average(self, obj): - return obj.rating_average() - - -class FriendRequestSerializer(serializers.ModelSerializer): - class Meta: - model = Friend - fields = "__all__" - - class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/friends/views.py b/friends/views.py index 6117877..b7f6e66 100644 --- a/friends/views.py +++ b/friends/views.py @@ -2,10 +2,6 @@ from rest_framework.decorators import api_view from rest_framework.views import APIView -# from rest_framework.authentication import TokenAuthentication -# from rest_framework.permissions import IsAuthenticated -from rest_framework.views import APIView - # from rest_framework.authentication import TokenAuthentication # from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -18,7 +14,6 @@ FriendRequestSerializer, RestaurantlistSerializer, FriendRecommendSerializer, - # RestaurantSerializer, ) # from .serializers import FriendSerializer, FriendRequestSerializer @@ -221,4 +216,4 @@ def decline_request(self, request, friend_id): friend_request.state = "declined" friend_request.save() - return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) + return Response({"message": "친구 신청을 거절했습니다."}, status=status.HTTP_200_OK) \ No newline at end of file