Skip to content

Angela Amethyst A19#130

Open
angela100743 wants to merge 10 commits intoAda-C19:mainfrom
angela100743:main
Open

Angela Amethyst A19#130
angela100743 wants to merge 10 commits intoAda-C19:mainfrom
angela100743:main

Conversation

@angela100743
Copy link
Copy Markdown

No description provided.

Comment thread app/models/goal.py
@@ -3,3 +3,13 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job completing Task List Angela! Your code looks clean and easily readable. I want to point out the good variable naming and your code is DRY. Great use of helper methods in your models! Excellent work using blue prints & creating RESTful CRUD routes for each model.

Comment thread app/models/goal.py
Comment on lines +9 to +15
def to_dict(self):
goal_as_dict = {
"id": self.goal_id,
"title": self.title
}

return goal_as_dict No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job creating this reusable helper function`

Comment thread app/models/task.py
Comment on lines +8 to +9
goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'), nullable=True)
goal = db.relationship("Goal", back_populates="tasks")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice approach creating this relationship to your Goal model. Why not use lazy here?

Comment thread app/models/task.py

return task_as_dict


No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like there's some extra whitespace here

Comment thread app/routes.py
@@ -1 +1,235 @@
from flask import Blueprint No newline at end of file
from flask import Flask, Blueprint, jsonify, abort, make_response, request
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏾 These imports help a great deal when it comes to our request & response cycle

Comment thread app/routes.py
Comment on lines +7 to +9
goals_bp = Blueprint("goals", __name__, url_prefix="/goals")
tasks_bp = Blueprint("tasks", __name__, url_prefix="/tasks")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏾

Comment thread app/routes.py
Comment on lines +12 to +23
def validate_model(cls, model_id):
try:
model_id = int(model_id)
except:
abort(make_response({"message": f"{model_id} is not a valid type ({type(model_id)}). Must be an integer)"}, 400))

model = cls.query.get(model_id)

if not model:
abort(make_response({"message": f"{cls.__name__} {model_id} does not exist"}, 404))

return model
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice job creating this reusable function & keeping your code DRY. Nice approach to handling an invalid model 😁

Comment thread app/routes.py

###

@tasks_bp.route("", methods=['POST'])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉

Comment thread app/routes.py
if "completed_at" in request_body:
new_task.completed_at=request_body["completed_at"]

db.session.add(new_task)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job using db.session.<method-name>. Session gives us access to the follow:

  • db is our app’s instance of SQLAlchemy.
  • session represents our active database connection.
  • By referencing db.session we can use SQLAlchemy’s methods to perform tasks like:
    • committing a change to a model
    • storing a new record of a model
    • deleting a record.
  • By referencing db.session.add() you are able to use the SQLAlchemy method to store a new record of the task model

Comment thread app/routes.py
Comment on lines +204 to +214
for task_id in request_body["task_ids"]:
task = validate_model(Task, task_id)
if task not in goal.tasks:
goal.tasks.append(task)


task_ids=[]
for task in goal.tasks:
task_ids.append(task.task_id)

db.session.commit()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread app/__init__.py
@@ -4,19 +4,20 @@
import os
from dotenv import load_dotenv
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great work! We need to import load_dotenv to set up environment variables in our .env file

Comment thread app/__init__.py
Comment on lines 7 to 9
db = SQLAlchemy()
migrate = Migrate()
load_dotenv()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉

Comment thread app/__init__.py
from dotenv import load_dotenv


db = SQLAlchemy()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you remember what this does?

Comment thread app/__init__.py
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

if test_config is None:
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do we need this line?

Comment thread app/__init__.py
@@ -30,5 +31,9 @@ def create_app(test_config=None):
migrate.init_app(app, db)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job! We need to pass our instance of our app & the instance of our SQLALchemy db to connect the db and migrate to our Flask app

Comment thread app/__init__.py
Comment on lines 33 to +37
# Register Blueprints here
from .routes import goals_bp
app.register_blueprint(goals_bp)
from .routes import tasks_bp
app.register_blueprint(tasks_bp)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great work registering these blueprints ✅

Comment thread tests/test_wave_01.py
Comment on lines 61 to +63
assert response.status_code == 404
assert "message" in response_body
assert response_body["message"] == "Task 1 does not exist"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work with this test completion! This assertion is a great way to validate functionality is working as expected

Comment thread app/routes.py
Comment on lines +142 to +144
return {
"goal": new_goal.to_dict()
}, 201
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Usually a resource creation relates to a 201 response code 👍🏾

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