Browse Source

Add API support for restaurant addition and filtering

master
Apostolos Fanakis 6 years ago
parent
commit
a732dadcb0
  1. BIN
      UI/Database API/hyrieus/flavoursAPI/__pycache__/__init__.cpython-35.pyc
  2. BIN
      UI/Database API/hyrieus/flavoursAPI/__pycache__/settings.cpython-35.pyc
  3. BIN
      UI/Database API/hyrieus/flavoursAPI/__pycache__/urls.cpython-35.pyc
  4. BIN
      UI/Database API/hyrieus/flavoursAPI/__pycache__/wsgi.cpython-35.pyc
  5. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/__init__.cpython-35.pyc
  6. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/admin.cpython-35.pyc
  7. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/models.cpython-35.pyc
  8. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/serializers.cpython-35.pyc
  9. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/urls.cpython-35.pyc
  10. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/views.cpython-35.pyc
  11. 7
      UI/Database API/hyrieus/flavoursAPI/hyrieus/admin.py
  12. 116
      UI/Database API/hyrieus/flavoursAPI/hyrieus/migrations/0001_initial.py
  13. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/migrations/__pycache__/0001_initial.cpython-35.pyc
  14. BIN
      UI/Database API/hyrieus/flavoursAPI/hyrieus/migrations/__pycache__/__init__.cpython-35.pyc
  15. 66
      UI/Database API/hyrieus/flavoursAPI/hyrieus/models.py
  16. 48
      UI/Database API/hyrieus/flavoursAPI/hyrieus/serializers.py
  17. 30
      UI/Database API/hyrieus/flavoursAPI/hyrieus/urls.py
  18. 294
      UI/Database API/hyrieus/flavoursAPI/hyrieus/views.py
  19. 32
      UI/Database API/hyrieus/flavoursAPI/settings.py

BIN
UI/Database API/hyrieus/flavoursAPI/__pycache__/__init__.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/__pycache__/settings.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/__pycache__/urls.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/__pycache__/wsgi.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/__init__.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/admin.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/models.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/serializers.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/urls.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/__pycache__/views.cpython-35.pyc

Binary file not shown.

7
UI/Database API/hyrieus/flavoursAPI/hyrieus/admin.py

@ -1,5 +1,10 @@
from django.contrib import admin
from .models import Diet, DietProhibitsIngredient, Drink, DrinkHasIngredient, Food, FoodHasIngredient, Ingredient, Permission, Restaurant, Role, RoleHasPermission, User, UserFollowsDiet, UserProhibitsIngredient, UserRatesDrink, UserRatesFood, UserRatesRestaurant
from .models import (Diet,
DietProhibitsIngredient, Drink, DrinkHasIngredient, Food, FoodHasIngredient,
Ingredient, Permission, Restaurant, Role, RoleHasPermission, User,
UserFollowsDiet, UserProhibitsIngredient, UserRatesDrink, UserRatesFood,
UserRatesRestaurant,
)
admin.site.register(Diet)
admin.site.register(DietProhibitsIngredient)

116
UI/Database API/hyrieus/flavoursAPI/hyrieus/migrations/0001_initial.py

@ -1,7 +1,11 @@
# Generated by Django 2.1.4 on 2019-01-04 16:17
# Generated by Django 2.1.4 on 2019-01-09 11:35
from django.conf import settings
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
@ -9,20 +13,46 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0009_alter_user_last_name_max_length'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('user_age', models.DateField(null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
],
options={
'managed': True,
'db_table': 'user',
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='Diet',
fields=[
('diet_id', models.IntegerField(primary_key=True, serialize=False)),
('diet_id', models.AutoField(primary_key=True, serialize=False)),
('diet_name', models.CharField(max_length=500)),
('diet_description', models.CharField(blank=True, max_length=700, null=True)),
('diet_is_approved', models.BooleanField(default=False)),
],
options={
'db_table': 'diet',
'managed': True,
'db_table': 'diet',
},
),
migrations.CreateModel(
@ -32,21 +62,21 @@ class Migration(migrations.Migration):
('diet', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Diet')),
],
options={
'db_table': 'diet_prohibits_ingredient',
'managed': True,
'db_table': 'diet_prohibits_ingredient',
},
),
migrations.CreateModel(
name='Drink',
fields=[
('drink_id', models.IntegerField(primary_key=True, serialize=False)),
('drink_id', models.AutoField(primary_key=True, serialize=False)),
('drink_name', models.CharField(max_length=500)),
('drink_description', models.CharField(blank=True, max_length=700, null=True)),
('drink_is_approved', models.BooleanField(default=False)),
],
options={
'db_table': 'drink',
'managed': True,
'db_table': 'drink',
},
),
migrations.CreateModel(
@ -56,22 +86,22 @@ class Migration(migrations.Migration):
('drink', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Drink')),
],
options={
'db_table': 'drink_has_ingredient',
'managed': True,
'db_table': 'drink_has_ingredient',
},
),
migrations.CreateModel(
name='Food',
fields=[
('food_id', models.IntegerField(primary_key=True, serialize=False)),
('food_id', models.AutoField(primary_key=True, serialize=False)),
('food_name', models.CharField(max_length=500)),
('food_description', models.CharField(blank=True, max_length=700, null=True)),
('food_calories', models.IntegerField(blank=True, null=True)),
('food_is_approved', models.BooleanField(default=False)),
],
options={
'db_table': 'food',
'managed': True,
'db_table': 'food',
},
),
migrations.CreateModel(
@ -81,8 +111,8 @@ class Migration(migrations.Migration):
('food', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Food')),
],
options={
'db_table': 'food_has_ingredient',
'managed': True,
'db_table': 'food_has_ingredient',
},
),
migrations.CreateModel(
@ -92,25 +122,25 @@ class Migration(migrations.Migration):
('ingredient_has_alcohol', models.BooleanField(blank=True, default=False, null=True)),
],
options={
'db_table': 'ingredient',
'managed': True,
'db_table': 'ingredient',
},
),
migrations.CreateModel(
name='Permission',
fields=[
('permission_id', models.IntegerField(primary_key=True, serialize=False)),
('permission_id', models.AutoField(primary_key=True, serialize=False)),
('permission_description', models.CharField(max_length=700)),
],
options={
'db_table': 'permission',
'managed': True,
'db_table': 'permission',
},
),
migrations.CreateModel(
name='Restaurant',
fields=[
('restaurant_id', models.IntegerField(primary_key=True, serialize=False)),
('restaurant_id', models.AutoField(primary_key=True, serialize=False)),
('restaurant_name', models.CharField(max_length=500)),
('restaurant_category', models.CharField(max_length=10)),
('restaurant_longitude', models.FloatField()),
@ -118,10 +148,11 @@ class Migration(migrations.Migration):
('restaurant_opening', models.TimeField(blank=True, null=True)),
('restaurant_closing', models.TimeField(blank=True, null=True)),
('restaurant_is_approved', models.BooleanField(default=False)),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'restaurant',
'managed': True,
'db_table': 'restaurant',
},
),
migrations.CreateModel(
@ -132,8 +163,8 @@ class Migration(migrations.Migration):
('role_description', models.CharField(max_length=700)),
],
options={
'db_table': 'role',
'managed': True,
'db_table': 'role',
},
),
migrations.CreateModel(
@ -144,24 +175,8 @@ class Migration(migrations.Migration):
('role', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Role')),
],
options={
'db_table': 'role_has_permission',
'managed': True,
},
),
migrations.CreateModel(
name='User',
fields=[
('user_id', models.IntegerField(primary_key=True, serialize=False)),
('user_email', models.CharField(max_length=500)),
('user_username', models.CharField(max_length=500)),
('user_hashed_password', models.CharField(max_length=64)),
('user_salt', models.CharField(max_length=32)),
('user_age', models.DateField()),
('role', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Role')),
],
options={
'db_table': 'user',
'managed': True,
'db_table': 'role_has_permission',
},
),
migrations.CreateModel(
@ -169,11 +184,11 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('diet', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Diet')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.User')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'user_follows_diet',
'managed': True,
'db_table': 'user_follows_diet',
},
),
migrations.CreateModel(
@ -181,11 +196,11 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ingredient_name', models.ForeignKey(db_column='ingredient_name', on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Ingredient')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.User')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'user_prohibits_ingredient',
'managed': True,
'db_table': 'user_prohibits_ingredient',
},
),
migrations.CreateModel(
@ -197,11 +212,11 @@ class Migration(migrations.Migration):
('rating_text', models.CharField(blank=True, max_length=700, null=True)),
('rating_pοrtion_size', models.CharField(blank=True, max_length=6, null=True)),
('drink', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Drink')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.User')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'user_rates_drink',
'managed': True,
'db_table': 'user_rates_drink',
},
),
migrations.CreateModel(
@ -213,11 +228,11 @@ class Migration(migrations.Migration):
('rating_text', models.CharField(blank=True, max_length=700, null=True)),
('rating_pοrtion_size', models.CharField(blank=True, max_length=6, null=True)),
('food', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Food')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.User')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'user_rates_food',
'managed': True,
'db_table': 'user_rates_food',
},
),
migrations.CreateModel(
@ -230,18 +245,13 @@ class Migration(migrations.Migration):
('rating_accessibility', models.CharField(blank=True, max_length=8, null=True)),
('diet', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Diet')),
('restaurant', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Restaurant')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.User')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'user_rates_restaurant',
'managed': True,
'db_table': 'user_rates_restaurant',
},
),
migrations.AddField(
model_name='restaurant',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.User'),
),
migrations.AddField(
model_name='foodhasingredient',
name='ingredient_name',
@ -267,6 +277,16 @@ class Migration(migrations.Migration):
name='ingredient_name',
field=models.ForeignKey(db_column='ingredient_name', on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Ingredient'),
),
migrations.AddField(
model_name='user',
name='role',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.DO_NOTHING, to='hyrieus.Role'),
),
migrations.AddField(
model_name='user',
name='user_permissions',
field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions'),
),
migrations.AlterUniqueTogether(
name='userratesrestaurant',
unique_together={('user', 'restaurant')},

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/migrations/__pycache__/0001_initial.cpython-35.pyc

Binary file not shown.

BIN
UI/Database API/hyrieus/flavoursAPI/hyrieus/migrations/__pycache__/__init__.cpython-35.pyc

Binary file not shown.

66
UI/Database API/hyrieus/flavoursAPI/hyrieus/models.py

@ -1,7 +1,26 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.conf import settings
class Role(models.Model):
role_id = models.IntegerField(primary_key=True)
role_name = models.CharField(max_length=500)
role_description = models.CharField(max_length=700)
class Meta:
managed = True
db_table = 'role'
class User(AbstractUser):
role = models.ForeignKey(Role, models.DO_NOTHING, default=0)
user_age = models.DateField(null=True)
class Meta:
managed = True
db_table = 'user'
class Diet(models.Model):
diet_id = models.IntegerField(primary_key=True)
diet_id = models.AutoField(primary_key=True)
diet_name = models.CharField(max_length=500)
diet_description = models.CharField(max_length=700, blank=True, null=True)
diet_is_approved = models.BooleanField(default=False)
@ -21,7 +40,7 @@ class DietProhibitsIngredient(models.Model):
unique_together = (('diet', 'ingredient_name'),)
class Drink(models.Model):
drink_id = models.IntegerField(primary_key=True)
drink_id = models.AutoField(primary_key=True)
drink_name = models.CharField(max_length=500)
drink_description = models.CharField(max_length=700, blank=True, null=True)
drink_is_approved = models.BooleanField(default=False)
@ -43,7 +62,7 @@ class DrinkHasIngredient(models.Model):
class Food(models.Model):
food_id = models.IntegerField(primary_key=True)
food_id = models.AutoField(primary_key=True)
food_name = models.CharField(max_length=500)
food_description = models.CharField(max_length=700, blank=True, null=True)
food_calories = models.IntegerField(blank=True, null=True)
@ -74,7 +93,7 @@ class Ingredient(models.Model):
class Permission(models.Model):
permission_id = models.IntegerField(primary_key=True)
permission_id = models.AutoField(primary_key=True)
permission_description = models.CharField(max_length=700)
class Meta:
@ -83,7 +102,7 @@ class Permission(models.Model):
class Restaurant(models.Model):
restaurant_id = models.IntegerField(primary_key=True)
restaurant_id = models.AutoField(primary_key=True)
restaurant_name = models.CharField(max_length=500)
restaurant_category = models.CharField(max_length=10)
restaurant_longitude = models.FloatField()
@ -91,23 +110,12 @@ class Restaurant(models.Model):
restaurant_opening = models.TimeField(blank=True, null=True)
restaurant_closing = models.TimeField(blank=True, null=True)
restaurant_is_approved = models.BooleanField(default=False)
user = models.ForeignKey('User', models.DO_NOTHING, blank=True, null=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = True
db_table = 'restaurant'
class Role(models.Model):
role_id = models.IntegerField(primary_key=True)
role_name = models.CharField(max_length=500)
role_description = models.CharField(max_length=700)
class Meta:
managed = True
db_table = 'role'
class RoleHasPermission(models.Model):
role = models.ForeignKey(Role, models.DO_NOTHING)
permission = models.ForeignKey(Permission, models.DO_NOTHING)
@ -118,22 +126,8 @@ class RoleHasPermission(models.Model):
unique_together = (('role', 'permission'),)
class User(models.Model):
user_id = models.IntegerField(primary_key=True)
user_email = models.CharField(max_length=500)
user_username = models.CharField(max_length=500)
user_hashed_password = models.CharField(max_length=64)
user_salt = models.CharField(max_length=32)
role = models.ForeignKey(Role, models.DO_NOTHING)
user_age = models.DateField()
class Meta:
managed = True
db_table = 'user'
class UserFollowsDiet(models.Model):
user = models.ForeignKey(User, models.DO_NOTHING)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
diet = models.ForeignKey(Diet, models.DO_NOTHING)
class Meta:
@ -143,7 +137,7 @@ class UserFollowsDiet(models.Model):
class UserProhibitsIngredient(models.Model):
user = models.ForeignKey(User, models.DO_NOTHING)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
ingredient_name = models.ForeignKey(Ingredient, models.DO_NOTHING, db_column='ingredient_name')
class Meta:
@ -153,7 +147,7 @@ class UserProhibitsIngredient(models.Model):
class UserRatesDrink(models.Model):
user = models.ForeignKey(User, models.DO_NOTHING)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
drink = models.ForeignKey(Drink, models.DO_NOTHING)
rating_grade = models.IntegerField()
rating_date = models.DateField()
@ -167,7 +161,7 @@ class UserRatesDrink(models.Model):
class UserRatesFood(models.Model):
user = models.ForeignKey(User, models.DO_NOTHING)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
food = models.ForeignKey(Food, models.DO_NOTHING)
rating_grade = models.IntegerField()
rating_date = models.DateField()
@ -181,7 +175,7 @@ class UserRatesFood(models.Model):
class UserRatesRestaurant(models.Model):
user = models.ForeignKey(User, models.DO_NOTHING)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
restaurant = models.ForeignKey(Restaurant, models.DO_NOTHING)
diet = models.ForeignKey(Diet, models.DO_NOTHING, blank=True, null=True)
rating_grade = models.IntegerField()

48
UI/Database API/hyrieus/flavoursAPI/hyrieus/serializers.py

@ -1,22 +1,10 @@
from rest_framework import serializers
from rest_framework.authtoken.models import Token
from .models import (
Diet,
DietProhibitsIngredient,
Drink,
DrinkHasIngredient,
Food,
FoodHasIngredient,
Ingredient,
Permission,
Restaurant,
Role,
RoleHasPermission,
User,
UserFollowsDiet,
UserProhibitsIngredient,
UserRatesDrink,
UserRatesFood,
UserRatesRestaurant,
Diet, DietProhibitsIngredient, Drink, DrinkHasIngredient, Food,
FoodHasIngredient, Ingredient, Permission, Restaurant, Role,
RoleHasPermission, User, UserFollowsDiet, UserProhibitsIngredient,
UserRatesDrink, UserRatesFood, UserRatesRestaurant,
)
class DietSerializer(serializers.ModelSerializer):
@ -64,6 +52,16 @@ class RestaurantSerializer(serializers.ModelSerializer):
model = Restaurant
fields = '__all__'
def create(self, validated_data):
user = None
request = self.context.get("request")
if request and hasattr(request, "user"):
user = request.user
user = User.objects.get(username=user)
validated_data['restaurant_is_approved'] = True if (user.role.role_id == 1) else False
restaurant = Restaurant.objects.create(**validated_data)
return restaurant
class RoleSerializer(serializers.ModelSerializer):
class Meta:
model = Role
@ -79,6 +77,16 @@ class UserSerializer(serializers.ModelSerializer):
model = User
fields = '__all__'
class UserPublicInfoSerializer(UserSerializer):
class Meta:
model = User
fields = (
'id',
'role',
'username'
)
class UserFollowsDietSerializer(serializers.ModelSerializer):
class Meta:
model = UserFollowsDiet
@ -103,3 +111,9 @@ class UserRatesRestaurantSerializer(serializers.ModelSerializer):
class Meta:
model = UserRatesRestaurant
fields = '__all__'
class FlavoursTokenSerializer(serializers.ModelSerializer):
user = UserPublicInfoSerializer(many=False, read_only=True)
class Meta:
model = Token
fields = ('key', 'user')

30
UI/Database API/hyrieus/flavoursAPI/hyrieus/urls.py

@ -1,23 +1,12 @@
from django.conf.urls import url
from django.urls import include, path
from rest_framework import routers
from flavoursAPI.hyrieus.views import (DietViewSet,
DietProhibitsIngredientViewSet,
DrinkViewSet,
DrinkHasIngredientViewSet,
FoodViewSet,
FoodHasIngredientViewSet,
IngredientViewSet,
PermissionViewSet,
RestaurantViewSet,
RoleViewSet,
RoleHasPermissionViewSet,
UserViewSet,
UserFollowsDietViewSet,
UserProhibitsIngredientViewSet,
UserRatesDrinkViewSet,
UserRatesFoodViewSet,
UserRatesRestaurantViewSet,
Signup,
from flavoursAPI.hyrieus.views import (DietViewSet, DietProhibitsIngredientViewSet,
DrinkViewSet, DrinkHasIngredientViewSet, FoodViewSet, FoodHasIngredientViewSet,
IngredientViewSet, PermissionViewSet, RestaurantViewSet, RoleViewSet,
RoleHasPermissionViewSet, UserViewSet, UserFollowsDietViewSet,
UserProhibitsIngredientViewSet, UserRatesDrinkViewSet, UserRatesFoodViewSet,
UserRatesRestaurantViewSet, UserSetBirthDay,
)
router = routers.DefaultRouter()
@ -40,7 +29,10 @@ router.register(r'userratesfood', UserRatesFoodViewSet)
router.register(r'userratesrestaurant', UserRatesRestaurantViewSet)
urlpatterns = [
url(r'signup', Signup.as_view()),
# url(r'signup', Signup.as_view()),
path('setUserBirthday/<int:pk>/', UserSetBirthDay.as_view(), name='setUserBirthday'),
path('rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls'))
]
urlpatterns += router.urls

294
UI/Database API/hyrieus/flavoursAPI/hyrieus/views.py

@ -1,127 +1,327 @@
from django.shortcuts import render
from decimal import Decimal
from django.db.models import F, ExpressionWrapper, FloatField
from rest_framework.views import APIView
from rest_framework import viewsets
from .models import (
Diet,
DietProhibitsIngredient,
Drink,
DrinkHasIngredient,
Food,
FoodHasIngredient,
Ingredient,
Permission,
Restaurant,
Role,
RoleHasPermission,
User,
UserFollowsDiet,
UserProhibitsIngredient,
UserRatesDrink,
UserRatesFood,
UserRatesRestaurant,
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.exceptions import PermissionDenied
from .models import (Diet, DietProhibitsIngredient, Drink, DrinkHasIngredient,
Food, FoodHasIngredient, Ingredient, Permission, Restaurant, Role,
RoleHasPermission, User, UserFollowsDiet, UserProhibitsIngredient,
UserRatesDrink, UserRatesFood, UserRatesRestaurant,
)
from .serializers import (
DietSerializer,
DietProhibitsIngredientSerializer,
DrinkSerializer,
DrinkHasIngredientSerializer,
FoodSerializer,
FoodHasIngredientSerializer,
IngredientSerializer,
PermissionSerializer,
RestaurantSerializer,
RoleSerializer,
RoleHasPermissionSerializer,
UserSerializer,
UserFollowsDietSerializer,
UserProhibitsIngredientSerializer,
UserRatesDrinkSerializer,
UserRatesFoodSerializer,
DietSerializer, DietProhibitsIngredientSerializer, DrinkSerializer,
DrinkHasIngredientSerializer, FoodSerializer, FoodHasIngredientSerializer,
IngredientSerializer, PermissionSerializer, RestaurantSerializer,
RoleSerializer, RoleHasPermissionSerializer, UserSerializer,
UserFollowsDietSerializer, UserProhibitsIngredientSerializer,
UserRatesDrinkSerializer, UserRatesFoodSerializer,
UserRatesRestaurantSerializer,
)
class DietViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Diet.objects.all()
serializer_class = DietSerializer
class DietProhibitsIngredientViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = DietProhibitsIngredient.objects.all()
serializer_class = DietProhibitsIngredientSerializer
class DrinkViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Drink.objects.all()
serializer_class = DrinkSerializer
class DrinkHasIngredientViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = DrinkHasIngredient.objects.all()
serializer_class = DrinkHasIngredientSerializer
class FoodViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Food.objects.all()
serializer_class = FoodSerializer
class FoodHasIngredientViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = FoodHasIngredient.objects.all()
serializer_class = FoodHasIngredientSerializer
class IngredientViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Ingredient.objects.all()
serializer_class = IngredientSerializer
class PermissionViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Permission.objects.all()
serializer_class = PermissionSerializer
class RestaurantViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
filterType = self.request.query_params.get('filter_restaurant_type', None)
filterDistanceRadius = self.request.query_params.get('filter_restaurant_radius', None)
filterDistanceLongitude = self.request.query_params.get('filter_restaurant_longitude', None)
filterDistanceLatitude = self.request.query_params.get('filter_restaurant_latitude', None)
filterCalories = self.request.query_params.get('filter_restaurant_calories', None)
restaurants = Restaurant.objects.all()
if filterDistanceRadius is not None:
filterDistanceRadius = float(filterDistanceRadius)
filterDistanceLongitude = float(filterDistanceLongitude)
filterDistanceLatitude = float(filterDistanceLatitude)
import math
restaurants = restaurants.filter(
restaurant_latitude__range=(filterDistanceLatitude-(filterDistanceRadius/111.045),
filterDistanceLatitude+(filterDistanceRadius/111.045)))
restaurants = restaurants.filter(
restaurant_longitude__range=(filterDistanceLongitude-(filterDistanceRadius/(111.045*math.cos(math.radians(filterDistanceLatitude)))),
filterDistanceLongitude+(filterDistanceRadius/(111.045*math.cos(math.radians(filterDistanceLatitude))))))
# ======================================================================================
# WHY THE FUCK DOES BELOW CODE FAIL? :-(
# ======================================================================================
# restaurants = restaurants.annotate(distance =
# 111.045 * math.degrees(math.acos(
# math.cos(math.radians(filterDistanceLatitude))
# * math.cos(math.radians(F('restaurant_latitude')))
# * math.cos(math.radians(filterDistanceLongitude - float(F('restaurant_longitude'))))
# + math.sin(math.radians(filterDistanceLatitude))
# * math.sin(math.radians(F('restaurant_latitude')))
# )))
# restaurants = restaurants.filter(distance__lt=filterDistanceRadius)
# restaurants = restaurants.order_by('distance')
restaurants = restaurants.distinct();
if filterType is not None:
restaurants = restaurants.filter(restaurant_category=filterType)
if not user.role.role_id == 1:
restaurants = restaurants.filter(restaurant_is_approved=True)
return restaurants
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Restaurant.objects.all()
serializer_class = RestaurantSerializer
class RoleViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = Role.objects.all()
serializer_class = RoleSerializer
class RoleHasPermissionViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = RoleHasPermission.objects.all()
serializer_class = RoleHasPermissionSerializer
class UserViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = User.objects.all()
serializer_class = UserSerializer
class UserFollowsDietViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = UserFollowsDiet.objects.all()
serializer_class = UserFollowsDietSerializer
class UserProhibitsIngredientViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = UserProhibitsIngredient.objects.all()
serializer_class = UserProhibitsIngredientSerializer
class UserRatesDrinkViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = UserRatesDrink.objects.all()
serializer_class = UserRatesDrinkSerializer
class UserRatesFoodViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = UserRatesFood.objects.all()
serializer_class = UserRatesFoodSerializer
class UserRatesRestaurantViewSet(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user),
'auth': unicode(request.auth),
}
return Response(content)
queryset = UserRatesRestaurant.objects.all()
serializer_class = UserRatesRestaurantSerializer
from rest_framework.views import APIView, Response
class UserSetBirthDay(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
class Signup(APIView):
def get(self, request, format=None):
serializer = User.objects.all()
return Response(serializer.data, status=status.HTTP_201_CREATED)
def put(self, request, pk, format=None):
try:
user = User.objects.get(pk=pk)
except Snippet.DoesNotExist:
raise Http404
if not request.user == user:
raise PermissionDenied({"message":"You don't have permission to access"})
def post(self, request, format=None):
serializer = UserSerializer(data=request.data)
serializer = UserSerializer(user, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@classmethod
def get_extra_actions(cls):
return []

32
UI/Database API/hyrieus/flavoursAPI/settings.py

@ -38,9 +38,17 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'flavoursAPI.hyrieus',
'rest_auth',
'rest_framework',
'rest_framework.authtoken',
'rest_auth.registration',
'allauth.account',
'allauth',
'django.contrib.sites',
]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@ -82,7 +90,6 @@ DATABASES = {
'USER': 'flavoursUser',
'PASSWORD': 'flavours13',
'HOST': '83.212.109.171',
# 'HOST': '127.0.0.1',
'PORT': '',
},
}
@ -127,3 +134,26 @@ USE_TZ = True
STATIC_URL = '/static/'
SILENCED_SYSTEM_CHECKS = ['mysql.E001']
AUTH_USER_MODEL = 'hyrieus.User'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
)
}
REST_AUTH_SERIALIZERS = {
'TOKEN_SERIALIZER': 'flavoursAPI.hyrieus.serializers.FlavoursTokenSerializer',
}
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'

Loading…
Cancel
Save