diff --git a/code/dbapi.py b/code/dbapi.py index c296a7f..9df1733 100644 --- a/code/dbapi.py +++ b/code/dbapi.py @@ -633,5 +633,32 @@ def setCreditByEventIdAndUserName(self,eid,username,credit): return {"errorCode":200,"errorDesc":""} #07/10 + + #add relation from temprelation or not + # lin 7/21 + def addrelation(self,uid,cid,condition,kind): + cursor = self.db.cursor(cursorclass=MySQLdb.cursors.DictCursor) + if(condition!="yes"): + sql="delete from temprelation where uid=%s and cid=%s" + param=(uid,cid) + cursor.execute(sql,param) + self.db.commit() + data=[{'state':0},{'dec':"the cid not accept the request"}]#not accept the request return 0 + result=json.dumps(data) + return result + else: + sql="insert relation(usrid,cid,kind)value(%s,%s,%s)" + param=(uid,cid,kind) + cursor.execute(sql,param) + sql="delete from temprelation where uid=%s and cid=%s" + param=(uid,cid) + cursor.execute(sql,param) + self.db.commit() + data=[{'state':1},{'dec':"add relation success"}]#add relation success return state 1 + result=json.dumps(data) + return result + cursor.close() + + def __del__(self): self.db.close() diff --git a/code/handler/AddtemprelationHandler.py b/code/handler/AddtemprelationHandler.py new file mode 100644 index 0000000..dcc7e14 --- /dev/null +++ b/code/handler/AddtemprelationHandler.py @@ -0,0 +1,15 @@ +import tornado.ioloop +import tornado.web +import tornado.httpserver +import json + +class AddtemprelationHandler(tornado.web.RequestHandler): + def get(self): + self.write("

AddtemprelationHandler

") + + def post(self): + content='{"uid":1,"cid":2,"kind":1,"condition":"yes"}' + j=json.loads(content) + result=self.application.dbapi.addrelation(j['uid'],j['cid'],j['condition'],j['kind']) + print result + \ No newline at end of file diff --git a/code/handler/__init__.py b/code/handler/__init__.py index 1aecfa3..708bb43 100644 --- a/code/handler/__init__.py +++ b/code/handler/__init__.py @@ -19,4 +19,5 @@ "UpdateUserInfoHandler", "startFollowHandler", "cancelFollowHandler", - "GetArroundEvent"] + "GetArroundEvent", + "AddtemprelationHandler"] diff --git a/code/main.py b/code/main.py index ec0c974..b17becf 100644 --- a/code/main.py +++ b/code/main.py @@ -37,7 +37,8 @@ def __init__(self): (r"/api/updateuserinfo",UpdateUserInfoHandler.UpdateUserInfoHandler), (r"/api/getAround",GetArroundEvent.GetArroundEvent), (r"/api/startfollow",startFollowHandler.startFollowHandler), - (r"/api/cancelfollow",cancelFollowHandler.cancelFollowHandler)] + (r"/api/cancelfollow",cancelFollowHandler.cancelFollowHandler), + (r"/api/addtemprelation",AddtemprelationHandler.AddtemprelationHandler)] tornado.web.Application.__init__(self,handlers,**settings) self.dbapi=dbapi.dbapi() self.util=util.util()