def get_current_user(): session = get_session() current_user_id = get_jwt_identity() user = session.query(User).get(current_user_id) json_user = convert_to_json(user) session.close() return json_user
def get_places(): session = get_session() places = session.query(Place).all() locale = get_locale() json_places = convert_to_json(places, locale) session.close() return json_places
def get_historical_persons(): session = get_session() historical_persons = session.query(HistoricalPerson).all() locale = get_locale() json_historical_persons = convert_to_json(historical_persons, locale) session.close() return json_historical_persons
def get_cities(): session = get_session() cities = session.query(City).all() locale = get_locale() json_cities = convert_to_json(cities, locale) session.close() return json_cities
def get_user_visited_by_id(): session = get_session() current_user_id = get_jwt_identity() user = session.query(User).get(current_user_id) locale = get_locale() json_visited_places = convert_to_json( list(map(lambda entity: entity.to_entity_json(locale), user.visited_places)) ) session.close() return json_visited_places
def get_user_reviews_by_id(): limit = request.args.get('limit') session = get_session() current_user_id = get_jwt_identity() reviews = session.query(Review).filter( Review.user_id == current_user_id ).order_by(desc(Review.time)).limit(limit).all() json_reviews = convert_to_json(reviews) session.close() return json_reviews
def get_place_by_id(object_id): session = get_session() place = session.query(Place).get(object_id) if place is None: session.close() abort(404, "Place with id = %s not found" % object_id) locale = get_locale() json_place = convert_to_json(place, locale) session.close() return json_place
def get_route_by_id(route_id): session = get_session() route = session.query(Route).get(route_id) if route is None: session.close() abort(404, "Route with id = %s not found" % route_id) locale = get_locale() json_route = convert_to_json(route, locale) session.close() return json_route
def get_object_by_id(object_id): session = get_session() obj = session.query(Object).get(object_id) if obj is None: session.close() abort(404, "Object with id = %s not found" % object_id) locale = get_locale() json_object = convert_to_json(obj, locale) session.close() return json_object
def get_category_by_id(category_id): session = get_session() cat = session.query(Category).get(category_id) if cat is None: session.close() abort(404, "Category with id = %s not found" % category_id) locale = get_locale() json_category = convert_to_json(cat, locale) session.close() return json_category
def get_categories(): session = get_session() categories = session.query(Category)\ .outerjoin(CategoryObject)\ .group_by(Category)\ .order_by(desc(func.count(CategoryObject.c.object_id)))\ .all() locale = get_locale() json_categories = convert_to_json(categories, locale) session.close() return json_categories
def get_historical_person_by_id(object_id): session = get_session() historical_person = session.query(HistoricalPerson).get(object_id) if historical_person is None: session.close() abort(404, "Historical person with id = %s not found" % object_id) locale = get_locale() json_historical_person = convert_to_json(historical_person, locale) session.close() return json_historical_person
def get_city_by_id(city_id): session = get_session() city = session.query(City).get(city_id) if city is None: session.close() abort(404, "City with id = %s not found" % city_id) locale = get_locale() json_city = convert_to_json(city, locale) session.close() return json_city
def get_routes(): session = get_session() city_id = request.args.get('city') object_id = request.args.get('object') routes = session.query(Route).filter( Route.city_id == city_id if city_id is not None else True, Route.places.any(RoutePlaceInfo.place_id == object_id) if object_id is not None else True ).all() locale = get_locale() mapped_routes = list(map(lambda r: r.to_view_json(locale), routes)) json_routes = convert_to_json(mapped_routes, locale) session.close() return json_routes
def get_reviews(): entity_id = request.args.get('object') limit = request.args.get('limit') session = get_session() locale = get_locale().name reviews = session.query(Review).filter( Review.entity_id == entity_id if entity_id is not None else True, Review.text.isnot(None) ).order_by(case(((Review.locale == locale, 1),), else_=2), desc(Review.time))\ .limit(limit)\ .all() json_reviews = convert_to_json(reviews) session.close() return json_reviews
def get_objects(): session = get_session() city_id = request.args.get('city') object_type = request.args.get('type') category = request.args.get('category') objects = session.query(Object).filter( Object.city_id == city_id if city_id is not None else True, Object.type == object_type if object_type is not None else True, Object.categories.any(Category.label == category) if category is not None else True ).all() locale = get_locale() mapped_objects = list(map(lambda o: o.to_object_json(locale), objects)) json_objects = convert_to_json(mapped_objects, locale) session.close() return json_objects