def edit_employee_api(id):
    error = context.repository.edit_employee(
        Employee.from_tuple([id] + request.data.decode("utf-8").split(",")))
    if error:
        return error, 418
    context.repository.commit()
    return "", 204
Esempio n. 2
0
 def get_employee_by_id(self, id):
     employee = self.cursor.execute(
         """
             SELECT *
             FROM employees
             WHERE id = ?
         """, (id, )).fetchone()
     if not employee:
         return "Incorrect data"
     return Employee.from_tuple(employee)
def new_employee():
    new_employee_data = Employee.from_tuple(
        tuple([0] + request.data.decode("utf-8").split(",")))
    error = context.repository.add_employee(
        new_employee_data.department_id, new_employee_data.first_name,
        new_employee_data.last_name, new_employee_data.gender,
        new_employee_data.age, new_employee_data.position,
        new_employee_data.salary)
    if error == "DUPLICATE MEMBERS":
        return "Duplicate members", 400
    context.repository.commit()
    return "", 204