revome gameid from localtion

This commit is contained in:
pengtao 2019-07-16 19:53:23 +08:00
parent 0ea06034d1
commit 60662e2081

View File

@ -10,7 +10,7 @@ from config import mysql_promotion_config
import pdb
log = logging.getLogger(__name__)
mydb = MysqlBase(**mysql_promotion_config)
parser = reqparse.RequestParser()
parser.add_argument('id')
parser.add_argument('area')
@ -21,18 +21,18 @@ parser.add_argument('in_used')
class Location(Resource):
def __init__(self):
self.args = parser.parse_args()
self.mydb = MysqlBase(**mysql_promotion_config)
def get(self):
sql = f"select id,area,type from location where in_used=1;"
try:
data = mydb.query(sql)
data = self.mydb.query(sql)
except Exception:
log.error("get data from location failed!", exc_info=True)
return jsonify({'code': 500})
all_data = []
log.debug(f"get data from localtion was {data}")
pdb.set_trace()
if data:
for line in data:
if line:
@ -52,7 +52,7 @@ class Location(Resource):
location['area'] = self.args['area']
location['type'] = self.args['type']
location['id'] = self.create_id()
mydb.insert("location", location)
self.mydb.insert("location", location)
except Exception:
log.error("set values to location mysql failed!", exc_info=True)
return jsonify({'code': 500})
@ -61,7 +61,7 @@ class Location(Resource):
def create_id(self):
max_id = f"select id from location order by id desc limit 1"
data = mydb.query(max_id)
data = self.mydb.query(max_id)
log.info(f"2 {data}")
try:
max = int(data[0][0]) + 1
@ -80,10 +80,10 @@ class Location(Resource):
location['type'] = self.args['type']
location['in_used'] = self.args['in_used'] or 0
sel_sql = f"select area from location where id={self.args['id']};"
data = mydb.query(sel_sql)
data = self.mydb.query(sel_sql)
if data:
condition = f"id='{self.args['id']}'"
mydb.update("location", location, condition)
self.mydb.update("location", location, condition)
return jsonify({'code': 200})
else:
return jsonify({'code': 404, 'message': f"{self.args['id']} not found in mysql!"})
@ -98,7 +98,7 @@ class Location(Resource):
return jsonify({'code': 500, 'message': 'id not found'})
try:
del_sql = f'delete from location where id={id};'
mydb.query(del_sql)
self.mydb.query(del_sql)
except Exception:
log.error(f"location remove {id} failed!", exc_info=True)
return jsonify({'code': 500})