Exemple #1
0
    def get_customer_reservation(fromDate: str, toDate: str, customer_id: str):
        current_app.logger.debug("Filtering by: {}".format(
            [fromDate, toDate, customer_id]))

        # bind filter params...
        url = "{}?user_id={}".format(BOOKING_MICROSERVICE_URL, customer_id)
        if fromDate:
            url = HttpUtils.append_query(url, "fromDate", fromDate)
        if toDate:
            url = HttpUtils.append_query(url, "toDate", toDate)

        response = HttpUtils.make_get_request(url)
        return response
Exemple #2
0
    def get_reservation_rest(restaurant_id, from_date, to_date):
        """
        This method contains the logic to find all reservation in the restaurant
        with the filter on the date
        """

        url = "{}/list/{}".format(BOOKING_MICROSERVICE_URL, restaurant_id)
        if from_date:
            url = HttpUtils.append_query(url, "fromDate", from_date)
        if to_date:
            url = HttpUtils.append_query(url, "toDate", to_date)

        response = HttpUtils.make_get_request(url)
        return response
Exemple #3
0
    def review_restaurant(restaurant_id, reviewer_email, stars, review):
        """
        This method insert a review to the specified restaurant
        """
        if stars is None or review is None or review == "":
            return None
        if stars < 0 or stars > 5:
            return None

        json = {
            "stars": stars,
            "review": review,
            "reviewer_email": reviewer_email
        }
        url = "{}/{}/reviews".format(RESTAURANTS_MICROSERVICE_URL,
                                     restaurant_id)
        current_app.logger.debug("URL to microservices: {}".format(url))
        response, code = HttpUtils.make_post_request(url, json)

        if response is None:
            return None

        review = ReviewModel()
        json["id"] = response["id"]
        json["date"] = response["date"]
        json["restaurant_id"] = restaurant_id
        review.fill_from_json(json)
        return review
Exemple #4
0
 def send_possible_contact(contacts: list) -> bool:
     """
     This method perform the request to send emails to possible contacts
     """
     url = EMAIL_MICROSERVICE_URL + "/send_contact"
     response = HttpUtils.make_post_request(url, contacts)
     return response is not None
Exemple #5
0
 def delete_dish(dish_id):
     """
     This method delete a dish
     :param dish_id: dish id
     """
     url = "{}/dishes/{}".format(RESTAURANTS_MICROSERVICE_URL, dish_id)
     response = HttpUtils.make_delete_request(url)
     return response
Exemple #6
0
 def get_user_by_id(user_id):
     """"""
     user = "******".format(USER_MICROSERVICE_URL, user_id)
     response = HttpUtils.make_get_request(user)
     if response is None:
         return None
     user_model = UserModel()
     user_model.fill_from_json(response)
     return user_model
Exemple #7
0
 def force_reload_rating_all_restaurants():
     """
     This method call the restaurants api to force the microservice to recalculate
     the rating for each restaurants
     :return if the request is ok I rill return the request, otherwise None
     """
     user = "******".format(
         RESTAURANTS_MICROSERVICE_URL)
     return HttpUtils.make_get_request(user)
Exemple #8
0
 def get_opening_hours_restaurant(restaurant_id: int):
     """
     This method help to retreival all information inside the
     """
     url = "{}/{}/openings".format(RESTAURANTS_MICROSERVICE_URL,
                                   restaurant_id)
     response = HttpUtils.make_get_request(url)
     if response is None:
         return None
     return response["openings"]
Exemple #9
0
 def get_menu_restaurant(restaurant_id: int):
     """
     This method help to retrieve all information inside the
     """
     url = "{}/{}/menu".format(RESTAURANTS_MICROSERVICE_URL, restaurant_id)
     current_app.logger.debug("URL to microservices is {}".format(url))
     response = HttpUtils.make_get_request(url)
     if response is None:
         return None
     return response["menus"]
Exemple #10
0
    def get_restaurant_name(restaurant_id):
        """
        Given the id return the name of the restaurant
        """
        response = HttpUtils.make_get_request("{}/{}/name".format(
            RESTAURANTS_MICROSERVICE_URL, restaurant_id))
        if response is None:
            return ""

        return response["result"]
Exemple #11
0
 def get_count_of_positive_user():
     """
     This method perform the request to get all positive user inside the database
     """
     url = "{}/report_positive".format(USER_MICROSERVICE_URL)
     response = HttpUtils.make_get_request(url)
     if response is None or len(response) == 0:
         return []
     users = response["users"]
     return len(users)
Exemple #12
0
    def get_restaurant_people(restaurant_id: int):
        """
        Given the id of the restaurant return the number of people at lunch and dinner
        """
        response = HttpUtils.make_get_request("{}/stats/{}".format(
            BOOKING_MICROSERVICE_URL, restaurant_id))
        if response is None:
            return [0, 0, 0]

        return [response["lunch"], response["dinner"], response["now"]]
Exemple #13
0
 def delete_restaurant(restaurant_id: int) -> bool:
     """
     This method perform the request to microservices to delete the restaurants
     :return true or false
     """
     url = "{}/delele/{}".format(RESTAURANTS_MICROSERVICE_URL,
                                 restaurant_id)
     current_app.logger.debug("URL to microservice is {}".format(url))
     response = HttpUtils.make_put_request(url, {})
     return response is not None
Exemple #14
0
 def delete_table(table_id):
     """
     This method remove a table from the restaurant
     :param table: table id
     """
     url = "{}/table/{}".format(RESTAURANTS_MICROSERVICE_URL, table_id)
     response = HttpUtils.make_delete_request(url)
     if response is None:
         return None
     return True
Exemple #15
0
 def get_all_restaurants():
     """
     Method to return a list of all restaurants inside the database
     """
     url = "{}".format(RESTAURANTS_MICROSERVICE_URL)
     current_app.logger.debug("URL microservices: {}".format(url))
     response = HttpUtils.make_get_request(url)
     if response is None:
         current_app.logger.error("Microservices error")
         return []
     return response["restaurants"]
Exemple #16
0
 def add_table(table):
     """
     This method add a table to the restaurant
     :param table: TableModel to insert
     """
     url = "{}/{}/tables".format(RESTAURANTS_MICROSERVICE_URL,
                                 table.restaurant_id)
     response = HttpUtils.make_post_request(url, table.serialize())
     if response is None:
         return None
     return True
Exemple #17
0
 def add_photo(photo):
     """
     This method add a photo to the restaurant photo gallery
     :param photo: PhotoModel to insert
     """
     url = "{}/{}/photos".format(RESTAURANTS_MICROSERVICE_URL,
                                 photo.restaurant_id)
     response, code = HttpUtils.make_post_request(url, photo.serialize())
     if response is None:
         return None
     photo.fill_from_json(response)
     return photo
Exemple #18
0
 def insert_dish(dish):
     """
     This method insert the dish in the system
     :param dish: DishModel of the dish
     """
     url = "{}/{}/dishes".format(RESTAURANTS_MICROSERVICE_URL,
                                 dish.restaurant_id)
     response, code = HttpUtils.make_post_request(url, dish.serialize())
     if response is None:
         return None
     else:
         return response
Exemple #19
0
 def search_possible_contacts(email: str = None, phone: str = None):
     """
     Search all possible contact for the user with email of phone
     """
     if email is not None and len(email) != 0:
         url = USER_MICROSERVICE_URL + "/positiveinfo/email/" + str(email)
     elif phone is not None and len(phone) != 0:
         url = USER_MICROSERVICE_URL + "/positiveinfo/phone/" + str(phone)
     else:
         return None
     # check if the user exists (ON VIEW)
     # check if the user is positive (get also date of marking) (API) ????
     return HttpUtils.make_get_request(url)
Exemple #20
0
 def update_restaurant(restaurant_id, name, lat, lon, anticovid_measures):
     restaurant = RestaurantServices.get_rest_by_id(restaurant_id)
     if restaurant is None:
         return None
     restaurant.name = name
     restaurant.lat = lat
     restaurant.lon = lon
     restaurant.covid_measures = anticovid_measures
     url = "{}/update".format(RESTAURANTS_MICROSERVICE_URL)
     response, status_code = HttpUtils.make_put_request(
         url, restaurant.serialize())
     if status_code == 200:
         return True
     return None
Exemple #21
0
 def get_rest_by_id(id: int):
     """
     This method contains the logic to get an restaurants by id
     :param id: The restaurants id
     """
     url = "{}/{}".format(RESTAURANTS_MICROSERVICE_URL, id)
     current_app.logger.debug("URL to microservices is {}".format(url))
     restaurant = HttpUtils.make_get_request(url)
     if restaurant is None:
         return None
     current_app.logger.debug(restaurant)
     restaurant_model = RestaurantModel()
     restaurant_model.fill_from_json(restaurant)
     return restaurant_model
Exemple #22
0
    def unmark_positive(email: str = None, phone: str = None):
        """
        This method perform the request to user microservices to make the user positive
        """
        if email is None and phone is None:
            return "Insert an email or a phone number"

        if email is not None and len(email) != 0:
            body = {"key": "email", "value": email}
        else:
            body = {"key": "phone", "value": phone}

        url = USER_MICROSERVICE_URL + "/unmark"
        response = HttpUtils.make_put_request(url, body)
        return response
Exemple #23
0
 def get_list_of_positive_user():
     """
     This method perform the request to get all positive user inside the database
     """
     url = "{}/report_positive".format(USER_MICROSERVICE_URL)
     response = HttpUtils.make_get_request(url)
     if response is None or len(response) == 0:
         return []
     users = response["users"]
     list_user = []
     for user in users:
         new_user = UserModel()
         new_user.fill_from_json(user)
         list_user.append(new_user)
     return list_user
Exemple #24
0
    def modify_user(user_form: UserForm,
                    role_id: int = None,
                    user_id: int = None):
        """
        This method take an user that is populate from te called (e.g: the flat form)
        and make the operation to store it as persistent (e.g database).
        We can assume that by default is not possible change the password
        :param form: the user form with new data
        :param user_id: it is used only for test because the session is not available
        :param role_id: by default is none but it is possible setup to change also the role id
        :return: the user with the change if is changed
        """
        if user_id is None:
            user_id = current_user.id
        if role_id is None:
            role_id = current_user.role_id

        email = user_form.email.data
        current_app.logger.debug("New user email {}".format(email))
        phone = user_form.phone.data
        current_app.logger.debug("New user phone {}".format(phone))
        date = user_form.dateofbirth.data
        current_app.logger.debug("New user birth {}".format(date))
        firstname = user_form.firstname.data
        current_app.logger.debug("New user firstname {}".format(firstname))
        lastname = user_form.lastname.data
        current_app.logger.debug("New user lastname {}".format(lastname))
        json_request = {
            "email": email,
            "phone": phone,
            "dateofbirth": str(date),
            "firstname": firstname,
            "lastname": lastname,
            "role": role_id,
            "id": user_id,
        }
        current_app.logger.debug("Request body \n{}".format(json_request))
        url = "{}/data/".format(USER_MICROSERVICE_URL)
        response = HttpUtils.make_put_request(to_url=url, args=json_request)
        if response[0] is None:
            current_app.logger.debug("An error with code occurs {}".format(
                response[1]))
            return None
        json = response[0]
        current_app.logger.debug("Response: ".format(json))
        user = UserModel()
        user.fill_from_json(json)
        return user
Exemple #25
0
    def get_three_reviews(restaurant_id):
        """
        Given the restaurant_di return three random reviews
        """
        response = HttpUtils.make_get_request("{}/{}/reviews/3".format(
            RESTAURANTS_MICROSERVICE_URL, restaurant_id))

        if response is None:
            return []

        review_list = []
        for json in response["Reviews"]:
            review = ReviewModel()
            review.fill_from_json(json)
            review_list.append(review)
        return review_list
Exemple #26
0
 def login_user(email: str, password: str) -> (UserModel, int):
     """
     This method perform the http request to perform the login on user microservices
     :return It return the user if the login has success
     """
     current_app.logger.debug("Email user: {}".format(email))
     current_app.logger.debug("Password is {}".format(password))
     url = "{}/login".format(USER_MICROSERVICE_URL)
     current_app.logger.debug("URL to call microservices: {}".format(url))
     json = {"email": email, "password": password}
     response, status_code = HttpUtils.make_post_request(url, json)
     if response is None:
         return None, status_code
     user = UserModel()
     user.fill_from_json(response)
     return user, status_code
Exemple #27
0
 def delete_user(user_id: int = None):
     user = UserService.get_user_by_id(user_id=user_id)
     if user is None:
         return False
     with current_app.test_request_context():
         if user.role_id == 2 and "RESTAURANT_ID" in session:
             restaurant_id = session["RESTAURANT_ID"]
             response = RestaurantServices.delete_restaurant(
                 restaurant_id=restaurant_id)
             if response is False:
                 current_app.logger.debug("Impossible delete restaurant")
                 return False
     url = "{}/delete/{}".format(USER_MICROSERVICE_URL, str(user_id))
     response = HttpUtils.make_delete_request(url)
     if response is not None:
         return True
     else:
         return False
Exemple #28
0
    def get_dishes_restaurant(restaurant_id: int):
        """
        This method return the restaurants dished
        """
        url = "{}/{}/dishes".format(RESTAURANTS_MICROSERVICE_URL,
                                    restaurant_id)
        current_app.logger.debug("URL to microservices is {}".format(url))
        response = HttpUtils.make_get_request(url)
        if response is None:
            return None
        dishes = []
        json_dishes = response["dishes"]
        for json_dish in json_dishes:
            new_dish = DishModel()
            new_dish.fill_from_json(json_dish)
            dishes.append(new_dish)

        return dishes
Exemple #29
0
 def get_photos_restaurants(restaurant_id: int):
     """
     This method retrieval all information about the restaurants photos
     """
     url = "{}/{}/photos".format(RESTAURANTS_MICROSERVICE_URL,
                                 restaurant_id)
     current_app.logger.debug("URL to microservices is {}".format(url))
     response = HttpUtils.make_get_request(url)
     if response is None:
         return None
     photos = []
     for json_photo in response["photos"]:
         current_app.logger.debug("photo {}, url {}".format(
             json_photo["id"], json_photo["url"]))
         new_photo = PhotoModel()
         new_photo.fill_from_json(json_photo)
         photos.append(new_photo)
     return photos
Exemple #30
0
    def get_restaurants_by_keyword(name: str = None):
        """
        This method contains the logic to perform the search restaurant by keywords
        The keywords supported are:
        https://stackoverflow.com/questions/3325467/sqlalchemy-equivalent-to-sql-like-statement
        :param name: is the name of restaurants
        """
        if name is None:
            raise Exception("Name is required to make this type of research")
        response = HttpUtils.make_get_request("{}/search/{}".format(
            RESTAURANTS_MICROSERVICE_URL, name))

        rest_list = []
        for json in response["restaurants"]:
            rest = RestaurantModel()
            rest.fill_from_json(json)
            rest_list.append(rest)

        return rest_list