I have a working SQL stored procedure and have flask-sqlAlchemy set up in Python and connected to my MySQL database. I'm trying to build a simple API that will take in 6-7 request parameters entered via URL request and send these to my call procedure and update the database accordingly based on the stored procedure which inserts a new record in the DB table (the sp is 'add_spotting' below).
I am trying to do this via a POST method and believe I'm taking in the request argument parameters correctly and calling the procedure but I'm not sure how to execute those procedures and actually inject to the DB.
class Spotting(mysql.Model):
__tablename__ = 'spotting'
spotting_id = mysql.Column(mysql.Integer, primary_key = True)
animal_id = mysql.Column(mysql.Integer, mysql.ForeignKey('animal.animal_id'), nullable=False)
user_id = mysql.Column(mysql.Integer, mysql.ForeignKey('user.user_id'), nullable=False)
trail_id = mysql.Column(mysql.Integer, mysql.ForeignKey('trail.trail_id'), nullable=False)
quantity = mysql.Column(mysql.Integer, nullable = False)
lat = mysql.Column(mysql.Float, nullable=True)
lon = mysql.Column(mysql.Float, nullable=True)
description = mysql.Column(mysql.String(250), nullable=False)
#Post method
@application.route('/spotting', methods=['POST'])
def postSpotting():
animal = request.args.get('animal')
user = request.args.get('user')
trail = request.args.get('trail')
quantity = request.args.get('quantity')
lat = request.args.get('lat')
lon = request.args.get('lon')
desc = request.args.get('desc')
proc_call = "call add_spotting('" + animal + "','"+ user + "','" + trail + \
"','" + quantity + "','" + lat + "','" + lon + "','" + desc + "')"
mysql.engine.execute(proc_call)
### Here I want to post and commit this to the MySQL DB via the stored proc and return a message such as
# ## 'Spotting successfully added'
return ("Successfully posted!")