def setPayment():
'''This function is used to store the new payment in the database
Example : POST /api/v1/payments HTTP/1.1
{ "p_type": " onsite"}
Result : {
"meta": {
"code": 200,
"message": "Created Successfully"
}
}
'''
with SessionManager(Session) as session:
try:
p_type = request.json['p_type']
payment = Payment(p_type=p_type)
session.add(payment)
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(p_type)))
except:
return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
评论列表
文章目录