Exemple #1
0
    def updateAdmin(self, admin_id, json):
        dao_admin = AdminDAO()
        if not dao_admin.getAdminById(admin_id):
            return jsonify(Error="Admin not found."), 404
        else:
            admin_firstname = json['admin_firstname']
            admin_lastname = json['admin_lastname']
            admin_date_birth = json['admin_date_birth']
            admin_email = json['admin_email']
            admin_phone = json['admin_phone']
            admin_phone_id = json["admin_phone_id"]

            if admin_firstname and admin_lastname and admin_date_birth and admin_email and admin_phone and admin_phone_id:
                user_id = dao_admin.update(admin_id)
                dao_user = UserDAO()
                dao_user.update(user_id, admin_firstname, admin_lastname,
                                admin_date_birth, admin_email)
                dao_phone = UserPhoneDAO()
                dao_phone.update(user_id, admin_phone)
                result = self.build_admin_attributes(
                    user_id, admin_id, admin_firstname, admin_lastname,
                    admin_date_birth, admin_email, admin_phone_id, admin_phone)
                return jsonify(Admin=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400
Exemple #2
0
    def updateCustomer(self, customer_id, json):
        customer_dao = CustomerDAO()
        if not customer_dao.getCustomerById(customer_id):
            return jsonify(Error="Customer not found."), 404
        else:
            customer_firstname = json["customer_firstname"]
            customer_lastname = json["customer_lastname"]
            customer_date_birth = json["customer_date_birth"]
            customer_email = json["customer_email"]
            customer_phone = json["customer_phone"]
            customer_phone_id = json["customer_phone_id"]

            if customer_firstname and customer_lastname and customer_date_birth and customer_email and customer_phone_id and customer_phone:
                user_id = customer_dao.update(customer_id)
                user_dao = UserDAO()
                user_dao.update(user_id, customer_firstname, customer_lastname,
                                customer_date_birth, customer_email)
                dao_phone = UserPhoneDAO()
                dao_phone.update(user_id, customer_phone)
                result = self.build_customer_attributes(
                    customer_id, user_id, customer_firstname,
                    customer_lastname, customer_date_birth, customer_email,
                    customer_phone_id, customer_phone)
                return jsonify(Customer=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400
Exemple #3
0
 def deleteCustomer(self, customer_id):
     customer_dao = CustomerDAO()
     if not customer_dao.getCustomerById(customer_id):
         return jsonify(Error="Customer not found."), 404
     else:
         user_id = customer_dao.delete(customer_id)
         dao_phone = UserPhoneDAO()
         dao_phone.delete(user_id)
         user_dao = UserDAO()
         user_dao.delete(user_id)
         return jsonify(DeleteStatus="OK"), 200
Exemple #4
0
 def deleteAdmin(self, admin_id):
     dao_admin = AdminDAO()
     if not dao_admin.getAdminById(admin_id):
         return jsonify(Error="Admin not found."), 404
     else:
         dao_user = UserDAO()
         dao_phone = UserPhoneDAO()
         user_id = dao_admin.delete(admin_id)
         dao_phone.delete(user_id)
         dao_user.delete(user_id)
         return jsonify(DeleteStatus="OK"), 200
Exemple #5
0
 def deleteSupplier(self, supplier_id):
     supplier_dao = SupplierDAO()
 
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error = "Supplier not found."), 404
     else:
         user_id = supplier_dao.delete(supplier_id)
         dao_phone = UserPhoneDAO()
         dao_phone.delete(user_id)
         user_dao = UserDAO()
         user_dao.delete(user_id)
         return jsonify(DeleteStatus = "OK"), 200
Exemple #6
0
    def insertSupplier(self, json):
        supplier_firstname = json['supplier_firstname']
        supplier_lastname = json['supplier_lastname']
        supplier_date_birth = json['supplier_date_birth']
        supplier_email = json['supplier_email']
        supplier_phone = json['supplier_phone']

        if supplier_firstname and supplier_lastname and supplier_date_birth and supplier_email and supplier_phone:
            dao_user = UserDAO()
            user_id = dao_user.insert(supplier_firstname, supplier_lastname, supplier_date_birth, supplier_email)
            dao_phone = UserPhoneDAO()
            supplier_phone_id = dao_phone.insert(user_id, supplier_phone)
            dao_supplier = SupplierDAO()
            supplier_id = dao_supplier.insert(user_id)
            result = self.build_supplier_attributes(user_id, supplier_id, supplier_firstname, supplier_lastname, supplier_date_birth, supplier_email, supplier_phone_id, supplier_phone)
            return jsonify(Supplier = result), 201
        else:
            return jsonify(Error = "Unexpected attributes in post request"), 400
Exemple #7
0
    def insertCustomer(self, json):
        customer_firstname = json['customer_firstname']
        customer_lastname = json['customer_lastname']
        customer_date_birth = json['customer_date_birth']
        customer_email = json['customer_email']
        customer_phone = json['customer_phone']

        if customer_firstname and customer_lastname and customer_date_birth and customer_email and customer_phone:
            user_dao = UserDAO()
            user_id = user_dao.insert(customer_firstname, customer_lastname,
                                      customer_date_birth, customer_email)
            dao_phone = UserPhoneDAO()
            customer_phone_id = dao_phone.insert(user_id, customer_phone)
            customer_dao = CustomerDAO()
            customer_id = customer_dao.insert(user_id)
            result = self.build_customer_attributes(
                customer_id, user_id, customer_firstname, customer_lastname,
                customer_date_birth, customer_email, customer_phone_id,
                customer_phone)
            return jsonify(Customer=result), 201
        else:
            return jsonify(Error="Unexpected attributes in post request"), 400
Exemple #8
0
    def updateSupplier(self, supplier_id, json):
        dao_supplier = SupplierDAO()
        dao_user = UserDAO()
        if not dao_supplier.getSupplierById(supplier_id):
            return jsonify(Error = "Supplier not found."), 404
        else:
            supplier_firstname = json['supplier_firstname']
            supplier_lastname = json['supplier_lastname']
            supplier_date_birth = json['supplier_date_birth']
            supplier_email = json['supplier_email']
            supplier_phone = json['supplier_phone']
            supplier_phone_id = json["supplier_phone_id"]

            if supplier_firstname and supplier_lastname and supplier_date_birth and supplier_email and supplier_phone and supplier_phone_id:
                user_id = dao_supplier.update(supplier_id)
                dao_user.update(user_id, supplier_firstname, supplier_lastname, supplier_date_birth, supplier_email)
                dao_phone = UserPhoneDAO()
                dao_phone.update(user_id, supplier_phone) 
                result = self.build_supplier_attributes(user_id, supplier_id, supplier_firstname, supplier_lastname, supplier_date_birth, supplier_email, supplier_phone_id, supplier_phone)
                return jsonify(Supplier = result), 200
            else:
                return jsonify(Error = "Unexpected attributes in update request"), 400
Exemple #9
0
    def insertAdmin(self, json):
        admin_firstname = json['admin_firstname']
        admin_lastname = json['admin_lastname']
        admin_date_birth = json['admin_date_birth']
        admin_email = json['admin_email']
        admin_phone = json['admin_phone']

        if admin_firstname and admin_lastname and admin_date_birth and admin_email and admin_phone:
            dao_user = UserDAO()
            user_id = dao_user.insert(admin_firstname, admin_lastname,
                                      admin_date_birth, admin_email)
            dao_phone = UserPhoneDAO()
            admin_phone_id = dao_phone.insert(user_id, admin_phone)
            dao_admin = AdminDAO()
            admin_id = dao_admin.insert(user_id)
            result = self.build_admin_attributes(user_id, admin_id,
                                                 admin_firstname,
                                                 admin_lastname,
                                                 admin_date_birth, admin_email,
                                                 admin_phone_id, admin_phone)
            return jsonify(Admin=result), 201
        else:
            return jsonify(Error="Unexpected attributes in post request"), 400