Adding get_all_row and auth function stubs

pull/64/head
MasterGunner 5 years ago
parent 612e34b88d
commit 736f0e0fe4

@ -48,8 +48,10 @@ def thrimshim(ident):
row = flask.request.json row = flask.request.json
return update_row(ident, row) return update_row(ident, row)
else: else:
if ident:
return get_row(ident) return get_row(ident)
else:
return get_all_rows()
def get_row(ident): def get_row(ident):
"""Gets the row from the database with id == ident.""" """Gets the row from the database with id == ident."""
@ -73,11 +75,40 @@ def get_row(ident):
} }
return json.dumps(response) return json.dumps(response)
def get_all_rows():
"""Gets all rows from the events table from the database"""
conn = app.db_manager.get_conn()
results = database.query(conn, """
SELECT *
FROM events""")
rows = []
row = results.fetchone()
while row:
row = row._asdict()
row['id'] = str(row['id'])
row = {
key: (
value.isoformat() if isinstance(value, datetime.datetime)
else value
) for key, value in row.items()
}
rows.append(row)
row = results.fetchone()
if not rows:
return 'No rows found', 404
response = rows
return json.dumps(response)
def update_row(ident, new_row): def update_row(ident, new_row):
"""Updates row of database with id = ident with the edit columns in """Updates row of database with id = ident with the edit columns in
new_row.""" new_row."""
if not authenticate_user(new_row['Auth_Token']):
return 'User not authenticated.', 403
state_columns = ['state', 'uploader', 'error', 'video_link'] state_columns = ['state', 'uploader', 'error', 'video_link']
#these have to be set before a video can be set as 'EDITED' #these have to be set before a video can be set as 'EDITED'
non_null_columns = ['upload_location', 'video_start', 'video_end', non_null_columns = ['upload_location', 'video_start', 'video_end',
@ -94,6 +125,13 @@ def update_row(ident, new_row):
for extra in extras: for extra in extras:
del new_row[extra] del new_row[extra]
#validate title length - YouTube titles are limited to 100 characters, 9 reserved for "DBXXXX - ".
if(len(new_row['video_title']) > 91):
return 'Title must be 91 characters or less', 400
#validate start time is less than end time
if(new_row['video_start'] > new_row['video_end']):
return 'Video Start must be less than Video End.', 400
conn = app.db_manager.get_conn() conn = app.db_manager.get_conn()
#check a row with id = ident is in the database #check a row with id = ident is in the database
results = database.query(conn, """ results = database.query(conn, """
@ -140,6 +178,8 @@ def update_row(ident, new_row):
logging.info('Row {} updated to state {}'.format(ident, new_row['state'])) logging.info('Row {} updated to state {}'.format(ident, new_row['state']))
return '' return ''
def authenticate_user(authToken):
return True
@app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST']) @app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST'])
def manual_link(ident): def manual_link(ident):

Loading…
Cancel
Save