예제 #1
0
def user_updateProfile():
	con = dbConnector.connect()
	params = request.json

	try:
		helpers.check_params(params, ["about", "user", "name"])
		response = user.updateProfile(con=con, about=params["about"], user=params["user"], name=params["name"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": response})
예제 #2
0
def unsubscribe_thread():
	con = dbConnector.connect()

	params = request.json

	try:
		helpers.check_params(params, ["user", "thread"])
		response = thread.unsubscribe(con=con, user=params["user"], thread=params["thread"])
	except Exception, e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
예제 #3
0
def user_unfollow():
	con = dbConnector.connect()
	params = request.json

	try:
		helpers.check_params(params, ["follower", "followee"])
		response = user.unfollow(con=con, follower_email=params["follower"], followee_email=params["followee"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})

	con.close()
	return json.dumps({"code": 0, "response": response})
예제 #4
0
def user_details():

	con = dbConnector.connect()
	params = helpers.json_from_get(request)

	try:
		helpers.check_params(params, ["user"])
		userr = user.details(con, params["user"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	
	con.close()
	return json.dumps({"code": 0, "response": userr})
예제 #5
0
def post_vote():
	con = dbConnector.connect()
	params = request.json
	try:
		helpers.check_params(params, ["post", "vote"])
		response = post.vote(con=con, post=params["post"], vote=params["vote"])
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
예제 #6
0
def post_restore():
	con = dbConnector.connect()
	params = request.json
	try:
		helpers.check_params(params, ["post"])
		response = post.restore_remove(con=con, post=params["post"], isDeleted=0)
		thread.inc_posts(con, params["post"])
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
예제 #7
0
def vote_thread():
	con = dbConnector.connect()
	params = request.json

	try:
		helpers.check_params(params, ["vote", "thread"])
		response = thread.vote(con=con, vote=params["vote"], thread=params["thread"])
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 1,
		"response": response})
예제 #8
0
def user_listFollowers():

	con = dbConnector.connect()

	params = helpers.json_from_get(request)

	optional = helpers.get_optional_params(params, ["limit", "order", "since_id"])

	try:
		helpers.check_params(params, ["user"])
		response = user.listFollowers(con, params["user"], optional)
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": response})
예제 #9
0
def user_listPosts():

	con = dbConnector.connect()

	params = helpers.json_from_get(request)

	optional = helpers.get_optional_params(params, ["limit", "order", "since"])

	try:
		helpers.check_params(params, ["user"])
		response = post.posts_list(con=con, entity="user", params=optional, identifier=params["user"], related=[])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": response})
예제 #10
0
def post_details():
	con = dbConnector.connect()
	params = helpers.json_from_get(request)
	required_data = ["post"]
	related = helpers.related_exists(params)
	try:
		helpers.check_params(params, required_data)
		response = post.details(con, params["post"], related)
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
예제 #11
0
def remove_thread():
	con = dbConnector.connect()

	params = request.json

	try:
		helpers.check_params(params, ["thread"])
		response = thread.restore_remove(con, params["thread"], isDeleted=1)
	except Exception as e:
		con.close()
		return ({
			"code": 1,
			"response": (e.message)})

	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
예제 #12
0
def create_user():

	con = dbConnector.connect()
	params = request.json

	optional = helpers.get_optional_params(params, values=["isAnonymous"])

	try:
		helpers.check_params(params, ["username", "about", "name", "email"])
		userr = user.create(con, params["username"], params["about"], params["name"], params["email"], optional)
	except Exception as e:
		if e.message == "5":
			con.close();
			return json.dumps({"code": 5, "response": (e.message)})
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": userr})
예제 #13
0
def create_thread():
	con = dbConnector.connect();
	params = request.json

	optional = helpers.get_optional_params(params, ["isDeleted"])

	try:
		helpers.check_params(params, ["forum", "title", "isClosed", "user", "date", "message", "slug"])

		response = thread.create(con, params["forum"], params["title"], params["isClosed"], params["user"],
		                         params["date"], params["message"], params["slug"], optional);

	except Exception as e:
		con.close();
		return json.dumps({
			"code": 3,
			"response": (e.message)})

	con.close();
	return json.dumps({
		"code": 0,
		"response": response});
예제 #14
0
def post_create():
	con = dbConnector.connect()

	params = request.json

	optional = helpers.get_optional_params(
		params,
		["parent",
		 "isApproved",
		 "isHighlighted",
		 "isEdited",
		 "isSpam",
		 "isDeleted"]
	)

	try:
		helpers.check_params(
			params,
			["date",
			 "thread",
			 "message",
			 "user",
			 "forum"]
		)

		response = post.create(con, params["date"], params["thread"], params["message"], params["user"],
		                       params["forum"], optional)

	except Exception as e:
		con.close()
		return json.dumps({
			"code": 3,
			"response": (e.message)})

	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
예제 #15
0
def details_thread():
	con = dbConnector.connect()
	params = helpers.json_from_get(request)
	required_data = ["thread"]
	related = helpers.related_exists(params)

	if 'thread' in related:
		con.close()
		return json.dumps({
			"code": 3,
			"response": "error"})
	try:
		helpers.check_params(params, required_data)
		response = thread.details(con, params["thread"], related)
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": response})