def insert_customer(self, customer):

        customer_dao = CustomerDAO()
        user_dao = UserDAO()
        location_dao = LocationDAO()
        cc_dao = CreditCardDAO()

        try:
            customer_first_name = customer["customer_first_name"]
            customer_last_name = customer["customer_last_name"]
            customer_city = customer["customer_city"]
            customer_address = customer["customer_address"]
            latitude = customer["latitude"]
            longitude = customer["longitude"]
            username = customer["username"]
            password = customer["password"]
            phone = customer["phone"]

        except KeyError:
            ErrorHandler().bad_request()

        user_id = user_dao.insert_user(username, password, phone)
        location_id = location_dao.insert_location(latitude, longitude)
        customer_id = customer_dao.insert_customer(
            customer_first_name,
            customer_last_name,
            customer_city,
            location_id,
            user_id,
            customer_address,
        )

        return (
            self.build_customer_user((
                customer_id,
                customer_first_name,
                customer_last_name,
                customer_city,
                location_id,
                user_id,
            )),
            201,
        )
Exemplo n.º 2
0
    def insert_admin(self, admin):
        admin_dao = AdminDAO()
        user_dao = UserDAO()

        try:
            admin_name = admin["admin_name"]
            username = admin["username"]
            password = admin["password"]
            phone_number = admin["phone_number"]
        except KeyError:
            ErrorHandler().bad_request()

        user_id = user_dao.insert_user(username, password, phone_number)
        admin_id = admin_dao.insert_admin(admin_name, user_id)

        return (
            self.build_admin_dict((
                admin_id,
                admin_name,
                user_id,
            )),
            201,
        )
    def insert_user(self, form):

        user_dao = UserDAO()

        try:
            username = form["username"]
            password = form["password"]
            phone_number = form["phone_number"]
        except KeyError:
            return ErrorHandler().bad_request()

        user_id = user_dao.insert_user(username, password, phone_number,)

        return (self.build_user_dict(
                    (
                        user_id,
                        username,
                        password,
                        phone_number
                    )
            ),
            201,
        )
    def updated_user(self, user_id, user):
        if not self.get_user_by_id(user_id):
            return ErrorHandler().not_found()
        try:
            username = user["username"]
            password = user["password"]
            phone_number = user["phone_number"]
        except KeyError:
            ErrorHandler().bad_request()

            if username and password and phone_number:
                user_id = UserDAO().update_user(username, password, phone_number)
                return (self.build_user_dict((username, password, phone_number)), 200)
            else:
                return ErrorHandler().bad_request()
        else:
            return ErrorHandler().bad_request()
 def delete_user(self, user_id):
     if not self.get_user_by_id(user_id):
         return ErrorHandler().not_found()
     else:
         UserDAO().delete_user(user_id)
         return jsonify(Deletion="OK"), 200
 def get_user_by_id(self, user_id):
     result = UserDAO().get_user_by_id(user_id)
     if not result:
         return ErrorHandler().not_found()
     else:
         return jsonify(user=result), 200
 def get_all_users(self):
     result = UserDAO().get_all_users()
     return jsonify(users=result), 200