Skip to content

Rock - Nyckolle L. #52

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 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
91fd8d2
completes initial setup
NLucuab May 6, 2021
a61ec77
updates task.py
NLucuab May 6, 2021
e71bdca
runs migrations
NLucuab May 6, 2021
3f8ff6c
initializes blueprint registers it in __init__.py
NLucuab May 6, 2021
7eadf3c
changes to routes & task class
NLucuab May 9, 2021
8938edf
adds Procfile file for heroku deployment
NLucuab May 9, 2021
b963379
changes " to ' in __init__ file & adds comment
NLucuab May 10, 2021
ab16820
refactors GET & POST methods
NLucuab May 10, 2021
4e07c82
adds is_complete function & improves "POST" method
NLucuab May 11, 2021
aa9d174
refactors to_json funciton & moves "GET" logic
NLucuab May 11, 2021
14c6110
sets up route for task_id & creates "GET"
NLucuab May 11, 2021
3e89ff4
adds DELETE logic & adds function comments
NLucuab May 11, 2021
c9cbd2f
adds PUT logic & completes Wave 1
NLucuab May 11, 2021
32c1dbd
adds sort logic for ascending (by title)
NLucuab May 11, 2021
e07e578
adds sort logic for descending (by title)
NLucuab May 11, 2021
a1852c2
sets up "mark complete" logic for PATCH call
NLucuab May 11, 2021
2c3c6f3
adds mark_complete endpoint logic
NLucuab May 11, 2021
bd3debe
adds "mark incomplete" logic
NLucuab May 11, 2021
a0dabbd
adds slack bot function
NLucuab May 12, 2021
99bac13
adds column 'title' to goal and runs migrations
NLucuab May 13, 2021
4144db2
sets up goals blueprint
NLucuab May 13, 2021
b1a06c4
adds goal routes for POST & GET calls
NLucuab May 13, 2021
e37df34
adds logic for Goal DELETE & PUT calls
NLucuab May 13, 2021
0f42ef8
sets up one-to-many relationship btw Goal & Task
NLucuab May 13, 2021
eb303bd
POST logic for "/<goal_id>/tasks" endpoint
NLucuab May 13, 2021
bba404f
adds GET logic for one-to-many relationship
NLucuab May 13, 2021
abad9e9
adds conditional for to_json Task function
NLucuab May 13, 2021
67bf815
fixes typo that was causing mapper error
NLucuab May 13, 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()'
20 changes: 12 additions & 8 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@
import os
from dotenv import load_dotenv


db = SQLAlchemy()
migrate = Migrate()
load_dotenv()


def create_app(test_config=None):
app = Flask(__name__)
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

if test_config is None:
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_DATABASE_URI")
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
'SQLALCHEMY_DATABASE_URI')
else:
app.config["TESTING"] = True
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_TEST_DATABASE_URI")
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
'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)
load_dotenv()

# Register Blueprints here
from .routes import tasks_bp
app.register_blueprint(tasks_bp)

from .routes import goals_bp
app.register_blueprint(goals_bp)

return app
12 changes: 10 additions & 2 deletions app/models/goal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from flask import current_app
from sqlalchemy.orm import backref
from app import db


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

def goal_json(self):

Choose a reason for hiding this comment

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

👍 love to see some helper methods!

return {
"id": self.goal_id,
"title": self.title
}
28 changes: 26 additions & 2 deletions app/models/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
from flask import current_app
from app import db

from sqlalchemy import DateTime
from app.models.goal import Goal

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

# creates a dictionary of key-value pairs describing the given task
def to_json(self):

Choose a reason for hiding this comment

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

👍

# Wave 6: need to create a conditional for "goal_id"
if self.goaltask_id == None:
return {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": False if self.completed_at is None else True
}
else:
return{
"id": self.task_id,
"goal_id": self.goaltask_id,
"title": self.title,
"description": self.description,
"is_complete": False if self.completed_at is None else True
}
Loading