Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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