Implement post method

This commit is contained in:
Jose De Freitas 2021-02-28 12:01:11 -05:00
parent 5e93e266e9
commit 3863384afe
4 changed files with 41 additions and 0 deletions

0
voter/api/__init__.py Normal file
View File

32
voter/api/api.py Normal file
View File

@ -0,0 +1,32 @@
import json
from flask import Blueprint, request, jsonify
with open("data.json", "r") as read_data:
channels = json.load(read_data)
api_channels = Blueprint('api_channels', __name__)
@api_channels.route("/channels/all")
def list_channels():
""" Lists all channels in the database. """
return jsonify(channels)
@api_channels.route("/channels", methods=["GET", "POST"])
def get_channel():
"""
Opens the confirmation form that sends the vote
to the database corresponding the channel selected.
"""
if "name" in request.args:
name = str(request.args["name"])
else:
return "No name of channel provided."
if name in channels:
return "Good!"
else:
return "The name specified is not a channel on the list."

6
voter/data.json Normal file
View File

@ -0,0 +1,6 @@
{
"Tech With Tim": 0,
"Derek Banas": 0,
"Don Jones": 0,
"LearningLad": 0
}

View File

@ -1,7 +1,10 @@
from flask import Flask
from api.api import api_channels
app = Flask(__name__)
app.register_blueprint(api_channels)
@app.route("/")
def main():