Exemplo n.º 1
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('post_id')
        parser.add_argument('profile_id')
        args = parser.parse_args()
        try:
            if args['post_id'] == None and args['profile_id'] == None:
                return make_response(jsonify({"status": "Bad Request"}), 400)

            if args['post_id'] != None:
                result = DatabaseConnection.callprocONE(
                    "GetPost", (args['post_id'], ""))
                if (result == None):
                    return make_response(
                        jsonify({"message": "Posts Do not Exist"}), 404)
                return make_response(jsonify({"post": result}), 200)

            if args['profile_id'] != None:
                result = DatabaseConnection.callprocALL(
                    "GetUserPosts", (args['profile_id'], ""))
                if (result == None):
                    return make_response(
                        jsonify({"message": "Posts Do not Exist"}), 404)
                return make_response(jsonify({"posts": result}), 200)
        except:
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
Exemplo n.º 2
0
def GetPopularPosts():
    try:
        result = DatabaseConnection.callprocALL("GetPopularPosts", ())

        if (result == None):
            return make_response(jsonify({"message": "Posts Do not Exist"}),
                                 404)
        return make_response(jsonify({"posts": result}), 200)
    except:
        return make_response(jsonify({"status": "Internal Server Error"}), 500)
Exemplo n.º 3
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('post_id')
        args = parser.parse_args()

        try:
            results = DatabaseConnection.callprocALL("GetComments",
                                                     (args['post_id'], ""))
            return make_response(jsonify({"comments": results}), 200)
        except:
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
Exemplo n.º 4
0
def getStarredPosts():
    try:
        result = Authentication.isAuthenticated()
        profile_id = result['profile_id']
        if (profile_id == None):
            return {"result": {"status", "You are not Logged In"}, "code": 402}

        # Gets a list of starred posts
        result = DatabaseConnection.callprocALL("GetStarredPosts",
                                                (profile_id, ""))

        if (result == None):
            {"result": {"status": "Posts Do not Exist"}, "code": 400}
        return {"result": {"posts": result}, "code": 200}
    except:
        return {"result": {"status": "Internal Server Error"}, "code": 500}
Exemplo n.º 5
0
def GetFollowedPosts():
    try:
        result = Authentication.isAuthenticated()
        profile_id = result['profile_id']
        if (profile_id == None):
            abort(401, "Unauthorised")

        result = DatabaseConnection.callprocALL("GetFollowedPosts",
                                                (profile_id, ""))

        if (result == None):
            return make_response(jsonify({"message": "Posts Do not Exist"}),
                                 404)
        return make_response(jsonify({"posts": result}), 200)
    except:
        return make_response(jsonify({"status": "Internal Server Error"}), 500)
Exemplo n.º 6
0
def GetFollowers():
	parser = reqparse.RequestParser()
	parser.add_argument('profile_id')
	args = parser.parse_args()

	profile_id = args['profile_id']
	try:
		if(profile_id == None):
			# Check Authenticated
			result = Authentication.isAuthenticated()
			if(result == None):
				return make_response(jsonify({"status": "You are not Logged In"}), 401)
			profile_id = result['profile_id']

		results = DatabaseConnection.callprocALL("GetFollowers", (profile_id, ""))
		return make_response(jsonify({"followers":results}), 200)
	except:
		return make_response(jsonify({"status": "Internal Server Error"}), 500)
Exemplo n.º 7
0
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument('post_id')
        parser.add_argument('title')
        parser.add_argument('description')
        parser.add_argument('tags', action='append')
        args = parser.parse_args()
        try:
            # Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                abort(401, "Unauthorised")

            # Update the post
            DatabaseConnection.callprocONE(
                "UpdatePost",
                (args['post_id'], args['title'], args['description']))
            DatabaseConnection.commit()
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)

        # Update the tags
        # First Get a list of the current tags on the post
        # Then get a list of the new tags being put on the post
        # then determine the tags that are new and deleted from the post
        # Then loop through the new tags create tags that dont exist and attach to DB
        # Then loop through deleted tags and remove them from the post
        try:
            # Get all tags from the current post
            result = DatabaseConnection.callprocALL("GetTags",
                                                    (args['post_id'], ""))
            currentTags = []
            for tag in result:
                currentTags.append(tag['id'])

            # Get the new and removed tags from the args list
            newTags = []
            removedTags = []
            for tag in args['tags']:
                try:
                    tag_id = -1
                    # Get tag if it exists
                    result = DatabaseConnection.callprocONE(
                        "GetTagID", (tag, ""))
                    if (result == None):
                        # Tag doesnt exist create it
                        result = DatabaseConnection.callprocONE(
                            "CreateTag", (tag, ""))
                        tag_id = result['LAST_INSERT_ID()']
                    else:
                        # tag exists set tag_id
                        tag_id = result['id']
                    # If tag_id is not currently on the post add it
                    if tag_id not in currentTags:
                        DatabaseConnection.callprocONE(
                            "AddTags", (args['post_id'], tag_id))

                    # Append all tags to the new tags array (it is the new list on the DB)
                    newTags.append(tag_id)
                except:
                    tag_id = -1

            # Loop through the old current tags on the post
            for tag_id in currentTags:
                try:
                    # If the current tag from the before update post does not exist in new tags remove it from the post
                    if tag_id not in newTags:
                        DatabaseConnection.callprocONE(
                            "DeleteTags", (args['post_id'], tag_id))

                except:
                    tag_id = -1

            DatabaseConnection.commit()
            return redirect(settings.APP_HOST + ":" + str(settings.APP_PORT) +
                            "/post?post_id=" + str(args['post_id']),
                            code=302)
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)