Ejemplo n.º 1
0
 def del_employee(employee_id):
     try:
         ret = EmployeeService.get_employee_by_id(int(employee_id))
         if ret is None:
             log(f"Failed to find and delete employee")
             return 'Employee not found', 404
         log(f"Deleted employee with employee id={employee_id}")
         EmployeeService.delete_employee(int(employee_id))
         return 'Employee Deleted', 205
     except ResourceNotFound:
         return 'employee id not found', 404
     except ValueError:
         return 'Invalid Input', 201
class EmployeeInfoByName(AbstractCommand):
    def __init__(self):
        self.employeeService = EmployeeService()

    def execute(self, empName: str):
        #print("emp name"+empName)
        return self.employeeService.getEmployeeByName(empName)
Ejemplo n.º 3
0
 def post_employee():
     try:
         log(f"Creating new employee")
         employee = Employee.json_parse(request.json)
         employee = EmployeeService.create_employee(employee)
         return jsonify(employee.json()), 201
     except ValueError:
         return 'Invalid input', 400
 def post_employee():
     try:
         employee = Employee.json_parse(request.json)
         employee = EmployeeService.add_employee(employee)
         return jsonify(employee.json()), 201
     except KeyError:
         return "Please enter a username.", 400
     except ResourceNotFound as r:
         return r.message, 404
Ejemplo n.º 5
0
 def put_employee(employee_id):
     try:
         log(f"Updating employee info for employee id={employee_id}")
         employee = Employee.json_parse(request.json)
         employee.employee_id = int(employee_id)
         employee = EmployeeService.update_employee(employee)
         return jsonify(employee.json()), 200
     except ResourceNotFound:
         return 'employee id not found', 404
     except ValueError:
         return 'Invalid Input', 201
Ejemplo n.º 6
0
 def get_employee(employee_id):
     try:
         employee = EmployeeService.get_employee_by_id(int(employee_id))
         if employee is None:
             log(f"get error for employee id={employee_id}")
             return 'No employee found', 404
         log(f"Used get request for employee id={employee_id}")
         return jsonify(employee.json()), 200
     except ValueError as e:
         return "Not a valid ID", 400  # Bad Request
     except ResourceNotFound as r:
         return r.message, 404
Ejemplo n.º 7
0
    def post(self):
        arg = self.get_argument_dict(must_keys=[
            "id", "name", "avatar", "title1", "title2", "production"
        ])

        result = EmployeeService().update_employee(
            employee_id=arg.get("id"),
            name=arg.get("name"),
            avatar=arg.get("avatar"),
            title1=arg.get("title1"),
            title2=arg.get("title2"),
            production=arg.get("production"))
        return {"code": 0, "msg": "success", "data": result}
Ejemplo n.º 8
0
 def get_employee_request_with_id(employee_id, request_id):
     try:
         if employee_id.isdigit() and request_id.isdigit():
             employee = EmployeeService.get_employee_by_id(employee_id=employee_id)
             ret = [request.json() for request in
                    RequestDAOImpl.get_request_with_id(int(employee_id), int(request_id))]
             print("ret is:")
             print(ret)
             if not ret:
                 log(f"Could not find request for employee id={employee_id}")
                 return "Not a valid request", 404
         log(f"Viewing request for employee id={employee_id} with request id={request_id}")
         return jsonify(RequestServiceImpl.get_request_with_id(int(employee_id), int(request_id)))
     except ValueError:
         return "no employee exists", 404
Ejemplo n.º 9
0
 def post_authentication_employee():
     try:
         print("here")
         employee = Employee.json_parse(request.json)
         print(f"name: {employee.name} title: {employee.title}")
         employee = EmployeeService.employee_authentication(employee)
         # before returning any data after an employee is verified
         # need to check if any pending process have taken too long
         # I decided each manager gets five day to approve or deny
         # if it is day five and the requester still needs to add info
         # The claim could be auto-rejected and if the manager requests
         # addition information on the fifth day I could add one day
         return jsonify(employee.json()), 202  # accepted
     except ResourceNotFound as r:
         return r.message, 404
Ejemplo n.º 10
0
    def get(self):
        employees_list = EmployeeService().employees()

        result_list = []
        for employee in employees_list:
            result = {
                "id": employee.id,
                "created_at": str(employee.created_at),
                "name": employee.name,
                "avatar": employee.avatar,
                "title1": employee.title1,
                "title2": employee.title2,
                "production": employee.production,
            }
            result_list.append(result)

        return {"code": 0, "msg": "success", "data": result_list}
Ejemplo n.º 11
0
    def post(self):
        self.get_argument_dict(must_keys=["user_id"])
        employees_list = EmployeeService().employees()

        result_list = []
        for employee in employees_list:
            result = {
                "id": employee.id,
                "created_at": str(employee.created_at),
                "name": employee.name,
                "avatar": employee.avatar,
                "title1": employee.title1,
                "title2": employee.title2,
                "production": employee.production,
            }
            result_list.append(result)

        return {"code": 0, "msg": "success", "data": result_list}
Ejemplo n.º 12
0
    def create_employee_request(employee_id, employee_name, request_for, req_funds, req_type, info, pass_grade,
                                event_date, submit_date):
        try:
            # req_funds = request.json["req_funds"]
            if employee_id.isdigit() and req_funds == int or float:
                employee = EmployeeService.get_employee_by_id(employee_id=int(employee_id))
                if employee == "Not a valid ID":
                    return "No such employee exist", 404
                log(f"Creating request for employee id={employee_id}")
                return jsonify(RequestServiceImpl.create_request(employee_id=employee_id, employee_name=employee_name,
                                                                 request_for=request_for, req_funds=req_funds,
                                                                 req_type=req_type, info=info, pass_grade=pass_grade,
                                                                 event_date=event_date, submit_date=submit_date)), 201
            else:
                raise ValueError

        except ValueError:
            return "No such employee exist", 404
 def __init__(self):
     self.employeeService = EmployeeService()
Ejemplo n.º 14
0
 def get_all_employees():
     log(f"Indexing all employees")
     return jsonify(EmployeeService.all_employees()), 200
class DomainInfoByName(AbstractCommand):
    def __init__(self):
        self.employeeService = EmployeeService()

    def execute(self, empName: str):
        return self.employeeService.getDomainByName(empName)
Ejemplo n.º 16
0
 def get_employee(username):
     try:
         employee = EmployeeService.get_employee(username)
         return jsonify(employee.json()), 200
     except ResourceNotFound as r:
         return r.message, 404
Ejemplo n.º 17
0
 def delete_employee(username):
     try:
         return EmployeeService.delete_employee(username)
     except KeyError:
         return "No Employee found by that username.", 400
 def login():
     login_id = request.json["loginId"]
     return jsonify(EmployeeService.login(login_id).serialize())
Ejemplo n.º 19
0
 def get_all_employees():
     return jsonify(EmployeeService.get_all_employees())
async def create_employee(
    payload: CreateEmployee,
    db: Session = Depends(get_db),
    current_user: UserOut = Depends(get_current_active_user)):
    return EmployeeService.create_employee(data=payload, db=db)
Ejemplo n.º 21
0
class NameInfoByDomain(AbstractCommand):
    def __init__(self):
        self.employeeService = EmployeeService()

    def execute(self, DomainName: str):
        return self.employeeService.getNameByDomain(DomainName)
async def employee_by_id(
    employee_id: int,
    db: Session = Depends(get_db),
    current_user: UserOut = Depends(get_current_active_user)):
    return EmployeeService.read_employee_byID(employee_id=employee_id, db=db)
async def get_employees(
        db: Session = Depends(get_db),
        current_user: UserOut = Depends(get_current_active_user)):
    return EmployeeService.read_employees(db=db)
Ejemplo n.º 24
0
 def post(self):
     arg = self.get_argument_dict(must_keys=["id"])
     result = EmployeeService().remove_employee(employee_id=arg.get("id"))
     return {"code": 0, "msg": "success", "data": result}
Ejemplo n.º 25
0
class EmployeeInfoById(AbstractCommand):
    def __init__(self):
        self.employeeService = EmployeeService()

    def execute(self, empId: int):
        return self.employeeService.getEmployeeById(empId)
Ejemplo n.º 26
0
class GetEmployeesList(AbstractCommand):
    def __init__(self):
        self.employeeService = EmployeeService()

    def execute(self):
        return self.employeeService.getEmployees()