Skip to content
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

Paper-Ruthie Newman #71

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
910c4c0
Add Blueprints for task and goal in __init__.py.
RuthieRNewman May 6, 2021
017dee1
Register Blueprints for task blueprint and goal blueprint in routes.py.
RuthieRNewman May 6, 2021
0127839
Register task_bp and goal_bp Blueprints and import Task and Goal mode…
RuthieRNewman May 6, 2021
ae62c5c
Adds task_bp and goal_bp Blueprints in routes.py and defines Task Mod…
RuthieRNewman May 6, 2021
bf142cb
Generates migrations for goal.py and task.py.
RuthieRNewman May 6, 2021
fc8b18e
Adds GET and POST endpoints for tasks.
RuthieRNewman May 6, 2021
48a601a
Adds Goal model and instantiates a one to many relationship between T…
RuthieRNewman May 10, 2021
6e7565f
Adds migrations for changes made to Goal and Task Models to instantia…
RuthieRNewman May 10, 2021
e2ca8c7
Adds endpoints for Goal table and for one-tomany routes between goal …
RuthieRNewman May 10, 2021
03c82fb
adds routes to access data via task to goal relationsip, adds instanc…
RuthieRNewman May 11, 2021
d4f8cf9
Adds and populates Procfile file to root folder.
RuthieRNewman May 11, 2021
a3a4726
Adds instance method from_json for Goal and for Task classes in task.…
RuthieRNewman May 12, 2021
53b33d7
populates endpoints for tasks and goals with conditionals to address …
RuthieRNewman May 13, 2021
9186041
fixed key error in routes.py.
RuthieRNewman May 13, 2021
5b1097a
Comments out test_wave_07
RuthieRNewman May 13, 2021
802e2ec
changes key in response dictionary from 'token' to 'key' for mark_com…
RuthieRNewman May 13, 2021
9a89ccd
REvert changes made to response dictionary key from key back to token…
RuthieRNewman May 13, 2021
4a12975
renames variable name for api token key
RuthieRNewman May 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn 'app:create_app()'
14 changes: 12 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ def create_app(test_config=None):
"SQLALCHEMY_TEST_DATABASE_URI")

# Import models here for Alembic setup
from app.models.task import Task
from app.models.goal import Goal

db.init_app(app)
migrate.init_app(app, db)

# Register Blueprints here

#task
from .routes import tasks_bp
app.register_blueprint(tasks_bp)

#goal
from .routes import goals_bp
app.register_blueprint(goals_bp)

from app.models.task import Task
from app.models.goal import Goal


return app
19 changes: 18 additions & 1 deletion app/models/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,21 @@


class Goal(db.Model):
goal_id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(50))
tasks = db.relationship('Task', backref='goal', lazy=True)

def create_goal_json(self):

return {
'id' : self.id,
'title' : self.title
}

def from_json(request_dict):
# Converts JSON into a new instance of Task
new_goal = Goal(
title = request_dict["title"]
)

return new_goal
Comment on lines +17 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this method creates a new Goal, I suggest making it a class method

Suggested change
def from_json(request_dict):
# Converts JSON into a new instance of Task
new_goal = Goal(
title = request_dict["title"]
)
return new_goal
@classmethod
def from_json(cls, request_dict):
# Converts JSON into a new instance of Task
new_goal = Goal(
title = request_dict["title"]
)
return new_goal

44 changes: 43 additions & 1 deletion app/models/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
from flask import current_app
from app import db
from flask import Blueprint


class Task(db.Model):
task_id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(50))
description = db.Column(db.String(50))
completed_at = db.Column(db.DateTime, nullable=True)
goal_id = db.Column(db.Integer, db.ForeignKey("goal.id"), nullable=True)


def create_json(self):
if self.completed_at == None:
completed = False
else:
completed = True

return {
'id' : self.id,
'title' : self.title,
'description' : self.description,
'is_complete' : completed
}

def create_json_with_goal_id(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this helper a part of the above create_json function using an if statement to include goal if the goal field exists.

if self.completed_at == None:
completed = False
else:
completed = True

return {
'id' : self.id,
'goal_id' : self.goal_id,
'title' : self.title,
'description' : self.description,
'is_complete' : completed
}

def from_json(request_dict):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly I suggest making it a class method. This way you don't have to make an instance of Task before getting a new instance.

task = Task.from_json({ "title": "blah", "description": "...", "is_complete": True })

Suggested change
def from_json(request_dict):
@classmethod
def from_json(cls, request_dict):

new_task = Task(
title = request_dict["title"],
description = request_dict["description"],
completed_at = request_dict["completed_at"]
)

return new_task
Loading