Skip to content

Commit

Permalink
Merge pull request #38 from Pure-Plate/develop
Browse files Browse the repository at this point in the history
Release: fix account, review, restaurant list, favorite features
  • Loading branch information
saeyeonn authored May 26, 2024
2 parents c1668c2 + 4374b98 commit f13ca45
Show file tree
Hide file tree
Showing 47 changed files with 124 additions and 50 deletions.
Binary file not shown.
Binary file added pure_plate/account/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/account/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pure_plate/account/__pycache__/tests.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/account/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pure_plate/favorite/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/favorite/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pure_plate/favorite/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified pure_plate/pure_plate/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 4.2.13 on 2024-05-26 11:50

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("restaurant", "0002_rename_categoryid_category_category_id_and_more"),
]

operations = [
migrations.RemoveField(
model_name="restaurant",
name="categories",
),
migrations.AddField(
model_name="restaurant",
name="gluten_free",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="restaurant",
name="halal",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="restaurant",
name="lacto_free",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="restaurant",
name="phone",
field=models.CharField(db_index=True, default=0, max_length=255),
preserve_default=False,
),
migrations.AddField(
model_name="restaurant",
name="photo",
field=models.CharField(db_index=True, default="nonphoto", max_length=255),
preserve_default=False,
),
migrations.AddField(
model_name="restaurant",
name="time",
field=models.CharField(db_index=True, default=0, max_length=255),
preserve_default=False,
),
migrations.AddField(
model_name="restaurant",
name="vegan",
field=models.BooleanField(default=False),
),
migrations.DeleteModel(
name="Category",
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 4 additions & 8 deletions pure_plate/restaurant/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from django.db import models
from django.db.models import Avg

class Category(models.Model):
category_id = models.AutoField(primary_key=True)
category_name = models.CharField(max_length=50, db_index=True)

class Meta:
verbose_name_plural = "categories"

class Restaurant(models.Model):
name = models.CharField(max_length=255, db_index=True)
address = models.CharField(max_length=255)
Expand All @@ -18,7 +11,10 @@ class Restaurant(models.Model):
#phone = models.CharField(max_length=255, db_index=True)
review_count = models.IntegerField(default=0)
avg_rating = models.DecimalField(max_digits=3, decimal_places=2, default=0.00)
categories = models.ManyToManyField(Category, related_name='restaurants')
vegan=models.BooleanField(default=False)
halal=models.BooleanField(default=False)
gluten_free=models.BooleanField(default=False)
lacto_free=models.BooleanField(default=False)

def update_rating(self):
self.review_count = self.review_set.count()
Expand Down
41 changes: 39 additions & 2 deletions pure_plate/restaurant/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
from django.test import TestCase
from django.test import TestCase, Client
from django.urls import reverse
from .models import Restaurant

# Create your tests here.
class RestaurantSearchTests(TestCase):
def setUp(self):
self.client = Client()
# 테스트를 위한 레스토랑 데이터를 생성합니다.
Restaurant.objects.create(
name='Vegan Bliss', address='123 Green Way', vegan=True, halal=False,
gluten_free=True, lacto_free=False, latitude=10.0, longitude=20.0,
time='09:00-21:00', photo='vegan_bliss.jpg', phone='111-222-3333',
review_count=100, avg_rating=4.8
)
Restaurant.objects.create(
name='Halal Heaven', address='456 Crescent Moon', vegan=False, halal=True,
gluten_free=False, lacto_free=True, latitude=30.0, longitude=40.0,
time='10:00-22:00', photo='halal_heaven.jpg', phone='444-555-6666',
review_count=80, avg_rating=4.6
)

def test_search_for_vegan_restaurants(self):
# 비건 옵션을 선택했을 때 해당하는 레스토랑이 반환되는지 테스트합니다.
response = self.client.get(reverse('restaurants-in-categories'), {'categories': 'vegan'})
self.assertEqual(response.status_code, 200)
self.assertIn('Vegan Bliss', response.content.decode())

def test_search_for_halal_restaurants(self):
# 할랄 옵션을 선택했을 때 해당하는 레스토랑이 반환되는지 테스트합니다.
response = self.client.get(reverse('restaurants-in-categories'), {'categories': 'halal'})
self.assertEqual(response.status_code, 200)
self.assertIn('Halal Heaven', response.content.decode())

def test_search_for_gluten_free_and_lacto_free_restaurants(self):
# 글루텐 프리와 락토 프리 옵션을 모두 선택했을 때 해당하는 레스토랑이 없다는 것을 테스트합니다.
response = self.client.get(reverse('restaurants-in-categories'), {'categories': 'glutenfree,lactofree'})
self.assertEqual(response.status_code, 200)
content = response.content.decode()
# 이 부분은 실제 반환되는 내용에 따라 수정이 필요할 수 있습니다.
self.assertTrue('No restaurants found' in content or '[]' in content)
4 changes: 1 addition & 3 deletions pure_plate/restaurant/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from . import views



urlpatterns = [
path('restaurants/',views.restaurants_in_categories_view, name='restaurants-in-categories')
path('list/',views.restaurants_list, name='restaurants-list')
]
60 changes: 23 additions & 37 deletions pure_plate/restaurant/views.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,40 @@
from django.http import JsonResponse
from django.db.models import Count
from .models import Restaurant, Category
from .models import Restaurant

#/api/restaurants_in_categories?categories=Italian,Chinese,Mexican

def restaurants_in_categories_view(request):
def restaurants_list(request):

try:
category_names = request.GET.get('categories', '')
if not category_names:
return JsonResponse({
'status': 200,
'message': 'Category is not selected.',
'data': []
})

category_names_list = category_names.split(',')

# find all restaurants in selected categories
categories = Category.objects.filter(CategoryName__in=category_names_list)
restaurants = Restaurant.objects.filter(categories__in=categories).distinct()

# filtered restaurants list category by category
data = {}
for category_name in category_names_list:
category_restaurants = restaurants.filter(categories__CategoryName=category_name)
category_list = [{
'restaurantId': restaurant.id,
'restaurantName': restaurant.name,
'restaurantAddress': restaurant.address,
'restaurantLatitude': float(restaurant.latitude),
'restaurantLongitude': float(restaurant.longitude),
# 'restaurantTime': restaurant.time,
# 'restaurantPhoto': restaurant.photo,
# 'restaurantPhone': restaurant.phone,
'restaurantReviewCount': restaurant.review_count,
'restaurantRating': str(restaurant.avg_rating),
} for restaurant in category_restaurants]
data[f"{category_name}List"] = category_list
restaurants = Restaurant.objects.all()

data = [{
'Id': restaurant.id,
'Name': restaurant.name,
'Address': restaurant.address,
'Latitude': str(restaurant.latitude),
'Longitude': str(restaurant.longitude),
'Time': restaurant.time,
'Photo': restaurant.photo,
'Phone': restaurant.phone,
'ReviewCount': restaurant.review_count,
'Rating': str(restaurant.avg_rating),
'Vegan': restaurant.vegan,
'Halal': restaurant.halal,
'GlutenFree': restaurant.gluten_free,
'LactoFree': restaurant.lacto_free
} for restaurant in restaurants]


response = {
'status': 200,
'message': 'Successfully retrieved the restaurant list.',
'data': data
}

return JsonResponse(response)
return JsonResponse(response, status=200)

except Exception as e:
return JsonResponse({'status': 400, 'message': str(e), 'data': []})
return JsonResponse({'status': 400, 'message': str(e), 'data': []}, status=400)



Binary file not shown.
Binary file added pure_plate/review/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/review/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/review/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/review/__pycache__/tests.cpython-39.pyc
Binary file not shown.
Binary file added pure_plate/review/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit f13ca45

Please sign in to comment.