Esempio n. 1
0
 def get(self):
     return (
         {
             "success": True,
             "employees":
             [Employee.json(emp) for emp in Employee.find_all()],
         },
         200,
     )
Esempio n. 2
0
    def get_all_records(self):
        sql = "SELECT * FROM employees"
        cursor = connection.cursor()
        cursor.execute(sql)
        records = cursor.fetchall()

        employee_list = []
        for record in records:
            employee = Employee(record[0])
            employee_list.append(employee.json())

        return employee_list
Esempio n. 3
0
 def post(self):
     body = request.get_json()
     hased_password = Employee.hash_password(body["password"])
     emp = Employee(
         body["name"],
         body["age"],
         body["email"],
         hased_password,
         body["phone"],
         datetime.strptime(body["hire_date"], r"%Y/%m/%d"),
     )
     try:
         emp.save()
     except Exception as e:
         return {"msg": "Something went wrong", "description": e}, 500
     if emp.json()["id"] != None:
         return {
             "msg": "New Employee created.",
             "created_employee": emp.json()
         }, 201
     return {"msg": "Something went wrong"}, 500
Esempio n. 4
0
 def all_employee(self):  # Retrieve all employees from employee and return
     sql = "SELECT * FROM employee"
     cursor = connection.cursor()
     cursor.execute(sql)
     records = cursor.fetchall()
     emp_list = []
     for record in records:
         employee = Employee(record[0], record[1], record[2], record[3],
                             record[4], record[5], record[6], record[7],
                             record[8], record[9])
         emp_list.append(employee.json())
     return emp_list
    def all_employees(self):
        sql = "SELECT * FROM employees"
        cursor = connection.cursor()
        cursor.execute(sql)
        records = cursor.fetchall()
        log(f"Viewing employees")
        employee_list = []

        for record in records:
            employee = Employee(record[0], record[1], record[2], record[3],
                                record[4], record[5], record[6])

            employee_list.append(employee.json())

        return employee_list