Restaurant

Service for all Recipe interactions

Main Module for the Restaurant-Search

Functions:

add_assessment(db_session, assessment)

Add the given assessment to the Database.

apply_filter(rests, user_f)

Apply all filter (current only Rating)

create_rest_filter(db_session, filter_rest, user)

Add a Filter to an existing person

delete_assessment(db_session, user, rest)

Delete one assessment that are mapped between the user and rest

fill_user_rating(db_session, rests, user)

Search in the connected DB if one restaurant got already rated from the user and if so add the value to the restaurant

filter_rating(rests, rating)

Remove all Restaurants from the list under the given rating

get_assessments_from_user(db_session, user)

Get Bewertungen from a User to all restaurants

get_coordinates_from_location(location)

Convert a string containing an address into coordinates

get_rest_filter_from_user(db_session, user)

Return the saved Filter from the Database if found one

search_for_restaurant(db_session, user, user_f)

Do a full search for a Restaurant.

select_restaurant(rests)

Select one restaurant with specific weight.

update_assessment(db_session, ...)

Update the comment and rating of a existing assessment

update_rest_filter(db_session, ...)

Update a Filter from a User.

services.service_res.add_assessment(db_session: sqlalchemy.orm.session.Session, assessment: schemes.scheme_rest.RestBewertungCreate) schemes.scheme_rest.RestBewertungReturn[source]

Add the given assessment to the Database.

Parameters
Raises

schemes.exceptions.DatabaseException – if the User or Restaurant does not exist or the assessment is duplicated

Returns

The created Restaurant

Return type

[schemes.scheme_rest.RestBewertungReturn]

services.service_res.apply_filter(rests: List[schemes.scheme_rest.Restaurant], user_f: schemes.scheme_filter.FilterRest) List[schemes.scheme_rest.Restaurant][source]

Apply all filter (current only Rating)

Parameters
Returns

The filtered List of the restaurants

Return type

List[schemes.scheme_rest.Restaurant]

services.service_res.create_rest_filter(db_session: sqlalchemy.orm.session.Session, filter_rest: schemes.scheme_filter.FilterRestDatabase, user: schemes.scheme_user.UserBase) schemes.scheme_filter.FilterRestDatabase[source]

Add a Filter to an existing person

Parameters
Raises

schemes.exceptions.UserNotFound – If the User does not exist

Returns

Added Filter

Return type

schemes.scheme_filter.FilterRestDatabase

services.service_res.delete_assessment(db_session: sqlalchemy.orm.session.Session, user: schemes.scheme_user.UserBase, rest: schemes.scheme_rest.RestaurantBase) int[source]

Delete one assessment that are mapped between the user and rest

Parameters
Raises

schemes.exceptions.DatabaseException – if the User or Restaurant does not exist

Returns

The number of affected Rows of the delete

Return type

int

services.service_res.fill_user_rating(db_session: sqlalchemy.orm.session.Session, rests: List[schemes.scheme_rest.Restaurant], user: schemes.scheme_user.UserBase) List[schemes.scheme_rest.Restaurant][source]

Search in the connected DB if one restaurant got already rated from the user and if so add the value to the restaurant

Parameters
  • db_session (sqlalchemy.orm.Session) – Session to the DB -> See db: Session = Depends(get_db)

  • google_res (List[schemes.scheme_rest.Restaurant]) – Restaurants for lookup

Returns

Return of the input List with the user rating if one got found

Return type

List[schemes.scheme_rest.Restaurant]

services.service_res.filter_rating(rests: List[schemes.scheme_rest.Restaurant], rating: int) List[schemes.scheme_rest.Restaurant][source]

Remove all Restaurants from the list under the given rating

Parameters
Returns

Filtered List based ob the rating

Return type

List[schemes.scheme_rest.Restaurant]

services.service_res.get_assessments_from_user(db_session: sqlalchemy.orm.session.Session, user: schemes.scheme_user.UserBase) Optional[List[schemes.scheme_rest.RestBewertungReturn]][source]

Get Bewertungen from a User to all restaurants

Parameters
  • db_session (sqlalchemy.orm.Session) – Session to the DB -> See db: Session = Depends(get_db)

  • user_mail (str) – Mail of the User

Returns

Return a List of all Restaurants or None

Return type

Union[List[schemes.scheme_rest.RestBewertungReturn], None]

services.service_res.get_coordinates_from_location(location: str) schemes.scheme_rest.LocationBase[source]

Convert a string containing an address into coordinates

Parameters

location (str) – The address/zipcode string to search

Raises

NoneExcistingLocationException – Raises if the location was not found

Returns

Location with the coordinates

Return type

schemes.scheme_rest.LocationBase

services.service_res.get_rest_filter_from_user(db_session: sqlalchemy.orm.session.Session, user: schemes.scheme_user.UserBase) Optional[schemes.scheme_filter.FilterRestDatabase][source]

Return the saved Filter from the Database if found one

Parameters
Returns

Return the Filter or None

Return type

Union[schemes.scheme_filter.FilterRest, None]

services.service_res.search_for_restaurant(db_session: sqlalchemy.orm.session.Session, user: schemes.scheme_user.UserBase, user_f: schemes.scheme_filter.FilterRest) schemes.scheme_rest.Restaurant[source]

Do a full search for a Restaurant. This does the google search, weights the result with the user rating and choose one of the restaurants according to the weights

Parameters
Raises
Returns

The one choosen Restaurant where the user have to go now!

Return type

schemes.scheme_rest.Restaurant

services.service_res.select_restaurant(rests: List[schemes.scheme_rest.Restaurant]) schemes.scheme_rest.Restaurant[source]

Select one restaurant with specific weight. weight = user_rating * 4 + google_rating * 2. If None rating found it will be count as 0

Parameters

user_res (List[schemes.scheme_rest.Restaurant]) – The Rating of the Restaurants are optional

Returns

The random chooses restaurant

Return type

schemes.scheme_rest.Restaurant

services.service_res.update_assessment(db_session: sqlalchemy.orm.session.Session, old_assessment: schemes.scheme_rest.RestBewertungCreate, new_assessment: schemes.scheme_rest.RestBewertungCreate) schemes.scheme_rest.RestBewertungReturn[source]

Update the comment and rating of a existing assessment

Parameters
Raises

schemes.exceptions.DatabaseException – if the User or Restaurant does not exist

Returns

Restaurant with the new values

Return type

schemes.scheme_rest.RestBewertungReturn

services.service_res.update_rest_filter(db_session: sqlalchemy.orm.session.Session, filter_updated: schemes.scheme_filter.FilterRestDatabase, user: schemes.scheme_user.UserBase) schemes.scheme_filter.FilterRestDatabase[source]

Update a Filter from a User. Need the full information of the filter (not only the new one)

Parameters
Raises

schemes.exceptions.UserNotFound – If the User is not in the db

Returns

The updated Filter

Return type

schemes.scheme_filter.FilterRestDatabase