From 81c064b6b60935d62fb03acfe0d4a329819a8a7c Mon Sep 17 00:00:00 2001 From: Jose De Freitas Date: Sun, 28 Feb 2021 17:52:08 -0500 Subject: [PATCH] Apply full functionality --- voter/api/api.py | 65 ++++++++++++++++++++++++++++++++---------------- voter/data.json | 10 ++++---- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/voter/api/api.py b/voter/api/api.py index cf673c1..c4b53cd 100644 --- a/voter/api/api.py +++ b/voter/api/api.py @@ -14,30 +14,51 @@ def list_channels(): return jsonify(channels) -@api_channels.route("/channels") -def get_channel(): - """ - Opens the confirmation form that sends the vote - to the database corresponding the channel selected. - """ - - if "name" in request.args and "vote" in request.args: - name = str(request.args["name"]) +@api_channels.route("/channels/") +def get_channel(channel): + if "vote" in request.args: vote = str(request.args["vote"]) - if "name" in request.args and "vote" not in request.args: - return vote - # else: - # return "No name of channel and vote provided." + if channel in channels: + if vote == "upvote": + channels[channel] += 1 + elif vote == "downvote": + channels[channel] -= 1 + else: + return "Vote word not recognised." - if name in channels: - if vote == "upvote": - channels[name] += 1 + with open("data.json", "w", encoding="utf8") as write_data: + json.dump(channels, write_data, indent=4) + + return f"You {vote}d successfully the channel {channel}." else: - channels[name] -= 1 - - with open("data.json", "w", encoding="utf8") as write_data: - json.dump(channels, write_data, indent=4) - return f"You {vote}d successfully the channel {name}." + return "Channel not found on the list." else: - return "The name specified is not a channel on the list." + if channel in channels: + return "Channel: " + channel + else: + return "Channel not found on the list." + + +@api_channels.route("/channels//image.svg") +def img_channel(channel): + if channel in channels: + return f""" + + + + + + {channels[channel]} + + + + """ + else: + return "Channel not found on the list" diff --git a/voter/data.json b/voter/data.json index 0737ba6..7501df2 100644 --- a/voter/data.json +++ b/voter/data.json @@ -1,10 +1,10 @@ { - "Tech With Tim": 0, - "Derek Banas": 0, - "Don Jones": 0, + "Tech With Tim": 12, + "Derek Banas": 1, + "Don Jones": 1, "Corey Schafer": 0, "Brian Will": 0, - "LearningLad": 0, + "LearningLad": 68, "David Bombal": 0, "Ben Eater": 0, "The Coding Train": 0, @@ -23,7 +23,7 @@ "WilliamFiset": 0, "Caleb Curry": 0, "CodingEntrepreneurs": 0, - "Sebastiaan Mathôt": 0, + "Sebastiaan Math\u00f4t": 0, "AngelSix": 0, "DataDaft": 0, "Fun Fun Function": 0,