Exemple #1
0
    def post(self):
        data = request.get_json()

        if SQL_queries_to_database.find_user_quiz_result(data['user_id'], data['quiz_id'], data['quiz_iteration']):
            return {'message': 'User has already taken this quiz'}, 400

        committed = SQL_queries_to_database.implant_users_quiz_score(data)

        if committed:
            return {'message': "Quiz results entered successfully."}, 201
Exemple #2
0
    def post(self):
        data = request.get_json()

        quiz_id = SQL_queries_to_database.find_new_quiz_id()

        if SQL_queries_to_database.find_quiz_by_id(quiz_id['quiz_id'] + 1):
            return {'message': 'A quiz with that id already exists'}, 400

        committed = SQL_queries_to_database.create_quiz(
            data, quiz_id['quiz_id'])

        if committed:
            return {'message': "Quiz created successfully."}, 201
Exemple #3
0
    def post(self):
        data = request.get_json()

        if User.find_by_username(data['username']):
            return {'username error': 'A user with that username already exists'}, 400
        elif User.find_by_email(data['email']):
            return {'email error': 'A user with that email already exists'}, 400
        else:
            user_id = SQL_queries_to_database.find_user_id()
            committed = SQL_queries_to_database.create_user(data, user_id['user_id'])

            if committed:
                return {'message': "User created successfully."}, 201
Exemple #4
0
    def get(self, quiz_id, user_id, quiz_action):

        quiz_questions = SQL_queries_to_database.find_quiz_questions(
            quiz_id, user_id, quiz_action)

        if quiz_action == "Taking_Quiz":
            if len(quiz_questions) == 0:
                return {
                    'Completed the quiz':
                    'You have completed all the questions to this quiz!'
                }, 200
            elif len(quiz_questions) < 10:
                return {
                    'Quiz Creator?':
                    'Quiz creator needs to finish adding more questions to make a complete 10 question quiz'
                }
            else:
                restructured_quiz_questions = {}
                for i in range(0, len(quiz_questions)):
                    restructured_quiz_questions[i + 1] = quiz_questions[i]
                return jsonify(restructured_quiz_questions)
        elif quiz_action == "Editing_Questions":
            if len(quiz_questions) == 0:
                return {'No questions': 0}
            else:
                restructured_quiz_questions = {}
                for i in range(0, len(quiz_questions)):
                    restructured_quiz_questions[i + 1] = quiz_questions[i]
                return jsonify(restructured_quiz_questions)
Exemple #5
0
    def put(self, quiz_id):
        data = request.get_json()

        committed = SQL_queries_to_database.revise_quiz(data, quiz_id)

        if committed:
            return {'message': 'quiz was successfully updated'}, 202
Exemple #6
0
    def put(self, question_id):
        data = request.get_json()

        committed = SQL_queries_to_database.revise_quiz_question(
            data, question_id)

        if committed:
            return {'message': 'quiz question was updated successfully'}
Exemple #7
0
    def get(self, quiz_id):

        number_of_questions = SQL_queries_to_database.find_number_of_quiz_questions(
            quiz_id)

        return {
            'number of questions in quiz': number_of_questions[0]['COUNT(*)']
        }, 200
Exemple #8
0
    def post(self):
        data = request.get_json()

        user_quiz_results = SQL_queries_to_database.find_user_quiz_results(data['user_id'], data['quiz_id'])
        restructured_user_quiz_results = {}
        for i in range(0, len(user_quiz_results)):
            restructured_user_quiz_results['Iteration: ' + str(user_quiz_results[i]['iteration'])] = user_quiz_results[i]
        return jsonify(restructured_user_quiz_results)
Exemple #9
0
    def find_by_email(cls, _email):
        results = SQL_queries_to_database.find_user_by_email(_email)

        if results:
            user = cls(*results)
        else:
            user = None
        return user
Exemple #10
0
    def find_by_id(cls, _id):
        results = SQL_queries_to_database.find_user_by_id(_id)

        if results:
            user = cls(*results)
        else:
            user = None
        return user
Exemple #11
0
    def find_by_username(cls, username):
        results = SQL_queries_to_database.find_user_by_username(username)

        if results:
            user = cls(results['user_id'], results['username'], results['password'], results['email'],
                       results['date_created'], results['last_login'], results['admin'], results['creator'])
        else:
            user = None
        return user
    def post(self):
        data = request.get_json()

        if SQL_queries_to_database.find_user_question_results(data['question_0']['user_id'],
                                                              data['question_0']['quiz_id'],
                                                              data['question_0']['quiz_iteration']):
            return {'message': 'User has already answered this question'}, 400

        committed_list = []
        for k in data.keys():
            committed = SQL_queries_to_database.implant_users_question_answers(data[k])
            committed_list.append(committed)

        for commit in committed_list:
            if not commit:
                return {'message': 'Error! User questions results implanted unsuccessfully.'}, 201
                break
        else:
            return {'message': 'User questions results implanted successfully.'}, 201
Exemple #13
0
    def post(self):
        data = request.get_json()

        quiz_questions = SQL_queries_to_database.find_quiz_questions_by_ids(
            data['question_ids'])

        restructured_quiz_questions = {}
        for i in range(0, len(quiz_questions)):
            restructured_quiz_questions[quiz_questions[i]
                                        ['question_id']] = quiz_questions[i]
        return jsonify(restructured_quiz_questions)
Exemple #14
0
    def post(self):
        data = request.get_json()

        if data['quiz_name'] is not None:
            quizzes = SQL_queries_to_database.find_quiz_by_name(
                data["quiz_name"], data['user_id'], data['users_quizzes'])
        elif data['createdBy'] is not None:
            quizzes = SQL_queries_to_database.find_quiz_by_creator(
                data["createdBy"], data['user_id'], data['users_quizzes'])
        elif data['source'] is not None:
            quizzes = SQL_queries_to_database.find_quiz_by_type(
                data["source"], data['user_id'], data['users_quizzes'])
        else:
            quizzes = SQL_queries_to_database.find_all_quizzes(
                data['user_id'], data['users_quizzes'])

        if len(quizzes) == 1:
            return jsonify(quizzes)
        else:
            restructured_quizzes = {}
            for i in range(0, len(quizzes)):
                restructured_quizzes[str(i + 1)] = quizzes[i]
            return jsonify(restructured_quizzes)
Exemple #15
0
    def post(self):
        data = request.get_json()

        id = SQL_queries_to_database.create_quiz_question(data)

        return {'question_id': id}, 200
Exemple #16
0
 def put(self, quiz_id):
     committed = SQL_queries_to_database.delete_quiz_by_id(quiz_id)
Exemple #17
0
    def get(self, username):

        user = SQL_queries_to_database.find_user_by_username(username)

        return jsonify(user)
Exemple #18
0
 def get(self, quiz_id):
     quiz = SQL_queries_to_database.find_quiz_by_id(quiz_id)
     return jsonify(quiz[0])
Exemple #19
0
    def get(self, email):

        user_info = SQL_queries_to_database.find_user_by_email(email)

        return user_info
Exemple #20
0
 def get(self, user_id, quiz_id, quiz_iteration):
     user_quiz_result = SQL_queries_to_database.find_user_quiz_result(user_id, quiz_id, quiz_iteration)
     return jsonify(user_quiz_result)
Exemple #21
0
    def post(self):
        data = request.get_json()

        quiz_iteration = SQL_queries_to_database.find_quiz_iteration(data['user_id'], data['quiz_id'])
        quiz_iteration['iteration'] += 1
        return jsonify(quiz_iteration)
Exemple #22
0
    def get(self, question_id):
        quiz_question = SQL_queries_to_database.find_quiz_question(question_id)

        return jsonify(quiz_question)
from Models import SQL_queries_to_database

create_tables = 0

if create_tables == 1:
    SQL_queries_to_database.create_nerd_alert_tables()