Skip to content

Commit ede7c75

Browse files
committed
Added endpoint to get all pastes.
1 parent 81e9087 commit ede7c75

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

app.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_paste(id):
8888
'message': 'No post can be found associated with the given id.'
8989
})
9090

91-
author, text, language, type, date, = result[0]
91+
author, text, language, type, date = result[0]
9292
cursor.close()
9393
connection.close()
9494

@@ -100,6 +100,33 @@ def get_paste(id):
100100
'date': date
101101
})
102102

103+
@app.route('/v1/pastebin/all', methods = ['GET'])
104+
def get_all_pastes():
105+
initialize_tables()
106+
107+
connection = sqlite3.connect(DATABASE_FILE_NAME)
108+
cursor = connection.cursor()
109+
110+
query = ('SELECT id, author, text, language, type, date FROM pastebin')
111+
cursor.execute(query)
112+
results = cursor.fetchall()
113+
114+
all_pastes = []
115+
for paste in results:
116+
id, author, text, language, type, date = paste
117+
all_pastes.append({
118+
'id': str(id),
119+
'author': str(author),
120+
'text': text,
121+
'language': language,
122+
'type': type,
123+
'date': date
124+
})
125+
126+
return jsonify({
127+
'results': all_pastes,
128+
})
129+
103130
def create_table():
104131
print('Creating a table!')
105132
connection = sqlite3.connect(DATABASE_FILE_NAME)

0 commit comments

Comments
 (0)