Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: 더미데이터 생성 #27

Merged
merged 10 commits into from
Jul 31, 2024
24 changes: 24 additions & 0 deletions friends/migrations/0002_alter_friend_state.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
25 changes: 25 additions & 0 deletions friends/migrations/0003_alter_friend_state.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
8 changes: 7 additions & 1 deletion friends/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 0 additions & 1 deletion mustgou/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"rest_framework",
"rest_framework.authtoken",
"accounts",
"users",
"friends",
"restaurants",
"reviews",
Expand Down
13 changes: 5 additions & 8 deletions restaurants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading