from flask import request, jsonify
from server import app
from os import getenv
import json

def return_options(x):
    return {"type": x}

@app.route('/homepage', methods=['GET'])
def get_homepage():
    with open('homepage_options.json') as json_file:
        data = json.load(json_file)
    cells = map(return_options, data['cellOptions'])
    return jsonify({
        "cells": cells
    })

@app.route('/homepage', methods=['POST'])
def change_order():
    cellOptions = request.get_json()
    authSecret = getenv('AUTH_SECRET')
    if (authSecret != request.headers.get('authSecret')):
        return "Please provide proper auth token with request."
    else:
        with open('homepage_options.json', 'w') as outfile:
            json.dump(cellOptions, outfile)
        return "Cell order successfully changed."

# TODO error check to ensure that cellOrder is only certain valid types

@@ -388,16 +388,318 @@
     %7D)%0A%0A
+# Error check request cell options%0Adef error_options(options):%0A    with open('homepage_options.json') as json_file:%0A        data = json.load(json_file)%0A    for option in options:%0A        if (option not in data%5B'cellOptions'%5D):%0A            print('not', option)%0A            return True%0A    return False%0A%0A
 @app.rou
@@ -950,16 +950,117 @@
 quest.%22%0A
+    elif error_options(cellOptions%5B'cellOptions'%5D):%0A        return %22Not all cell options are valid.%22%0A
     else

check for valid request values