def new_like(): """ (PUT: like) Instantiates a new <<CheckpointLike>> from a user on a <<UserCheckpoint>> """ #req var user_id = request.form.get("user_id") signature = request.form.get("signature") user_checkpoint_id = request.form.get("user_checkpoint_id") #generated var verb = "put" noun = "like" user = get_user(user_id) user_checkpoint = get_user_checkpoint(user_checkpoint_id) access_token = user.access_token #authorization check if not is_api_key_validated(access_token, user_id, signature, verb, noun): return authorization_fail() like = add_like(user, user_checkpoint) return jsonify({ "status": "ok", "result": { "like_id": like.id, } })
def delete_like(): """ (DELETE: like) Deletes an existing <<CheckpointLike>> between a user and a <<UserCheckpoint>> if it exists """ #req var user_id = request.args.get("user_id") signature = request.args.get("signature") user_checkpoint_id = request.args.get("user_checkpoint_id") #generated var verb = "delete" noun = "like" user = get_user(user_id) user_checkpoint = get_user_checkpoint(user_checkpoint_id) access_token = user.access_token #authorization check if not is_api_key_validated(access_token, user_id, signature, verb, noun): return authorization_fail() delete_like_action(user, user_checkpoint) return jsonify({ "status": "ok", })
def _checkpoint_details(): """ Gets detailed information about a (User)Checkpoint given its id. """ CheckpointDetail = namedtuple("CheckpointDetail", ("user_checkpoint_obj", "total_likes", "total_shares", "current_user_like", "comments", "user", )) user_id = request.args.get("user_id") user_checkpoint_id = request.args.get("user_checkpoint_id") user_obj = get_user(user_id) user_checkpoint_obj = get_user_checkpoint(user_checkpoint_id) total_likes = get_total_likes(user_checkpoint_obj) total_shares = get_total_shares(user_checkpoint_obj) current_user_like = (not get_like_w_attr(user_obj, user_checkpoint_obj.checkpoint) is None) comments = get_checkpoint_comments(user_checkpoint_obj.checkpoint) checkpoint_user_obj = user_checkpoint_obj.user user = {"name": checkpoint_user_obj.facebook_user.name, "facebook_portrait_url": "https://graph.facebook.com/%s/picture" % checkpoint_user_obj.facebook_user.id, } res = CheckpointDetail(user_checkpoint_obj, total_likes, total_shares, current_user_like, comments, user ) return res
def add_checkpoint_to_catalog(): """ (POST: user_checkpoint) user likes a Checkpoint from a user and wants to add it into his catalog; adds checkpoint to user's catalog """ #req vars user_id = request.form.get("user_id") signature = request.form.get("signature") to_add_user_checkpoint_id = request.form.get("user_checkpoint_id") #generated var verb = "post" noun = "catalog" user = get_user(user_id) if not authorize(verb, noun, user_id, signature): return authorization_fail() user_checkpoint = get_user_checkpoint(to_add_user_checkpoint_id) new_user_cp = add_existing_checkpoint_to_user(user, user_checkpoint) return jsonify({ "status": "ok", "result": { "user_checkpoint_id": new_user_cp.id, }, })
def new_comment(): """ (PUT: comment) Instantiates a new <<Comment>> from a user on a <<UserCheckpoint>> """ #req var user_id = request.form.get("user_id") signature = request.form.get("signature") user_checkpoint_id = request.form.get("user_checkpoint_id") comment = request.form.get("comment") #generated var verb = "put" noun = "comment" user = get_user(user_id) user_checkpoint = get_user_checkpoint(user_checkpoint_id) #authorization check if not authorize(verb, noun, user_id, signature): return authorization_fail() #comment validation if len(comment) > 255: return jsonify({ "status": "error", "error": "Comment too long", }) comment = add_comment(user, user_checkpoint, comment) return jsonify({ "status": "ok", "result": { "comment_id": comment.id } })