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

Rock-Leilani Allen #53

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

leilanianiel
Copy link

No description provided.

Copy link

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

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

Great job Leilani! You hit all the learning goals for this project. I'm glad you're finding the value in helper methods/functions and I challenge you to use them in future projects. I provided some refactoring tips, especially about unneeded imports.

Overall, great job and keep up the hard work 👍 🔥 ✨

app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_TEST_DATABASE_URI")
app.config['JSON_SORT_KEYS']=False

Choose a reason for hiding this comment

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

Nice! Flask automatically organizes keys alphabetically so adding this line ensures json are kept in the order you provided. This isn't actually recommended by Flask for performance reasons, but it is a feature.

More info can be found in documentation: https://flask.palletsprojects.com/en/2.0.x/config/#JSON_SORT_KEYS

I also found this stackoverflow answer helpful.

Comment on lines +38 to +42
from .routes import tasks_bp
app.register_blueprint(tasks_bp)

from .routes import goals_bp
app.register_blueprint(goals_bp)

Choose a reason for hiding this comment

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

You can reduce redundancy here by combining imports like so:

Suggested change
from .routes import tasks_bp
app.register_blueprint(tasks_bp)
from .routes import goals_bp
app.register_blueprint(goals_bp)
from .routes import tasks_bp, goals_bp
app.register_blueprint(tasks_bp)
app.register_blueprint(goals_bp)

@@ -1,6 +1,13 @@
from flask import current_app
from app import db
from sqlalchemy import Table, Column, Integer, ForeignKey

Choose a reason for hiding this comment

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

Hm... I'm not sure you needed these imports as Column, Integer, and ForeignKey should be coming from your own instance of SqlAlchemy called db.

class Goal(db.Model):
goal_id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String)
#relating to tasks database
tasks = db.relationship('Task', backref='goal', lazy=True)

Choose a reason for hiding this comment

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

Great job setting up the one-to-many relationship 😄

complete = False
else:
complete = True
return complete

Choose a reason for hiding this comment

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

Nice helper method!




return jsonify({"task": task.display_tasks()}), 201

Choose a reason for hiding this comment

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

good job! 👍


task = Task.query.get(task_id)

if task is None:

Choose a reason for hiding this comment

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

Another way to write these is conditional is:

Suggested change
if task is None:
if not task:


task.completed_at = datetime.now()
db.session.commit()
slack_message(task)

Choose a reason for hiding this comment

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

Nice helper function Leilani 👍 🔥

Comment on lines +170 to +171
"id": goal.goal_id,
"title": goal.title

Choose a reason for hiding this comment

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

💡 Refactor tip: notice how you return the same goal dictionary for GET and POST? I think a helper method to return a dictionary would come in handy here.

"title": goal.title,
"tasks": tasks
} , 200)

Choose a reason for hiding this comment

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

Nice! This looks great Leilani!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants