示例#1
0
def deletePost(post_id):
    post = dao.getPost(post_id)
    if post is None:
        return failure_response("Post was not found!")
    post = dao.deletePost(post_id)
    if post is None:
        return failure_response("The server was not able to delete this post!")
    return success_response(post, 200)
示例#2
0
def addTags(post_id):
    body = json.loads(request.data)
    tags = body.get("tags") # array of strings
    post = dao.getPost(post_id)
    if post is None:
        return failure_response("Post cannot be found!") 
    post = dao.updateTags(post_id, tags=tags)
    if post is None:
        return failure_response("Tags could not be updated!")
    return success_response(post)
示例#3
0
def rateOverall(post_id):
    body = json.loads(request.data)
    
    score = body.get("score")
    if score < 0 or score > 5:
        return failure_response("The score must be in between 0 and 5!")

    if dao.getPost(post_id) is None:
        return failure_response("That post was not found!")

    user_id = body.get("user_id")
    if user_id is None or score is None:
        return failure_response("No user_id or score provided!")

    rating = dao.rateOverall(user_id=user_id, post_id=post_id, score=score)
    if rating is None:
        return failure_response("Post was not able to be rated!")
    return success_response(rating, 200)
示例#4
0
def getOverallRating(post_id):
    post = dao.getPost(post_id)
    if post is None:
        return failure_response("That post was not found!")
    return dao.getOverallRating(post_id)
示例#5
0
def getPost(post_id):
    post = dao.getPost(post_id)
    if post is None:
        return failure_response("Post does not exist!")
    return success_response(post, 200)