Conversation
…request to slack api
| from app import db | ||
|
|
||
|
|
||
| class Goal(db.Model): |
There was a problem hiding this comment.
Great job completing Task List Hannah! 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.
| def to_dict(self): | ||
| return{ | ||
| "id": self.goal_id, | ||
| "title": self.title, | ||
| } |
There was a problem hiding this comment.
Great job creating this reusable helper function
| goal_id = db.Column(db.Integer, db.ForeignKey("goal.goal_id"), nullable=True) | ||
| goal = db.relationship("Goal", back) |
There was a problem hiding this comment.
Nice approach creating this relationship to your Goal model.
| from app.routes import tasks_bp | ||
| from app.routes import goals_bp | ||
| app.register_blueprint(tasks_bp) | ||
| app.register_blueprint(goals_bp) |
There was a problem hiding this comment.
Great work registering these blueprints ✅
| @@ -1 +1,306 @@ | |||
| from flask import Blueprint No newline at end of file | |||
| from flask import Blueprint, jsonify, request | |||
There was a problem hiding this comment.
👍🏾 These imports help a great deal when it comes to our request & response cycle
| if sort == "asc": | ||
| tasks = Task.query.order_by(Task.title.asc()).all() | ||
| elif sort == "desc": | ||
| tasks = Task.query.order_by(Task.title.desc()).all() | ||
| else: |
There was a problem hiding this comment.
Great job with this query param logic
| completed_at = request_body.get("completed_at") | ||
| ) | ||
|
|
||
| db.session.add(new_task) |
There was a problem hiding this comment.
Great job using db.session.<method-name>. Session gives us access to the follow:
dbis our app’s instance of SQLAlchemy.sessionrepresents our active database connection.- By referencing
db.sessionwe 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
| "description": new_task.description, | ||
| "is_complete": new_task.completed_at != None | ||
| } | ||
| }), 201 |
There was a problem hiding this comment.
Usually a resource creation relates to a 201 response code 👍🏾
|
|
||
| # Assert | ||
| assert response.status_code == 404 | ||
| assert response_body == {"message": "Goal not found"} |
There was a problem hiding this comment.
Nice work with this test completion! This assertion is a great way to validate functionality is working as expected
No description provided.