diff --git a/challenges/backend/server.py b/challenges/backend/server.py new file mode 100755 index 000000000..c533949c6 --- /dev/null +++ b/challenges/backend/server.py @@ -0,0 +1,54 @@ +from flask import Flask, request +from flask_restful import Resource,Api,reqparse, abort +import requests + +app = Flask(__name__) +api = Api(app) + +NUMBERLIST = {"list":[]} + +class ListProcess(Resource): + def get(self): + #Sort before returning + if(len(NUMBERLIST['list']) > 0): + NUMBERLIST['list'].sort() + return NUMBERLIST + else: + abort(404, message="No lists found.") + + def post(self): + numlist = str(request.data).strip() + numlist = numlist.split(sep=',') + templist = [] + if(len(numlist) == 500): + allnumbers = True + for entry in numlist: + entry = entry.replace('b\'','') + entry = entry.replace('\'','') + if(entry.isdigit() == False): + allnumbers = False + else: + templist.append(int(entry)) + if(allnumbers == True): + NUMBERLIST['list'] = templist + return NUMBERLIST + else: + abort(400,message="Bad input. All entries must be numbers.") + else: + abort(400, message="Bad input. Length must be 500.") + + def patch(self): + entry = str(request.data).strip() + entry = entry.replace('b\'', '') + entry = entry.replace('\'', '') + if(entry.isdigit()): + NUMBERLIST['list'].append(int(entry)) + NUMBERLIST['list'].sort() + return NUMBERLIST + else: + abort(400,message="Bad input. All entries must be numbers.") + +api.add_resource(ListProcess, "/data/",endpoint='data') + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=True) \ No newline at end of file diff --git a/challenges/backend/tester.py b/challenges/backend/tester.py new file mode 100644 index 000000000..952a85be7 --- /dev/null +++ b/challenges/backend/tester.py @@ -0,0 +1,16 @@ +import requests +import random +payload = '' +for i in range(499): + temp = random.randint(0,500) + payload = payload + str(temp) + ',' +payload = payload + str(random.randint(0,500)) +patchload = str(random.randint(0,500)) +r=requests.get("http://localhost:5000/data/") +print("get", r.text) +r=requests.post("http://localhost:5000/data/",data=payload) +print("post",r.text) +r=requests.get("http://localhost:5000/data/") +print("get", r.text) +r=requests.patch("http://localhost:5000/data/",data=patchload) +print("patch", r.text) \ No newline at end of file diff --git a/challenges/database/ER_Diagram.png b/challenges/database/ER_Diagram.png new file mode 100644 index 000000000..4fab4c160 Binary files /dev/null and b/challenges/database/ER_Diagram.png differ diff --git a/challenges/database/database.py b/challenges/database/database.py new file mode 100644 index 000000000..e039c338a --- /dev/null +++ b/challenges/database/database.py @@ -0,0 +1,30 @@ +import sqlite3 +import sys +#This program should only be run once to construct the database. +if(len(sys.argv) == 2): + handle = sys.argv[1] + con = sqlite3.connect(handle) + cur = con.cursor() + query = '''CREATE TABLE record + (id smallint, + basic int, + advanced int, + plan bool, + PRIMARY KEY(id))''' + print(query) + cur.execute(query) + query = '''CREATE TABLE customer + (name varchar(20), + email varchar(50), + workphone varchar(20), + cellphone varchar(20), + address tinytext, + order_id smallint, + PRIMARY KEY(name,email), + FOREIGN KEY(order_id) REFERENCES record(id))''' + print(query) + cur.execute(query) + con.commit() + con.close() +else: + print("Expected input: python3 database.py ") \ No newline at end of file diff --git a/challenges/database/db_migrate.py b/challenges/database/db_migrate.py new file mode 100644 index 000000000..4c9180d3d --- /dev/null +++ b/challenges/database/db_migrate.py @@ -0,0 +1,40 @@ +import sqlite3 +import json +import sys +json_dict = {} +if(len(sys.argv) == 3): + with open (sys.argv[1], 'r') as handle: + json_dict = json.load(handle) + con = sqlite3.connect(sys.argv[2]) + cur = con.cursor() + values = ('(' + str(json_dict['record_id']) + ',' + + str(json_dict['basic_order']) + ',' + + str(json_dict['advanced_order']) + ',' + + str(int(json_dict['protection_plan'])) + ')') + query = "INSERT INTO record " + values + print(query) + #This is the query, but doing this directly is insecure. Instead, we do this: + cur.execute("INSERT INTO record values (?,?,?,?)",( + json_dict['record_id'], + json_dict['basic_order'], + json_dict['advanced_order'], + int(json_dict['protection_plan']))) + values = ('(\'' + json_dict['name'] + '\',\'' + + json_dict['email'] + '\',\'' + + json_dict['work'] + '\',\'' + + json_dict['cell'] + '\',\'' + + json_dict['address'] + '\',' + + str(json_dict['record_id']) + ')') + query = "INSERT INTO custormer " + values + print(query) + cur.execute("INSERT INTO customer values (?,?,?,?,?,?)",( + json_dict['name'], + json_dict['email'], + json_dict['work'], + json_dict['cell'], + json_dict['address'], + json_dict['record_id'])) + con.commit() + con.close() +else: + print("Expected input: python3 db_migrate.py ") \ No newline at end of file diff --git a/challenges/database/record.json b/challenges/database/record.json new file mode 100644 index 000000000..9e718a6be --- /dev/null +++ b/challenges/database/record.json @@ -0,0 +1 @@ +{"record_id": 1234, "name": "Joe Smith", "cell": "405.868.5309", "work": "123.123.1234", "email": "joe_s@gmail.com", "address": "123 Vic Way, Dallas TX 75001", "basic_order": 37, "advanced_order": 12, "protection_plan": true} \ No newline at end of file diff --git a/challenges/frontend/favicon.png b/challenges/frontend/favicon.png new file mode 100644 index 000000000..626e97c13 Binary files /dev/null and b/challenges/frontend/favicon.png differ diff --git a/challenges/frontend/frontend.html b/challenges/frontend/frontend.html new file mode 100644 index 000000000..334b21fe1 --- /dev/null +++ b/challenges/frontend/frontend.html @@ -0,0 +1,32 @@ + + + + + + + + +

Erik's HTML Company

+

Contact Us

+
+ +
+
+
+
+
+
+
+ + + + \ No newline at end of file