def post(self):
     try:
         token = request.cookies.get('access_token')
         log.info(token)
         if utils.JWTdecode(token) == False:
             return redirect("/login", code=302)
         input_data = json.loads(request.data)
         log.info(input_data)
         univerList = dao_university.Database().getUniversity(input_data)
         if len(univerList) > 0:
             return {
                 "status": 400,
                 "message":
                 "新增失敗,學校 [ " + input_data.get('u_name') + " ] 已存在"
             }, 200
         result = dao_university.Database().addUniversity(input_data)
         if result:
             data = dao_university.Database().getUniversity(None)
             return {"data": data, "status": 200, "message": "success"}, 200
     except Exception as e:
         log.error("AddUniversity error: " + utils.except_raise(e))
         return {
             "status": 400,
             "message": "insert error: {}".format(e)
         }, 200
Exemplo n.º 2
0
 def post(self):
     try:
         input_data = json.loads(request.data)
         log.info(input_data)
         univerList = dao_university.Database().getUniversity(input_data)
         if len(univerList) > 0:
             return {"status":400, "message":"新增失敗,學校 [ "+input_data.get('u_name')+" ] 已存在"},200
         result = dao_university.Database().addUniversity(input_data)
         if result:
             data = dao_university.Database().getUniversity(None)
             return {"data":data, "status": 200, "message":"success"}, 200
     except Exception as e:
         log.error("AddUniversity error: "+utils.except_raise(e))
         return {"status":400, "message":"insert error: {}".format(e)}, 200
Exemplo n.º 3
0
 def post(self):
     try:
         input_data = json.loads(request.data)
         log.info(input_data)
         univerList = dao_university.Database().getUniversity(input_data)
         if len(univerList) < 1:
             return {"status":400, "message":"更新失敗,學校 [ "+input_data.get('u_name')+" ] 不存在"},200
         result = dao_university.Database().editUniversity(input_data)
         log.info('edit result:' + str(result))
         if result:
             data = dao_university.Database().getUniversity(input_data)
             log.info(data)
             return {"data":data, "status": 200, "message":"success"}, 200
     except Exception as e:
         log.error("EditUniversity error: "+utils.except_raise(e))
         return {"status":400, "message":"edit error: {}".format(e)}, 200
Exemplo n.º 4
0
 def post(self):
     try:
         data = {}
         if request.data :
             input_data = json.loads(request.data)
             if input_data.get("u_id"):
                 log.info(input_data)
                 data = dao_university.Database().getUniversity(input_data)
         else:
             data = dao_university.Database().getUniversity(None)
         log.info(data)
         # return {"data":data},200
         return {"data":data, "status": 200, "message":"success"}, 200
     except Exception as e:
         log.error("GetUniversity error: "+utils.except_raise(e))
         return {"status":400, "message":"get data error: {}".format(e)}, 200
Exemplo n.º 5
0
 def post(self):
     try:
         input_data = json.loads(request.data)
         log.info(input_data)
         data = dao_university.Database().delUniversity(input_data)
         log.info(data)
         if data:
             return {"status": 200, "message":"success"}, 200
         else:
             return {"status": 401, "message":"delete fail"}, 401
     except Exception as e:
         log.error("DelUniversity error: "+utils.except_raise(e))
         return {"status":400, "message":"delete error: {}".format(e)}, 200
 def post(self):
     try:
         token = request.cookies.get('access_token')
         log.info(token)
         if utils.JWTdecode(token) == False:
             return redirect("/login", code=302)
         input_data = json.loads(request.data)
         log.info(input_data)
         data = dao_university.Database().delUniversity(input_data)
         log.info(data)
         if data:
             return {"status": 200, "message": "success"}, 200
         else:
             return {"status": 401, "message": "delete fail"}, 401
     except Exception as e:
         log.error("DelUniversity error: " + utils.except_raise(e))
         return {
             "status": 400,
             "message": "delete error: {}".format(e)
         }, 200