murphyslemon / Raspberry_Pi_Server

International Sensor Development Project: This project is a voting system that uses a raspberry pi server and multiple voting devices. The system is easy, secure, scalable, and supports anonymous and registered voting. This repository focuses on the Raspberry Pi server.
0 stars 3 forks source link

get_topic function #8

Open MagnusLii opened 10 months ago

MagnusLii commented 10 months ago

Specific Vote Data Query Function from DB

Goal

This function takes in a JSON string containing the ID value of a vote within the database. Subsequently, the function constructs a SQL query to retrieve all information associated with the specified vote from the database.

Arguments

Returns

Function Name: get_topic

MagnusLii commented 9 months ago

The code takes int he topicID directly rather than a json string containing the data as handling that information within the function is pointless.

def get_topic(topicID):
    try:
        topic = Topics.query.filter_by(TopicID=topicID).first()

        topic_data = {
            "TopicID": topic.TopicID,
            "Title": topic.Title,
            "Description": topic.Description,
            "StartTime": str(topic.StartTime),
            "EndTime": str(topic.EndTime)
        }

        return jsonify(topic_data)

    except Exception as errorMsg:
        error_message = {"error": str(errorMsg)}
        return jsonify(error_message), 500