def setEmployeePosition():
'''This method is used to store the new position for the employee
Example : POST /api/v1/employeepostions
{"name" : "Cook", "description" : "THis is desription"}
'''
with SessionManager(Session) as session:
try:
name = request.json['name']
description = request.json.get('description', 'NA')
sql_pos = EmployeePosition(name=name, description=description)
session.add(sql_pos)
session.commit()
return jsonify(post_envelop(200, data = request.json))
except DataError: #this excepyion might probably occur if the value key has a value of non integer
return jsonify(error_envelop(400, 'DataError', 'Use the correct value'))
except IntegrityError:
return jsonify(error_envelop(400, 'IntegrityError','Value : {0} already exists'.format(name)))
except:
return jsonify(error_envelop(400, 'UnknownError', 'Error need to be identified'))
评论列表
文章目录