Skip to content

Front End Challenge! #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c3f27ad
Finished front end challenge
emm190 Sep 30, 2021
8532cac
Added readme.md
emm190 Sep 30, 2021
56f757a
modified readme
emm190 Sep 30, 2021
05f91f9
Update README.md
emm190 Sep 30, 2021
7cb5e8c
updated readme
emm190 Sep 30, 2021
e011e28
Merge branch 'master' of https://github.com/emm190/Interview
emm190 Sep 30, 2021
58dfbda
Update README.md
emm190 Sep 30, 2021
e0eb7b6
modified css, js, port
emm190 Sep 30, 2021
7d55c51
modified readme
emm190 Sep 30, 2021
fc469f4
Update README.md
emm190 Sep 30, 2021
b25f987
Update README.md
emm190 Sep 30, 2021
999a5e3
Update README.md
emm190 Sep 30, 2021
17ea738
Update README.md
emm190 Sep 30, 2021
13934cc
finished readme
emm190 Sep 30, 2021
1a5917d
Update README.md
emm190 Sep 30, 2021
5e68437
Updated pages
emm190 Sep 30, 2021
c9716c2
Update local-server.js
emm190 Sep 30, 2021
67ce4bd
Create package-lock.json
emm190 Oct 3, 2021
32b981c
Submission
emm190 Oct 3, 2021
2621af5
Create README.md
emm190 Oct 3, 2021
7eaf715
Update README.md
emm190 Oct 3, 2021
ad925e7
Update README.md
emm190 Oct 3, 2021
fe50894
Update README.md
emm190 Oct 3, 2021
8b07f05
added error checking
emm190 Oct 3, 2021
1f63884
Merge branch 'master' of https://github.com/emm190/Interview
emm190 Oct 3, 2021
d113058
Update README.md
emm190 Oct 3, 2021
4b147f9
added db challenge
emm190 Oct 4, 2021
edc94cd
added var to py
emm190 Oct 4, 2021
8578b02
Update dbchallenge.py
emm190 Oct 4, 2021
cfcaa44
Create README.md
emm190 Oct 4, 2021
7179da8
Update README.md
emm190 Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions BackEndChallenge/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Users/emilymariemiller/Desktop/BackEndChallenge/myproject/bin/python"
}
69 changes: 69 additions & 0 deletions BackEndChallenge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

<!-- PROJECT LOGO -->
<br />
<p align="center">

<h3 align="center">Headstorm Engineering Back End Challenge</h3>

<p align="center">
I made a rest API using flask for the /data entry point.
</p>
</p>



<!-- TABLE OF CONTENTS -->
<details open="open">
<summary><h2 style="display: inline-block">Table of Contents</h2></summary>
<ol>
<li><a href="#built-with">Built With</a></li>
<li>
<a href="#run-it">Run the project</a>
</li>
<li><a href="#usage">Improvements</a></li>
<li><a href="#contact">Contact</a></li>
</ol>
</details>




### Built With

* []() Python
* []() HTML

### Using

* []() Flask, python microframework
* []() Flask's SQLAlchemy & Flask's Restful API


<!-- GETTING STARTED -->
## Getting Started

To get a local copy up and running follow these simple steps.

### Prerequisites

You will need to have python 3.8.5 & flask installed along with the flask dependencies that are listed at the top of the app.py file. Specifically install flask_sqlalchemy & flask_restful along with flask.

### Installation

1. Clone my repo :)
2. Install flask & flask requirements
3. I set up a virtual environment & installed flask & the dependencies that way
4. To run my virtual environment, type "source bin/activate" from the myproject directory

### Run The Project
4. Type "python app.py"

### Improvements
* I did not get a chance to add the requirements about the input being 500 numbers as json input. My current program takes in 5 numbers. It checks that there are exactly 5 integers, but does not check that there are 500 or the input. It only works if there are 5 numbers separated by commas. This addition to meet the 500 json requirements could be
* met with more time.

### Contact
Please contact me with any issues running the code:
* email: [email protected]
* phone: 330-987-0225
* linkedIn: https://www.linkedin.com/in/emilymiller21/
95 changes: 95 additions & 0 deletions BackEndChallenge/myproject/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from flask import Flask
from flask_restful import Resource, Api
from flask import render_template
from flask import request
from flask import jsonify
from flask import redirect
from flask import url_for
from flask_sqlalchemy import SQLAlchemy
import re
from flask import flash


app = Flask(__name__)
api = Api(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)


class Number(db.Model):
id = db.Column(db.Integer, primary_key=True)
numbers = db.Column(db.String(80), unique=False, nullable=False)

def __repr__(self):
return '%s' % (
self.numbers)

def __init__(self, numbers):
self.numbers = numbers

db.create_all()

@app.route('/')
def home_page():
example_embed='Hello! Welcome to my submission for the backend challenge.'
return render_template('index.html', embed=example_embed)

@app.route('/data',methods = ['POST', 'GET'])
def data():
if request.method == 'POST':
numbers = request.form['numbers']
stringList = numbers
number1 = Number(stringList)
db.session.add(number1)
db.session.commit()
idNumber = number1.id
listOfNumbers = str(stringList)
user = listOfNumbers.split(',')
for x in user:
try:
int(x)
except:
error_msg='There is something wrong with your formatting. Make sure you did not enter any letters. The only acceptable input is numbers separated by commas (with no space at the end)'
return render_template('index.html', embed=error_msg)
intList = [int(x) for x in user]
print(intList)
if (len(intList)!=5):
error_msg='You have to enter 5 numbers. You did not. Try again'
return render_template('index.html', embed=error_msg)
print(idNumber)
return redirect(url_for('success',listOfNumbers = Number.query.filter_by(id=idNumber).all()))
else:
user = request.args.get('numbers')
lastQuery = Number.query.count()
print(Number.query.all())
return redirect(url_for('success',listOfNumbers = Number.query.filter_by(id=lastQuery).all()))

@app.route('/getValue',methods = ['POST'])
def getValue():
numbers = request.form['numbersOfRequest']
return redirect(url_for('success',listOfNumbers = Number.query.filter_by(id=numbers).all()))

@app.route('/success/<listOfNumbers>')
def success(listOfNumbers):
listOfNumbers = str(listOfNumbers)
user = listOfNumbers.split(',')
print(user)
intList = [int(x) for x in user]
intList.sort()
print(intList)
return 'This is your sorted list of numbers:%s' % str(intList)

@app.route('/showAll', methods = ['POST', 'GET'])
def showAll():
print(Number.query.count())
list = []
for x in range(Number.query.count()):
print(Number.query.filter_by(id=x).all())
list.append("%d:" %x)
list.append(Number.query.filter_by(id=x).all())
listOfNumbers = Number.query.all()
print(listOfNumbers)
return 'This is all of the submissions:%s' % list

if __name__ == '__main__':
app.run(debug=True)
Loading