Skip to content

Commit

Permalink
added material UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreymew committed Dec 4, 2018
1 parent 1c3f993 commit 04c469c
Show file tree
Hide file tree
Showing 75 changed files with 16,494 additions and 29 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": ["es2015"],
"plugins": [
"transform-class-properties",
"transform-react-jsx",
"transform-object-rest-spread",
["module-resolver", {
"root": ["./src"],
}],
["import-rename", {"^(.*)\\.jsx$": "$1"}]
]
}
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_PATH=./src
3 changes: 3 additions & 0 deletions .envpython
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class BaseConfig(object):
DATABASE_URL=sqlite:///db.sqlite3
SECRET_KEY=rqr_cjv4igscyu8&&(0ce(=sy=f2)p=f_wn&@0xsp7m$@!kp=d
29 changes: 27 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
node_modules/
__pycache__/
dist/
settings.py
settings.json
settings.json
db.sqlite3

# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# npmjs
/dist

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-azuretools.vscode-azureappservice",
"ms-python.python",
"vsmobile-vscode-react-native"
"ms-python.python"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Creative Tim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 36 additions & 12 deletions app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,48 +69,72 @@ def __init__(self, task, user_id, status):
self.status = status

@staticmethod
def add_task(incoming):
def add_task(task, user_id, status):
task = Task(
task=incoming["task"],
user_id=incoming["user_id"],
status=incoming["status"]
task=task,
user_id=user_id,
status=status
)


db.session.add(task)
try:
db.session.add(task)
db.session.commit()
return True
return True, task.id
except IntegrityError:
return False
return False, None

@staticmethod
def get_latest_tasks():
user_to_task = {}

result = db.engine.execute(
"""SELECT date, task, t.user_id, status, u.first_name, u.last_name
"""SELECT t.id, t.date, t.task, t.user_id, t.status, u.first_name, u.last_name
from task t
INNER JOIN (SELECT user_id, max(date) as MaxDate from task group by user_id) tm
on t.user_id = tm.user_id and t.date = tm.MaxDate
INNER JOIN "user" u
on t.user_id = u.email""") # join with users table
# INNER JOIN (SELECT user_id, max(date) as MaxDate from task group by user_id) tm
# on t.user_id = tm.user_id and t.date = tm.MaxDate

for t in result:
if t.user_id in user_to_task:
user_to_task.get(t.user_id).append(dict(t))
else:
user_to_task[t.user_id] = [dict(t)]

return user_to_task

@staticmethod
def get_tasks_for_user(user_id):
return Task.query.filter_by(user_id=user_id)

@staticmethod
def delete_task(task_id):
task_to_delete = Task.query.filter_by(id=task_id).first()
db.session.delete(task_to_delete)

try:
db.session.commit()
return True
except IntegrityError:
return False

@staticmethod
def edit_task(task_id, task, status):
task_to_edit = Task.query.filter_by(id=task_id).first()
task_to_edit.task = task
task_to_edit.status = status

try:
db.session.commit()
return True
except IntegrityError:
return False

@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id' : self.id,
'date' : self.date.strftime("%Y-%m-%d"),
'task' : self.task,
'user_id' : self.user_id,
Expand Down
41 changes: 38 additions & 3 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,55 @@ def is_token_valid():


@app.route("/api/submit_task", methods=["POST"])
@requires_auth
def submit_task():
incoming = request.get_json()

success = Task.add_task(incoming)
success, id = Task.add_task(
incoming.get("task"),
incoming.get("user_id"),
incoming.get("status")
)

if not success:
return jsonify(message="Error submitting task"), 409
return jsonify(message="Error submitting task", id=None), 409

return jsonify(success=True, id=id)

return jsonify(success=True)


@app.route("/api/get_tasks_for_user", methods=["POST"])
@requires_auth
def get_tasks_for_user():
incoming = request.get_json()

return jsonify(
tasks=[i.serialize for i in Task.get_tasks_for_user(incoming["user_id"]).all()]
)

@app.route("/api/delete_task", methods=["POST"])
@requires_auth
def delete_task():
incoming = request.get_json()

success = Task.delete_task(incoming.get('task_id'))
if not success:
return jsonify(message="Error deleting task"), 409

return jsonify(success=True)


@app.route("/api/edit_task", methods=["POST"])
@requires_auth
def edit_task():
incoming = request.get_json()

success = Task.edit_task(
incoming.get('task_id'),
incoming.get('task'),
incoming.get('status')
)
if not success:
return jsonify(message="Error editing task"), 409

return jsonify(success=True)
3 changes: 1 addition & 2 deletions app/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from flask import request, g, jsonify
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from itsdangerous import SignatureExpired, BadSignature
from app.settings import SECRET_KEY # TODO change to get from ENV variable
from app.settings import SECRET_KEY

TWO_WEEKS = 1209600


def generate_token(user, expiration=TWO_WEEKS):
s = Serializer(SECRET_KEY, expires_in=expiration)
token = s.dumps({
Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def create_db():


if __name__ == '__main__':
# manager.add_option("--dev", required=False, defaut=config.)
manager.run()
Loading

0 comments on commit 04c469c

Please sign in to comment.