Skip to content

Angela Amethyst A19 #130

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 10 commits into
base: main
Choose a base branch
from
Open

Angela Amethyst A19 #130

wants to merge 10 commits into from

Conversation

angela100743
Copy link

No description provided.

@@ -3,3 +3,13 @@

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 on lines +9 to +15
def to_dict(self):
goal_as_dict = {
"id": self.goal_id,
"title": self.title
}

return goal_as_dict

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 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")

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?


return task_as_dict


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

from flask import Flask, Blueprint, jsonify, abort, make_response, request

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 on lines +7 to +9
tasks_bp = Blueprint("tasks", __name__, url_prefix="/tasks")

Choose a reason for hiding this comment

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

👍🏾

Comment on lines +12 to +23
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

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 😁

###

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

Choose a reason for hiding this comment

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

🎉

new_task.completed_at=request_body["completed_at"]

db.session.add(new_task)

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 on lines +204 to +214
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()

Choose a reason for hiding this comment

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

@@ -4,19 +4,20 @@
import os
from dotenv import load_dotenv

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 on lines 7 to 9
db = SQLAlchemy()
migrate = Migrate()
load_dotenv()

Choose a reason for hiding this comment

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

🎉

@@ -4,19 +4,20 @@
import os
from dotenv import load_dotenv


db = SQLAlchemy()

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?

app = Flask(__name__)

app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

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

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?

@@ -30,5 +31,9 @@ def create_app(test_config=None):
migrate.init_app(app, db)

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 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)

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 on lines 61 to +63
assert response.status_code == 404
assert "message" in response_body
assert response_body["message"] == "Task 1 does not exist"

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 on lines +142 to +144
"goal": new_goal.to_dict()
}, 201

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