From a83f1bf2e78c911b6457170c6086a16969c5c826 Mon Sep 17 00:00:00 2001 From: dkfla Date: Wed, 31 Jul 2024 02:49:46 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restaurants/migrations/0003_searchhistory.py | 41 ++++++++++++++++++ restaurants/models.py | 17 ++++++++ restaurants/serializers.py | 19 ++++++++- restaurants/urls.py | 1 + restaurants/views.py | 45 ++++++++++++++++---- 5 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 restaurants/migrations/0003_searchhistory.py diff --git a/restaurants/migrations/0003_searchhistory.py b/restaurants/migrations/0003_searchhistory.py new file mode 100644 index 0000000..1040573 --- /dev/null +++ b/restaurants/migrations/0003_searchhistory.py @@ -0,0 +1,41 @@ +# Generated by Django 4.2.14 on 2024-07-30 17:48 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("restaurants", "0002_alter_restaurant_latitude_alter_restaurant_longitude"), + ] + + operations = [ + migrations.CreateModel( + name="SearchHistory", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("query", models.CharField(max_length=255)), + ("timestamp", models.DateTimeField(auto_now_add=True)), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "ordering": ["-timestamp"], + }, + ), + ] diff --git a/restaurants/models.py b/restaurants/models.py index 8524d60..0dc9d4e 100644 --- a/restaurants/models.py +++ b/restaurants/models.py @@ -1,4 +1,5 @@ from django.db import models +from accounts.models import User # Create your models here. @@ -17,3 +18,19 @@ 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) + + def rating_average(self): + ratings = [self.rating_naver, self.rating_kakao, self.rating_google] + valid_ratings = [rating for rating in ratings if rating is not None] + if valid_ratings: + return sum(valid_ratings) / len(valid_ratings) + return None + + +class SearchHistory(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + query = models.CharField(max_length=255) + timestamp = models.DateTimeField(auto_now_add=True) + + class Meta: + ordering = ["-timestamp"] diff --git a/restaurants/serializers.py b/restaurants/serializers.py index ea58b97..452e64a 100644 --- a/restaurants/serializers.py +++ b/restaurants/serializers.py @@ -1,8 +1,25 @@ from rest_framework import serializers -from .models import Restaurant +from .models import Restaurant, SearchHistory class RestaurantSerializer(serializers.ModelSerializer): class Meta: model = Restaurant fields = "__all__" + + +class RestaurantListSerializer(serializers.ModelSerializer): + rating_average = serializers.SerializerMethodField() + + class Meta: + model = Restaurant + fields = ["name", "rating_average", "address"] + + def get_rating_average(self, obj): + return obj.rating_average + + +class SearchHistorySerializer(serializers.ModelSerializer): + class Meta: + model = SearchHistory + fields = ["query", "timestamp"] diff --git a/restaurants/urls.py b/restaurants/urls.py index a6ffb5d..9bf61e7 100644 --- a/restaurants/urls.py +++ b/restaurants/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ path("restaurants/", views.restaurant_list, name="restaurant-list"), path("api-auth/", include("rest_framework.urls", namespace="rest_framework")), + path("search/", views.search, name="search"), ] diff --git a/restaurants/views.py b/restaurants/views.py index 15a01a6..9ec565e 100644 --- a/restaurants/views.py +++ b/restaurants/views.py @@ -1,13 +1,42 @@ # from django.shortcuts import render -from django.http import JsonResponse -from django.views.decorators.csrf import csrf_exempt -from .models import Restaurant -from .serializers import RestaurantSerializer +from rest_framework.decorators import api_view +from rest_framework.response import Response +from .models import Restaurant, SearchHistory +from .serializers import ( + RestaurantSerializer, + RestaurantListSerializer, + SearchHistorySerializer, +) -@csrf_exempt +@api_view(["GET"]) def restaurant_list(request): + restaurants = Restaurant.objects.all() + serializer = RestaurantSerializer(restaurants, many=True) + return Response(serializer.data) + + +@api_view(["GET", "POST"]) +def search(request): if request.method == "GET": - restaurants = Restaurant.objects.all() - serializer = RestaurantSerializer(restaurants, many=True) - return JsonResponse(serializer.data, safe=False) + if request.user.is_authenticated: + histories = SearchHistory.objects.filter(user=request.user) + serializer = SearchHistorySerializer(histories, many=True) + return Response({"histories": serializer.data}) + else: + return Response({"error": "User not authenticated"}, status=401) + + elif request.method == "POST": + query = request.data.get("query", "") + if not query: + return Response({"error": "No search query provided"}, status=400) + + if request.user.is_authenticated: + SearchHistory.objects.create(user=request.user, query=query) + + restaurants = Restaurant.objects.filter(name__icontains=query) + serializer = RestaurantListSerializer(restaurants, many=True) + return Response({"results": serializer.data}) + + else: + return Response({"error": "Unsupported method"}, status=405) From d4acf2bd4494e8b5501813157a66be63eda81f8e Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Wed, 31 Jul 2024 12:47:15 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=EB=82=B4=20=EB=A7=9B=EC=A7=91=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EA=B8=B0=EB=8A=A5=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 --- .../migrations/0004_userrestaurantlist.py | 46 +++++++++++++++++++ restaurants/models.py | 8 ++++ restaurants/serializers.py | 10 +++- restaurants/urls.py | 8 +++- restaurants/views.py | 44 +++++++++++++++++- 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 restaurants/migrations/0004_userrestaurantlist.py diff --git a/restaurants/migrations/0004_userrestaurantlist.py b/restaurants/migrations/0004_userrestaurantlist.py new file mode 100644 index 0000000..deac1ce --- /dev/null +++ b/restaurants/migrations/0004_userrestaurantlist.py @@ -0,0 +1,46 @@ +# Generated by Django 4.2.14 on 2024-07-31 03:43 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("restaurants", "0003_searchhistory"), + ] + + operations = [ + migrations.CreateModel( + name="UserRestaurantList", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "restaurant", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="restaurants.restaurant", + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "unique_together": {("user", "restaurant")}, + }, + ), + ] diff --git a/restaurants/models.py b/restaurants/models.py index 0dc9d4e..1d9700d 100644 --- a/restaurants/models.py +++ b/restaurants/models.py @@ -34,3 +34,11 @@ class SearchHistory(models.Model): class Meta: ordering = ["-timestamp"] + + +class UserRestaurantList(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE) + + class Meta: + unique_together = ("user", "restaurant") diff --git a/restaurants/serializers.py b/restaurants/serializers.py index 452e64a..f0ce4bc 100644 --- a/restaurants/serializers.py +++ b/restaurants/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from .models import Restaurant, SearchHistory +from .models import Restaurant, SearchHistory, UserRestaurantList class RestaurantSerializer(serializers.ModelSerializer): @@ -23,3 +23,11 @@ class SearchHistorySerializer(serializers.ModelSerializer): class Meta: model = SearchHistory fields = ["query", "timestamp"] + + +class UserRestaurantListSerializer(serializers.ModelSerializer): + restaurant = RestaurantSerializer() + + class Meta: + model = UserRestaurantList + fields = "__all__" diff --git a/restaurants/urls.py b/restaurants/urls.py index 9bf61e7..d91f411 100644 --- a/restaurants/urls.py +++ b/restaurants/urls.py @@ -3,7 +3,13 @@ urlpatterns = [ - path("restaurants/", views.restaurant_list, name="restaurant-list"), + # path("restaurants/", views.restaurant_list, name="restaurant-list"), path("api-auth/", include("rest_framework.urls", namespace="rest_framework")), path("search/", views.search, name="search"), + path( + "restaurants//", + views.add_remove_restaurant, + name="add-remove-restaurant", + ), + path("restaurants/", views.user_restaurant_list, name="user-restaurant-list"), ] diff --git a/restaurants/views.py b/restaurants/views.py index 9ec565e..2bf8b90 100644 --- a/restaurants/views.py +++ b/restaurants/views.py @@ -1,12 +1,15 @@ # from django.shortcuts import render from rest_framework.decorators import api_view from rest_framework.response import Response -from .models import Restaurant, SearchHistory +from rest_framework import status +from .models import Restaurant, SearchHistory, UserRestaurantList from .serializers import ( RestaurantSerializer, RestaurantListSerializer, SearchHistorySerializer, + UserRestaurantListSerializer, ) +from django.contrib.auth.decorators import login_required @api_view(["GET"]) @@ -40,3 +43,42 @@ def search(request): else: return Response({"error": "Unsupported method"}, status=405) + + +@api_view(["GET"]) +@login_required +def user_restaurant_list(request): + user_restaurants = UserRestaurantList.objects.filter(user=request.user) + serializer = UserRestaurantListSerializer(user_restaurants, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + + +@api_view(["POST", "DELETE"]) +@login_required +def add_remove_restaurant(request, pk): + try: + restaurant = Restaurant.objects.get(pk=pk) + if request.method == "POST": + UserRestaurantList.objects.create(user=request.user, restaurant=restaurant) + return Response( + {"message": "Restaurant added successfully"}, + status=status.HTTP_201_CREATED, + ) + elif request.method == "DELETE": + user_restaurant = UserRestaurantList.objects.get( + user=request.user, restaurant=restaurant + ) + user_restaurant.delete() + return Response( + {"message": "Restaurant deleted successfully"}, + status=status.HTTP_204_NO_CONTENT, + ) + except Restaurant.DoesNotExist: + return Response( + {"message": "Restaurant not found"}, status=status.HTTP_404_NOT_FOUND + ) + except UserRestaurantList.DoesNotExist: + return Response( + {"message": "Restaurant not found in your list"}, + status=status.HTTP_404_NOT_FOUND, + ) From ab0899d871c3bbdc22b61b63cb693b329682969c Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Wed, 31 Jul 2024 12:48:20 +0900 Subject: [PATCH 3/9] =?UTF-8?q?chore:=20users=20=EC=95=B1=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/__init__.py | 0 users/admin.py | 3 --- users/apps.py | 6 ------ users/migrations/0001_initial.py | 31 ------------------------------- users/migrations/__init__.py | 0 users/models.py | 11 ----------- users/serializers.py | 8 -------- users/tests.py | 3 --- users/views.py | 3 --- 9 files changed, 65 deletions(-) delete mode 100644 users/__init__.py delete mode 100644 users/admin.py delete mode 100644 users/apps.py delete mode 100644 users/migrations/0001_initial.py delete mode 100644 users/migrations/__init__.py delete mode 100644 users/models.py delete mode 100644 users/serializers.py delete mode 100644 users/tests.py delete mode 100644 users/views.py diff --git a/users/__init__.py b/users/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/users/admin.py b/users/admin.py deleted file mode 100644 index 4185d36..0000000 --- a/users/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.contrib import admin - -# Register your models here. diff --git a/users/apps.py b/users/apps.py deleted file mode 100644 index 88f7b17..0000000 --- a/users/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class UsersConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" - name = "users" diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py deleted file mode 100644 index b5b9347..0000000 --- a/users/migrations/0001_initial.py +++ /dev/null @@ -1,31 +0,0 @@ -# Generated by Django 4.2.14 on 2024-07-26 14:19 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [] - - operations = [ - migrations.CreateModel( - name="User", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("email", models.CharField(max_length=255)), - ("password", models.CharField(max_length=255)), - ("nickname", models.CharField(blank=True, max_length=255, null=True)), - ("image", models.CharField(blank=True, max_length=255, null=True)), - ("reliability", models.SmallIntegerField(blank=True, null=True)), - ], - ), - ] diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/users/models.py b/users/models.py deleted file mode 100644 index b061854..0000000 --- a/users/models.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.db import models - -# Create your models here. - - -class User(models.Model): - email = models.CharField(max_length=255) - password = models.CharField(max_length=255) - nickname = models.CharField(max_length=255, null=True, blank=True) - image = models.CharField(max_length=255, null=True, blank=True) - reliability = models.SmallIntegerField(null=True, blank=True) diff --git a/users/serializers.py b/users/serializers.py deleted file mode 100644 index 0ec035c..0000000 --- a/users/serializers.py +++ /dev/null @@ -1,8 +0,0 @@ -from rest_framework import serializers -from .models import User - - -class UserSerializer(serializers.ModelSerializer): - class Meta: - model = User - fields = "__all__" diff --git a/users/tests.py b/users/tests.py deleted file mode 100644 index a79ca8b..0000000 --- a/users/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/users/views.py b/users/views.py deleted file mode 100644 index fd0e044..0000000 --- a/users/views.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.shortcuts import render - -# Create your views here. From a4d4f92b7479c2a4804ddd8f2feb0616a331652e Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Wed, 31 Jul 2024 13:04:27 +0900 Subject: [PATCH 4/9] =?UTF-8?q?chore:=20Revert=20"chore:=20users=20?= =?UTF-8?q?=EC=95=B1=20=EC=82=AD=EC=A0=9C"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 37af76bed365f128e38155b9c19f46adbbd9a246. --- users/__init__.py | 0 users/admin.py | 3 +++ users/apps.py | 6 ++++++ users/migrations/0001_initial.py | 31 +++++++++++++++++++++++++++++++ users/migrations/__init__.py | 0 users/models.py | 11 +++++++++++ users/serializers.py | 8 ++++++++ users/tests.py | 3 +++ users/views.py | 3 +++ 9 files changed, 65 insertions(+) create mode 100644 users/__init__.py create mode 100644 users/admin.py create mode 100644 users/apps.py create mode 100644 users/migrations/0001_initial.py create mode 100644 users/migrations/__init__.py create mode 100644 users/models.py create mode 100644 users/serializers.py create mode 100644 users/tests.py create mode 100644 users/views.py diff --git a/users/__init__.py b/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/users/admin.py b/users/admin.py new file mode 100644 index 0000000..4185d36 --- /dev/null +++ b/users/admin.py @@ -0,0 +1,3 @@ +# from django.contrib import admin + +# Register your models here. diff --git a/users/apps.py b/users/apps.py new file mode 100644 index 0000000..88f7b17 --- /dev/null +++ b/users/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "users" diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py new file mode 100644 index 0000000..b5b9347 --- /dev/null +++ b/users/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.14 on 2024-07-26 14:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="User", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("email", models.CharField(max_length=255)), + ("password", models.CharField(max_length=255)), + ("nickname", models.CharField(blank=True, max_length=255, null=True)), + ("image", models.CharField(blank=True, max_length=255, null=True)), + ("reliability", models.SmallIntegerField(blank=True, null=True)), + ], + ), + ] diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/users/models.py b/users/models.py new file mode 100644 index 0000000..b061854 --- /dev/null +++ b/users/models.py @@ -0,0 +1,11 @@ +from django.db import models + +# Create your models here. + + +class User(models.Model): + email = models.CharField(max_length=255) + password = models.CharField(max_length=255) + nickname = models.CharField(max_length=255, null=True, blank=True) + image = models.CharField(max_length=255, null=True, blank=True) + reliability = models.SmallIntegerField(null=True, blank=True) diff --git a/users/serializers.py b/users/serializers.py new file mode 100644 index 0000000..0ec035c --- /dev/null +++ b/users/serializers.py @@ -0,0 +1,8 @@ +from rest_framework import serializers +from .models import User + + +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = "__all__" diff --git a/users/tests.py b/users/tests.py new file mode 100644 index 0000000..a79ca8b --- /dev/null +++ b/users/tests.py @@ -0,0 +1,3 @@ +# from django.test import TestCase + +# Create your tests here. diff --git a/users/views.py b/users/views.py new file mode 100644 index 0000000..fd0e044 --- /dev/null +++ b/users/views.py @@ -0,0 +1,3 @@ +# from django.shortcuts import render + +# Create your views here. From e071a5ec64db44bab7640286c37113a4bf46afc1 Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Wed, 31 Jul 2024 13:36:02 +0900 Subject: [PATCH 5/9] =?UTF-8?q?chore:=20users=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EA=B2=BD=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2_alter_friend_friend_alter_friend_user.py | 33 +++++++++++++++++++ friends/models.py | 2 +- ...antlist.py => 0004_userrestaurantslist.py} | 4 +-- restaurants/models.py | 2 +- restaurants/serializers.py | 4 +-- restaurants/views.py | 10 +++--- ..._alter_recommend_user_alter_review_user.py | 29 ++++++++++++++++ reviews/models.py | 2 +- 8 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 friends/migrations/0002_alter_friend_friend_alter_friend_user.py rename restaurants/migrations/{0004_userrestaurantlist.py => 0004_userrestaurantslist.py} (93%) create mode 100644 reviews/migrations/0002_alter_recommend_user_alter_review_user.py diff --git a/friends/migrations/0002_alter_friend_friend_alter_friend_user.py b/friends/migrations/0002_alter_friend_friend_alter_friend_user.py new file mode 100644 index 0000000..dea5a20 --- /dev/null +++ b/friends/migrations/0002_alter_friend_friend_alter_friend_user.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.14 on 2024-07-31 04:15 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("friends", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="friend", + name="friend", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="friend_of", + to=settings.AUTH_USER_MODEL, + ), + ), + migrations.AlterField( + model_name="friend", + name="user", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="friends", + to=settings.AUTH_USER_MODEL, + ), + ), + ] diff --git a/friends/models.py b/friends/models.py index 504a075..3a473bc 100644 --- a/friends/models.py +++ b/friends/models.py @@ -1,5 +1,5 @@ from django.db import models -from users.models import User +from accounts.models import User # Create your models here. diff --git a/restaurants/migrations/0004_userrestaurantlist.py b/restaurants/migrations/0004_userrestaurantslist.py similarity index 93% rename from restaurants/migrations/0004_userrestaurantlist.py rename to restaurants/migrations/0004_userrestaurantslist.py index deac1ce..d74b814 100644 --- a/restaurants/migrations/0004_userrestaurantlist.py +++ b/restaurants/migrations/0004_userrestaurantslist.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.14 on 2024-07-31 03:43 +# Generated by Django 4.2.14 on 2024-07-31 04:31 from django.conf import settings from django.db import migrations, models @@ -13,7 +13,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="UserRestaurantList", + name="UserRestaurantsList", fields=[ ( "id", diff --git a/restaurants/models.py b/restaurants/models.py index 1d9700d..41bed37 100644 --- a/restaurants/models.py +++ b/restaurants/models.py @@ -36,7 +36,7 @@ class Meta: ordering = ["-timestamp"] -class UserRestaurantList(models.Model): +class UserRestaurantsList(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE) diff --git a/restaurants/serializers.py b/restaurants/serializers.py index f0ce4bc..05b35a9 100644 --- a/restaurants/serializers.py +++ b/restaurants/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from .models import Restaurant, SearchHistory, UserRestaurantList +from .models import Restaurant, SearchHistory, UserRestaurantsList class RestaurantSerializer(serializers.ModelSerializer): @@ -29,5 +29,5 @@ class UserRestaurantListSerializer(serializers.ModelSerializer): restaurant = RestaurantSerializer() class Meta: - model = UserRestaurantList + model = UserRestaurantsList fields = "__all__" diff --git a/restaurants/views.py b/restaurants/views.py index 2bf8b90..37c8509 100644 --- a/restaurants/views.py +++ b/restaurants/views.py @@ -2,7 +2,7 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status -from .models import Restaurant, SearchHistory, UserRestaurantList +from .models import Restaurant, SearchHistory, UserRestaurantsList from .serializers import ( RestaurantSerializer, RestaurantListSerializer, @@ -48,7 +48,7 @@ def search(request): @api_view(["GET"]) @login_required def user_restaurant_list(request): - user_restaurants = UserRestaurantList.objects.filter(user=request.user) + user_restaurants = UserRestaurantsList.objects.filter(user=request.user) serializer = UserRestaurantListSerializer(user_restaurants, many=True) return Response(serializer.data, status=status.HTTP_200_OK) @@ -59,13 +59,13 @@ def add_remove_restaurant(request, pk): try: restaurant = Restaurant.objects.get(pk=pk) if request.method == "POST": - UserRestaurantList.objects.create(user=request.user, restaurant=restaurant) + UserRestaurantsList.objects.create(user=request.user, restaurant=restaurant) return Response( {"message": "Restaurant added successfully"}, status=status.HTTP_201_CREATED, ) elif request.method == "DELETE": - user_restaurant = UserRestaurantList.objects.get( + user_restaurant = UserRestaurantsList.objects.get( user=request.user, restaurant=restaurant ) user_restaurant.delete() @@ -77,7 +77,7 @@ def add_remove_restaurant(request, pk): return Response( {"message": "Restaurant not found"}, status=status.HTTP_404_NOT_FOUND ) - except UserRestaurantList.DoesNotExist: + except UserRestaurantsList.DoesNotExist: return Response( {"message": "Restaurant not found in your list"}, status=status.HTTP_404_NOT_FOUND, diff --git a/reviews/migrations/0002_alter_recommend_user_alter_review_user.py b/reviews/migrations/0002_alter_recommend_user_alter_review_user.py new file mode 100644 index 0000000..0c09793 --- /dev/null +++ b/reviews/migrations/0002_alter_recommend_user_alter_review_user.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.14 on 2024-07-31 04:15 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("reviews", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="recommend", + name="user", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + migrations.AlterField( + model_name="review", + name="user", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + ] diff --git a/reviews/models.py b/reviews/models.py index 1ffa83d..aa5f532 100644 --- a/reviews/models.py +++ b/reviews/models.py @@ -1,5 +1,5 @@ from django.db import models -from users.models import User +from accounts.models import User from restaurants.models import Restaurant # Create your models here. From 1dd60e614a45d4c2fcb045b179147e850f7e01aa Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Wed, 31 Jul 2024 15:16:53 +0900 Subject: [PATCH 6/9] =?UTF-8?q?chore:=20users=20=EC=95=B1=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/__init__.py | 0 users/admin.py | 3 --- users/apps.py | 6 ------ users/migrations/0001_initial.py | 31 ------------------------------- users/migrations/__init__.py | 0 users/models.py | 11 ----------- users/serializers.py | 8 -------- users/tests.py | 3 --- users/views.py | 3 --- 9 files changed, 65 deletions(-) delete mode 100644 users/__init__.py delete mode 100644 users/admin.py delete mode 100644 users/apps.py delete mode 100644 users/migrations/0001_initial.py delete mode 100644 users/migrations/__init__.py delete mode 100644 users/models.py delete mode 100644 users/serializers.py delete mode 100644 users/tests.py delete mode 100644 users/views.py diff --git a/users/__init__.py b/users/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/users/admin.py b/users/admin.py deleted file mode 100644 index 4185d36..0000000 --- a/users/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.contrib import admin - -# Register your models here. diff --git a/users/apps.py b/users/apps.py deleted file mode 100644 index 88f7b17..0000000 --- a/users/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class UsersConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" - name = "users" diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py deleted file mode 100644 index b5b9347..0000000 --- a/users/migrations/0001_initial.py +++ /dev/null @@ -1,31 +0,0 @@ -# Generated by Django 4.2.14 on 2024-07-26 14:19 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [] - - operations = [ - migrations.CreateModel( - name="User", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("email", models.CharField(max_length=255)), - ("password", models.CharField(max_length=255)), - ("nickname", models.CharField(blank=True, max_length=255, null=True)), - ("image", models.CharField(blank=True, max_length=255, null=True)), - ("reliability", models.SmallIntegerField(blank=True, null=True)), - ], - ), - ] diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/users/models.py b/users/models.py deleted file mode 100644 index b061854..0000000 --- a/users/models.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.db import models - -# Create your models here. - - -class User(models.Model): - email = models.CharField(max_length=255) - password = models.CharField(max_length=255) - nickname = models.CharField(max_length=255, null=True, blank=True) - image = models.CharField(max_length=255, null=True, blank=True) - reliability = models.SmallIntegerField(null=True, blank=True) diff --git a/users/serializers.py b/users/serializers.py deleted file mode 100644 index 0ec035c..0000000 --- a/users/serializers.py +++ /dev/null @@ -1,8 +0,0 @@ -from rest_framework import serializers -from .models import User - - -class UserSerializer(serializers.ModelSerializer): - class Meta: - model = User - fields = "__all__" diff --git a/users/tests.py b/users/tests.py deleted file mode 100644 index a79ca8b..0000000 --- a/users/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/users/views.py b/users/views.py deleted file mode 100644 index fd0e044..0000000 --- a/users/views.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.shortcuts import render - -# Create your views here. From f8a693aa257411705dbdb311126bb8d41262b058 Mon Sep 17 00:00:00 2001 From: dkfla Date: Wed, 31 Jul 2024 15:39:51 +0900 Subject: [PATCH 7/9] =?UTF-8?q?chore:=20=EC=B9=9C=EA=B5=AC=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/migrations/0002_alter_friend_state.py | 24 ++++++++++++++++++ friends/migrations/0003_alter_friend_state.py | 25 +++++++++++++++++++ friends/models.py | 8 +++++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 friends/migrations/0002_alter_friend_state.py create mode 100644 friends/migrations/0003_alter_friend_state.py diff --git a/friends/migrations/0002_alter_friend_state.py b/friends/migrations/0002_alter_friend_state.py new file mode 100644 index 0000000..c0aef6e --- /dev/null +++ b/friends/migrations/0002_alter_friend_state.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.14 on 2024-07-31 05:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("friends", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="friend", + name="state", + field=models.CharField( + choices=[ + ("request", "Request"), + ("approve", "Approve"), + ("deny", "Deny"), + ], + max_length=20, + ), + ), + ] diff --git a/friends/migrations/0003_alter_friend_state.py b/friends/migrations/0003_alter_friend_state.py new file mode 100644 index 0000000..d469b67 --- /dev/null +++ b/friends/migrations/0003_alter_friend_state.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.14 on 2024-07-31 05:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("friends", "0002_alter_friend_state"), + ] + + operations = [ + migrations.AlterField( + model_name="friend", + name="state", + field=models.CharField( + choices=[ + ("request", "Request"), + ("approve", "Approve"), + ("deny", "Deny"), + ], + default="request", + max_length=20, + ), + ), + ] diff --git a/friends/models.py b/friends/models.py index 3a473bc..3f0404b 100644 --- a/friends/models.py +++ b/friends/models.py @@ -5,6 +5,12 @@ class Friend(models.Model): + STATE_CHOICES = [ + ("request", "Request"), + ("approve", "Approve"), + ("deny", "Deny"), + ] + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="friends") friend = models.ForeignKey(User, on_delete=models.CASCADE, related_name="friend_of") - state = models.CharField(max_length=20, null=True, blank=True) + state = models.CharField(max_length=20, choices=STATE_CHOICES, default="request") From b3eeb73d5b6f8cf22b1035042b3c6f3c4100f7a1 Mon Sep 17 00:00:00 2001 From: dkfla Date: Wed, 31 Jul 2024 15:40:42 +0900 Subject: [PATCH 8/9] =?UTF-8?q?chore:=20users=20=EC=95=B1=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mustgou/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mustgou/settings.py b/mustgou/settings.py index 321b507..3ef618c 100644 --- a/mustgou/settings.py +++ b/mustgou/settings.py @@ -42,7 +42,6 @@ "rest_framework", "rest_framework.authtoken", "accounts", - "users", "friends", "restaurants", "reviews", From cec31206b64b79b02f23da2d5b3aef174e9701d9 Mon Sep 17 00:00:00 2001 From: dkfla Date: Wed, 31 Jul 2024 15:41:50 +0900 Subject: [PATCH 9/9] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=20=EA=B2=80=EC=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restaurants/views.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/restaurants/views.py b/restaurants/views.py index 37c8509..6c478b0 100644 --- a/restaurants/views.py +++ b/restaurants/views.py @@ -20,22 +20,19 @@ def restaurant_list(request): @api_view(["GET", "POST"]) +@login_required def search(request): if request.method == "GET": - if request.user.is_authenticated: - histories = SearchHistory.objects.filter(user=request.user) - serializer = SearchHistorySerializer(histories, many=True) - return Response({"histories": serializer.data}) - else: - return Response({"error": "User not authenticated"}, status=401) + histories = SearchHistory.objects.filter(user=request.user) + serializer = SearchHistorySerializer(histories, many=True) + return Response({"histories": serializer.data}) elif request.method == "POST": query = request.data.get("query", "") if not query: return Response({"error": "No search query provided"}, status=400) - if request.user.is_authenticated: - SearchHistory.objects.create(user=request.user, query=query) + SearchHistory.objects.create(user=request.user, query=query) restaurants = Restaurant.objects.filter(name__icontains=query) serializer = RestaurantListSerializer(restaurants, many=True)