コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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
コード例 #7
0
 def create_user(user_form: UserForm, role_id: int = 3):
     """
     This method contains the logic to create a new user
     :return:
     """
     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))
     password = user_form.password.data
     current_app.logger.debug("New user password {}".format(password))
     date = user_form.dateofbirth.data
     current_app.logger.debug("New user date {}".format(date))
     firstname = user_form.firstname.data
     current_app.logger.debug("New user date {}".format(firstname))
     lastname = user_form.lastname.data
     current_app.logger.debug("New user date {}".format(lastname))
     json_request = {
         "email": email,
         "phone": phone,
         "password": password,
         "dateofbirth": str(date),
         "firstname": firstname,
         "lastname": lastname,
     }
     if role_id == 3:
         url = "{}/create_user".format(USER_MICROSERVICE_URL)
     else:
         url = "{}/create_operator".format(USER_MICROSERVICE_URL)
     response = HttpUtils.make_post_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 False
     current_app.logger.debug("User created and the response was {}".format(
         response[0]))
     return True
コード例 #8
0
    def create_new_restaurant(form: RestaurantForm,
                              user_id: int,
                              max_sit: int,
                              user_email: str = None):
        """
        This method contains all logic save inside the a new restaurant
        :return:
        """
        json_body = {}
        # Menu on restaurants microservices is the cuisine type on the form
        # avg_time is the the how much time the people stay inside the restaurants
        name_rest = form.name.data
        current_app.logger.debug("New rest name is {}".format(name_rest))
        # I'm putting this tries because form.sumbitting in the endpoint does not work
        # so I'm checking here if the field are ok
        try:
            phone_rest = int(form.phone.data)
        except:
            return None
        current_app.logger.debug("Phone is: {}".format(phone_rest))
        covid_measures = form.covid_measures.data
        current_app.logger.debug(
            "Covid Measures is: {}".format(covid_measures))
        if user_email is not None:
            owner_email = user_email
        else:
            owner_email = current_user.email
        current_app.logger.debug("owner_email is {}".format(owner_email))
        try:
            lat_rest = float(form.lat.data)
            lon_rest = float(form.lon.data)
        except Exception as e:
            current_app.logger.error("Wrong lat/ton format\n{}".format(e))
            return None
        current_app.logger.debug("Restaurant position is lat={} lon={}".format(
            lat_rest, lon_rest))
        restaurant_json = {
            "name": name_rest,
            "covid_measures": covid_measures,
            "owner_email": owner_email,
            "phone": phone_rest,
            "lat": lat_rest,
            "lon": lon_rest,
            "rating": 0,
            "avg_time": 30,
        }
        current_app.logger.debug(
            "Restaurants obj is {}".format(restaurant_json))
        json_body["restaurant"] = restaurant_json
        n_table_rest = int(form.n_tables.data)
        current_app.logger.debug("N tables is: {}".format(n_table_rest))
        json_body["restaurant_tables"] = n_table_rest
        opening_json = []

        days = form.open_days.data
        for i in range(len(days)):
            day_json = {}
            week_day = int(days[i])
            current_app.logger.debug("Week day is {}".format(week_day))
            close_dinner = str(form.close_dinner.data)
            current_app.logger.debug("Close dinner {}".format(close_dinner))
            close_lunch = str(form.close_lunch.data)
            current_app.logger.debug("Close lunch  {}".format(close_lunch))
            close_lunch = str(form.close_lunch.data)
            current_app.logger.debug("Close lunch  {}".format(close_lunch))
            open_dinner = str(form.open_dinner.data)
            current_app.logger.debug("Open dinner {}".format(open_dinner))
            open_lunch = str(form.open_lunch.data)
            current_app.logger.debug("Open lunch {}".format(open_lunch))
            day_json["close_dinner"] = close_dinner
            day_json["close_lunch"] = close_lunch
            day_json["open_dinner"] = open_dinner
            day_json["open_lunch"] = open_lunch
            day_json["week_day"] = week_day
            opening_json.append(day_json)
        current_app.logger.debug("Opening day list \n{}".format(opening_json))
        json_body["opening"] = opening_json

        cuisine_type = form.cuisine.data
        current_app.logger.debug(
            "cuisine_type list is \n{}".format(cuisine_type))
        json_body["menu"] = cuisine_type

        url = "{}/create".format(RESTAURANTS_MICROSERVICE_URL)
        restaurant, status_code = HttpUtils.make_post_request(url, json_body)
        restaurant_model = RestaurantModel()
        if restaurant is None:
            return None
        restaurant_model.fill_from_json(restaurant)
        return restaurant_model