remove simplify frac text, add CORS fix for Vue port 8080 usage, fix swapped response & response code in API question generation

This commit is contained in:
Xevion
2020-12-13 17:43:27 -06:00
parent 714d5b6f7b
commit 4bc226713a
5 changed files with 9 additions and 4 deletions

View File

@@ -1,2 +1,3 @@
flask flask
flask-restful flask-restful
flask-cors

View File

@@ -58,7 +58,7 @@ class Question(Resource):
args = parser.parse_args() args = parser.parse_args()
# Generate new Question ID # Generate new Question ID
q_id = Nonewt q_id = None
while q_id in active_questions.keys() or q_id is None: while q_id in active_questions.keys() or q_id is None:
q_id = generate_id(5) q_id = generate_id(5)
@@ -78,7 +78,7 @@ class Question(Resource):
question = copy.copy(active_questions[q_id]) question = copy.copy(active_questions[q_id])
del question['answer'] del question['answer']
return 201, question return question, 201
def delete(self, question_id): def delete(self, question_id):
"""Delete a question object from the running before it is automatically removed.""" """Delete a question object from the running before it is automatically removed."""

View File

@@ -58,7 +58,7 @@ def simplify_fraction():
return { return {
'type': inspect.stack()[0][3], 'type': inspect.stack()[0][3],
'question': f'Simplify. \\frac{{{c}}}{{{d}}}', 'question': f'\\frac{{{c}}}{{{d}}}',
'answer': f'{a}/{b}' 'answer': f'{a}/{b}'
} }

View File

@@ -6,6 +6,7 @@ The main app creation, registering extensions, API routes, the Vue.js catch all
from flask import Flask, render_template, jsonify from flask import Flask, render_template, jsonify
from flask_restful import Api from flask_restful import Api
from flask_cors import CORS
from server import exceptions from server import exceptions
from server.api import Question, Questions, Category, Categories from server.api import Question, Questions, Category, Categories
@@ -19,6 +20,9 @@ def create_app(env=None):
template_folder="./../dist" template_folder="./../dist"
) )
# Add CORS support
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
# Instantiate Flask-Restful API and register appropriate routes # Instantiate Flask-Restful API and register appropriate routes
api = Api(app, prefix='/api/') api = Api(app, prefix='/api/')
api.add_resource(Question, '/question/', '/question/<string:question_id>') api.add_resource(Question, '/question/', '/question/<string:question_id>')

View File

@@ -5,6 +5,7 @@ Stores all API exceptions neatly for importing and usage elsewhere.
""" """
from typing import Tuple from typing import Tuple
# TODO: Improve exception management to cut down needless class definitions. # TODO: Improve exception management to cut down needless class definitions.
# TODO: Add 'extra' message parameter to base APIException kwargs. # TODO: Add 'extra' message parameter to base APIException kwargs.
@@ -75,7 +76,6 @@ class InvalidURIParam(APIException):
return error return error
class InvalidQuestion(InvalidURIParam): class InvalidQuestion(InvalidURIParam):
MESSAGE = "A invalid question was specified in the request URI and could not be resolved." MESSAGE = "A invalid question was specified in the request URI and could not be resolved."