Skip to content

Commit

Permalink
Merge pull request #252 from MensaToday/feature/mensa-map
Browse files Browse the repository at this point in the history
Feature/mensa map
  • Loading branch information
martenjostmann authored Mar 5, 2023
2 parents c377891 + 3e97ba3 commit 740d84b
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 13,386 deletions.
1 change: 1 addition & 0 deletions backend/mensa/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path('mensa/get_week_recommendation', views.get_week_recommendation),
path('mensa/get_quiz_dishes', views.get_quiz_dishes),
path('mensa/save_user_side_dishes', views.save_user_side_dishes),
path('mensa/mensa_data', views.get_mensa_data),
]
37 changes: 35 additions & 2 deletions backend/mensa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from rest_framework.response import Response

from mensa.models import Dish, DishPlan, UserDishRating, Category, Allergy, \
UserSideSelection
UserSideSelection, Mensa
from mensa_recommend.serializers import DishPlanSerializer, \
UserDishRatingSerializer, DishSerializer
UserDishRatingSerializer, DishSerializer, MensaSerializer
from mensa_recommend.source.computations.date_computations import \
get_last_monday
from mensa_recommend.source.computations.transformer import transform_rating
Expand Down Expand Up @@ -560,3 +560,36 @@ def save_user_side_dishes(request):
else:
return Response("Not all fields provided",
status=status.HTTP_406_NOT_ACCEPTABLE)


@api_view(['GET'])
@permission_classes((permissions.AllowAny,))
def get_mensa_data(request):
"""Get all relevant information about each mensa in the system
Route: api/v1/mensa/mensa_data
Authorization: AllowAny
Methods: Get
Output
-------
[
{
"id": 1,
"name": "Bistro Denkpause",
"city": "Münster",
"street": "Corrensstr.",
"houseNumber": "25",
"zipCode": 48149,
"startTime": "11:30:00",
"endTime": "14:15:00",
"lat": "51.96836000",
"lon": "7.59485300"
},
...
]
"""

mensa_qs = Mensa.objects.all()
mensa_serialized = MensaSerializer(mensa_qs, many=True).data
return Response(mensa_serialized)
11 changes: 7 additions & 4 deletions backend/mensa_recommend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_translated_name(self, obj: mensa_model.Dish) -> str:
class MensaSerializer(serializers.ModelSerializer):
class Meta:
fields = ["id", "name", "city", "street",
"houseNumber", "zipCode", "startTime", "endTime"]
"houseNumber", "zipCode", "startTime", "endTime", "lat", "lon"]
model = mensa_model.Mensa


Expand Down Expand Up @@ -124,10 +124,13 @@ def __init__(self, *args, **kwargs):
del self.fields['side_selected']

def get_ext_ratings(self, obj):
ext_ratings = mensa_model.ExtDishRating.objects.filter(
mensa=obj.mensa, dish=obj.dish).latest("date")
try:
ext_ratings = mensa_model.ExtDishRating.objects.filter(
mensa=obj.mensa, dish=obj.dish).latest("date")

return ExtRatingsSerializer(ext_ratings, read_only=True).data
return ExtRatingsSerializer(ext_ratings, read_only=True).data
except mensa_model.ExtDishRating.DoesNotExist:
return None

def get_popular_side_dish(self, obj):
popular_side = side_dish_recommender.predict(obj)
Expand Down
Loading

0 comments on commit 740d84b

Please sign in to comment.