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_all_topics function #7

Open MagnusLii opened 10 months ago

MagnusLii commented 10 months ago

Vote History Data Retrieval Function from DB

Goal

This function should contain a pre-defined SQL query to retrieve the entire vote history from the database. After obtaining this information, the function transforms it into JSON string format.

Arguments

Returns

Function Name: get_all_topics

MagnusLii commented 9 months ago

The function utilizes SQLAlchemy instead of queries.

```py # GET all topics (votes) from the database. def get_all_topics(): try: topics = Topics.query.all() topic_data_list = [] for topic in topics: topic_data = { "TopicID": topic.TopicID, "Title": topic.Title, "Description": topic.Description, "StartTime": str(topic.StartTime), "EndTime": str(topic.EndTime) } topic_data_list.append(topic_data) return jsonify(topic_data_list) except Exception as errorMsg: error_message = {"error": str(errorMsg)} return jsonify(error_message), 500 ```