def put(self, name): """Todo convert the json data to python format""" """Todo search the book if exists update it else not found 404""" data = request.get_json() employee = EmployeeModel.query.filter_by(name=name).first() if employee: employee.employee_id = data['employee_id'] employee.name = data['name'] employee.age = data['age'] employee.position = data['position'] else: employee = EmployeeModel(name=name, **data) # hit on data base using database class method employee.create() return employee.json()
def post(self): """Todo user send data and convert this data as Json and then this json format data converted into python native code and then after solving specific task this will return as a Json again. """ # get json from user or from api. data = request.get_json() # print("dattttttttttttttttttttta",data) new_employee = EmployeeModel(employee_id=data['employee_id'], name=data['name'], age=data['age'], position=data['position']) new_employee.create() # again python readable code to json return new_employee.json(), 201