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

Amethyst - Abby Goodman #129

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Amethyst - Abby Goodman #129

wants to merge 13 commits into from

Conversation

argoodm
Copy link

@argoodm argoodm commented May 18, 2023

No description provided.

Comment on lines 4 to +7
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", back_populates="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 completing Task List Abby! 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 +13 to +18
def from_dict(cls, goal_data):
new_goal = Goal(
title=goal_data["title"]
)

return new_goal

Choose a reason for hiding this comment

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

I noticed you created this class method but didn't make use of it

Comment on lines 4 to +10
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) #when refactoring change to varchar
description = db.Column(db.String) # when refacoring change to varvhar
completed_at = db.Column(db.DateTime, default=None, nullable=True)
goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'))
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?

Comment on lines +14 to +21
def from_dict(cls, task_data):
new_task = Task(
title=task_data["title"],
description=task_data["description"],
completed_at=task_data["completed_at"]
)

return new_task

Choose a reason for hiding this comment

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

I noticed you created this class method but didn't make use of it

"id":self.task_id,
"title":self.title,
"description":self.description,
"is_complete": True if self.completed_at else False}}

Choose a reason for hiding this comment

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

👍🏾

Comment on lines +35 to +38
from .routes import task_list_bp
app.register_blueprint(task_list_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.

Great work registering these blueprints ✅

@@ -15,8 +15,10 @@ def create_app(test_config=None):
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("RENDER_DB_URI")

Choose a reason for hiding this comment

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

👍🏾

@@ -30,5 +32,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

import requests
import json
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

from app.models.task import Task
from app.models.goal import Goal
from flask import Blueprint, jsonify, make_response, request, abort

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 +15 to +23
try:
task_id = int(task_id)
except:
abort(make_response({"message": f"Task {task_id} invalid"}, 400))
task = Task.query.get(task_id)
if not task:
abort(make_response({"details": "Invalid Data"}, 404))
return task

Choose a reason for hiding this comment

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

Nice approach to handling an invalid task 😁

Comment on lines +26 to +34
try:
goal_id = int(goal_id)
except:
abort(make_response({"message": f"Goal {goal_id} invalid"}, 400))
goal = Goal.query.get(goal_id)
if not goal:
abort(make_response({"details": "Invalid Data"}, 404))
return goal

Choose a reason for hiding this comment

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

Nice approach to handling an invalid goal 😁 There's a bunch of repeated code here, any ideas of how to refactor?

title = request_body["title"],
description = request_body["description"],
# completed_at = request_body["completed_at"]

Choose a reason for hiding this comment

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

It’s good practice to avoid committing commented out code when submitting a PR.

Comment on lines +47 to +48
db.session.commit()

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 +205 to +221
task = validate_task(task_id)
task.completed_at = datetime.now()
#slack implementation
url = "https://slack.com/api/chat.postMessage"
payload = json.dumps({
"channel": "C0581AUJACV",
"text": (f"Someone just completed the task {task.title}")
})
headers = {
'Authorization': os.environ.get("SLACK_API_TOKEN"),
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
db.session.commit()
return task.to_dict(), 200

Choose a reason for hiding this comment

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

This function is pretty packed, for readability I suggest using more spacing in between lines. Something like this:

def update_task_to_complete(task_id):
    task = validate_task(task_id)
    task.completed_at = datetime.now()
    
    #slack implementation
    url = "https://slack.com/api/chat.postMessage"

    payload = json.dumps({
        "channel": "C0581AUJACV",
        "text": (f"Someone just completed the task {task.title}")
    })

    headers = {
        'Authorization': os.environ.get("SLACK_API_TOKEN"),
        'Content-Type': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text)

    db.session.commit()

    return task.to_dict(), 200

@ameerrah9 ameerrah9 changed the title pull request Amethyst - Abby Goodman May 22, 2023
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