Skip to content

Commit

Permalink
Merge branch 'DHBW-FN-TIT20:main' into Implementation-Recipe-Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
screetox authored Feb 16, 2022
2 parents 7865664 + ed39354 commit 0d9a0a0
Show file tree
Hide file tree
Showing 31 changed files with 842 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- name: Test with pytest
working-directory: ./app
run: |
pytest ./tests
pytest -vv --ignore=./tests/test_recipe.py ./tests
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ app/tests/test_db.db
# Ignore Logs
*log*

# Ignore local data
app/data
# Ignore local Database
app/data/essensfindung.db
1 change: 1 addition & 0 deletions app/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/recipeitems.json filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions app/data/recipeitems.json
Git LFS file not shown
4 changes: 2 additions & 2 deletions app/db/crud/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_all_restaurants(db: Session, skip: int = 0, limit: int = 100) -> List[Re
return db.query(Restaurant).offset(skip).limit(limit).all()


def create_restaurant(db: Session, rest: scheme_rest.RestaurantBase) -> Restaurant:
def create_restaurant(db: Session, rest: scheme_rest.RestaurantCreate) -> Restaurant:
"""Create / Add a Restaurant to the DB
Args:
Expand All @@ -51,7 +51,7 @@ def create_restaurant(db: Session, rest: scheme_rest.RestaurantBase) -> Restaura
Restaurant: Return if success
"""
try:
db_rest = Restaurant(place_id=rest.place_id)
db_rest = Restaurant(place_id=rest.place_id, name=rest.name)
db.add(db_rest)
db.commit()
db.refresh(db_rest)
Expand Down
1 change: 1 addition & 0 deletions app/db/models/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class Restaurant(Base):
__tablename__ = "restaurant"

place_id = Column(String, primary_key=True)
name = Column(String, nullable=False, autoincrement=False)

bewertungen = relationship("Bewertung", back_populates="restaurant", passive_deletes=True)
4 changes: 3 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from views import index
from views import restaurant
from views import signin
from views import rating

app = fastapi.FastAPI()

Expand Down Expand Up @@ -69,6 +70,7 @@ def configure_routing():
app.include_router(restaurant.router)
app.include_router(signin.router)
app.include_router(error.router)
app.include_router(rating.router)


def configure_database():
Expand Down Expand Up @@ -174,6 +176,6 @@ async def general_exception_handler(request: fastapi.Request, exc: Exception):

if __name__ == "__main__":
configure()
uvicorn.run(app, port=8000, host="127.0.0.1")
uvicorn.run(app, port=8000, host="192.168.0.112")
else:
configure()
21 changes: 4 additions & 17 deletions app/schemes/scheme_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contains all Filter for the searches"""
from datetime import timedelta
from typing import List
from typing import Optional

Expand All @@ -14,8 +15,8 @@ class FilterBase(BaseModel):
"""Base Filter for recepes and restaurant"""

cuisines: List[scheme_cuisine.PydanticCuisine]
allergies: Optional[List[scheme_allergie.PydanticAllergies]] = None
rating: int
allergies: Optional[List[scheme_allergie.PydanticAllergies]]

@validator("rating")
@classmethod
Expand Down Expand Up @@ -100,19 +101,5 @@ def plz_length(cls, value: str):
class FilterRecipe(FilterBase):
"""Extended Model for Recipe-Filter"""

difficulty: int

@validator("difficulty")
@classmethod
def difficulty_range(cls, value: int):
"""Check if difficulty >= 1 and <= 5
Args:
value (int): Value of difficulty
Raises:
ValueError: If wrong values
"""
if 1 <= value <= 5:
return value
raise ValueError("difficulty is not between 1 (included) and 5 (included)")
keyword: str
total_time: timedelta
14 changes: 14 additions & 0 deletions app/schemes/scheme_recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from datetime import timedelta
from typing import Optional

from pydantic import BaseModel


class Recipe(BaseModel):
id: str
name: str
ingredients: str
url: str
image: Optional[str]
cookTime: Optional[timedelta]
prepTime: Optional[timedelta]
10 changes: 10 additions & 0 deletions app/schemes/scheme_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class RestaurantBase(BaseModel):
"""Scheme that is only needed for the DB"""

place_id: str
name: str


class RestaurantCreate(RestaurantBase):
"""Scheme that is only needed for the DB"""

name: str

class Config:
orm_mode = True
Expand All @@ -50,6 +57,7 @@ class Restaurant(RestaurantBase):
class RestBewertungBase(BaseModel):
"""BaseClass for the Bewertung"""

name: str
comment: Optional[str] = ""
rating: Optional[float] = 0

Expand All @@ -64,6 +72,8 @@ class RestBewertungCreate(RestBewertungBase):
class RestBewertungReturn(RestBewertungBase):
"""Class to return to the frontend"""

email: str
place_id: str
timestamp: datetime.datetime

class Config:
Expand Down
36 changes: 36 additions & 0 deletions app/services/service_rec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas

from schemes.scheme_filter import FilterRecipe
from schemes.scheme_recipe import Recipe
from tools.recipe_db import recipe_db
from tools.recipe_db import RecipeDB


def search_recipe(recipe_filter: FilterRecipe) -> Recipe:
"""Search for a recipe with the given filter
Args:
recipe_filter (FilterRecipe): Filter the Recipes
Returns:
Recipe: The one choosen Recipe
"""
random_recipe: pandas.DataFrame = __apply_filter(recipe_db.pd_frame, recipe_filter).sample()

return Recipe(
id=random_recipe["_id.$oid"][0],
name=random_recipe["name"][0],
ingredients=random_recipe["ingredients"][0],
url=random_recipe["url"][0],
image=random_recipe["image"][0],
cookTime=random_recipe["cookTime"][0],
prepTime=random_recipe["prepTime"][0],
)


def __apply_filter(recipes: pandas.DataFrame, recipe_filter: FilterRecipe) -> pandas.DataFrame:
cooktime_bool = RecipeDB.filter_cooktime(user_pd_frame=recipes, total_time=recipe_filter.total_time)
keyword_bool = RecipeDB.filter_keyword(user_pd_frame=recipes, keyword=recipe_filter.keyword)

filter_bool = cooktime_bool & keyword_bool
return recipes[filter_bool]
22 changes: 18 additions & 4 deletions app/services/service_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Union

import httpx
import sqlalchemy
from sqlalchemy.orm import Session

from db.crud import bewertung as crud_bewertung
Expand Down Expand Up @@ -37,7 +36,14 @@ def get_assessments_from_user(db_session: Session, user: UserBase) -> Union[List
"""
db_rests = crud_bewertung.get_all_user_bewertungen(db_session, user)
scheme_rests = [
RestBewertungReturn(comment=db_rest.kommentar, rating=db_rest.rating, timestamp=db_rest.zeitstempel)
RestBewertungReturn(
name=db_rest.restaurant.name,
email=db_rest.person_email,
place_id=db_rest.place_id,
comment=db_rest.kommentar,
rating=db_rest.rating,
timestamp=db_rest.zeitstempel,
)
for db_rest in db_rests
]
return scheme_rests
Expand All @@ -59,6 +65,9 @@ def add_assessment(db_session: Session, assessment: RestBewertungCreate) -> Rest
try:
created_assessment = crud_bewertung.create_bewertung(db_session, assessment)
return RestBewertungReturn(
name=created_assessment.restaurant.name,
email=created_assessment.person_email,
place_id=created_assessment.place_id,
comment=created_assessment.kommentar,
rating=created_assessment.rating,
timestamp=created_assessment.zeitstempel,
Expand Down Expand Up @@ -88,7 +97,12 @@ def update_assessment(
except DatabaseException as error:
raise error
return RestBewertungReturn(
comment=updated_assessment.kommentar, rating=updated_assessment.rating, timestamp=updated_assessment.zeitstempel
name=updated_assessment.restaurant.name,
email=updated_assessment.person_email,
place_id=updated_assessment.place_id,
comment=updated_assessment.kommentar,
rating=updated_assessment.rating,
timestamp=updated_assessment.zeitstempel,
)


Expand Down Expand Up @@ -205,7 +219,7 @@ def search_for_restaurant(db_session: Session, user: UserBase, user_f: FilterRes
if not crud_restaurant.get_restaurant_by_id(db_session, restaurant.place_id):
crud_restaurant.create_restaurant(db_session, restaurant)
if not crud_bewertung.get_bewertung_from_user_to_rest(db_session, user, restaurant):
add_assessment(db_session, RestBewertungCreate(person=user, restaurant=restaurant))
add_assessment(db_session, RestBewertungCreate(name=restaurant.name, person=user, restaurant=restaurant))
return restaurant


Expand Down
100 changes: 100 additions & 0 deletions app/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,104 @@
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

.drop-shadow {
filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.25));
}
.drop-shadow:hover {
box-shadow: 0 0 0 #fff;
}
.drop-shadow:active {
box-shadow: 0 0 0 #fff;
}
.box-shadow {
transition: box-shadow 0.2s;
box-shadow: 3px 3px 6px rgba(0,0,0,0.30);
}

.box-shadow:hover {
box-shadow: 0 0 0 #fff;
}

.box-shadow:active {
box-shadow: 0 0 0 #fff;
}

.drop-shadow-reveal {
transition: filter 0.4s;
filter: none;
}

.drop-shadow-reveal:hover {
filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.25));
}

.prevent-dark-fill:hover {
background-color: #fff !important;
color: #212529;
}

.prevent-dark-fill:active {
/*background-color: #6EB1DF !important;*/
background-color: #a8cfe9 !important;
border-color: #6eb1df !important;
color: #212529;
}
.prevent-dark-hover:hover {
background-color: #fff;
color: #212529;
}

.limit-width {
max-width: 480px;
}

.filter-character-up {
display: inline-block;
transform: rotate(90deg);
font-size: 0.8rem;
}
.filter-character-down {
display: inline-block;
transform: rotate(180deg);
font-size: 0.8rem;
}

.cursor-pointer {
cursor: pointer;
}

.img-display {
height: calc(1.625rem + 4.5vh);
width: auto;
}

.img-display svg {
height: calc(1.625rem + 4.5vh);
width: auto;
}

@media screen and (min-width: 768px) {
.img-display {
height: 5rem;
width: auto;
}
.img-display svg {
height: 5rem;
width: auto;
}
}

.rotate {
animation: rotation 2s infinite linear;
}

@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
Binary file added app/static/img/icons8-filter-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/img/icons8-recipe-book-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/static/js/rating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/******** inititialize star-rating-svg *****************/
$("#rating_edit_rating").raty({
starOff: 'https://cdn.jsdelivr.net/npm/[email protected]/lib/images/star-off.png',
starOn: 'https://cdn.jsdelivr.net/npm/[email protected]/lib/images/star-on.png',
click: function(score, evt) {
document.getElementById('rating_edit_rating_target').value = score;
},
score: function() {
return document.getElementById('rating_edit_rating_target').value;
}
});
Loading

0 comments on commit 0d9a0a0

Please sign in to comment.