Skip to content

Commit

Permalink
chore: 더미데이터 생성 (#27)
Browse files Browse the repository at this point in the history
* feat: 검색 기능

* feat: 내 맛집 리스트 기능 구현

* chore: users 앱 삭제

* chore: Revert "chore: users 앱 삭제"

This reverts commit 37af76b.

* chore: users 삭제를 위한 경로 변경 및 수정

* chore: users 앱 삭제

* chore: 친구 상태 타입 수정

* chore: users 앱 삭제

* feat: 로그인 반영 검색

---------

Co-authored-by: Shim Kyumin <[email protected]>
  • Loading branch information
dkfla and GalaxyDimension authored Jul 31, 2024
1 parent 8c879c8 commit c8af365
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
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

0 comments on commit c8af365

Please sign in to comment.