#4
@app.route('/EmployeeSystem/int:id', methods=['PUT'])
def EmployeeSystemPUT(id):
json=request.get_json()
name=json.get('name')
data={'id':id, 'name':name}
dbname='employee_info.db'
conn=sqlite3.connect(dbname)
cur=conn.cursor()
if type(name) is int:
return jsonify({'message': "データの形式が違います"}),400
elif not name:
return jsonify({'message': "データが入力されていません"}),400
else:
cur.execute('update info set name=? where id=?',[name,id])
change=cur.rowcount;
try:
if change>0:
conn.commit()
conn.close()
return jsonify(data),200
elif change==0:
conn.close()
raise IDerror("その社員IDは存在しません")
except IDerror as e:
data={'message':e}
return jsonify(data),404
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme