Skip to content

Task List, C17 Sea Turtles, Shelby Faulconer #97

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 12 commits into
base: master
Choose a base branch
from

Conversation

pickled-bot
Copy link

:) yay, Task List

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

Great work pulling together many concepts in this project Shelby! Check out the feedback when you have time and reach out if you have questions or need clarifications on any of the feedback 😊

# import requests
# from urllib import response
from flask import Blueprint, jsonify, abort, make_response, request
from sqlalchemy import desc

Choose a reason for hiding this comment

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

It looks like the import desc isn't used in goal_routes.py, so we should remove it as part of our code cleanup and refactor steps.

Comment on lines +26 to +27
response_body = make_response(jsonify({"details": "Invalid data"}), 400)
return response_body

Choose a reason for hiding this comment

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

Since we don't perform actions with response_body before returning it, I'd recommend returning on the same line rather than creating a variable. If the goal is to break things up for readability, I'd consider breaking out the message to a variable:

response_body = {"details": "Invalid data"}
return make_response(jsonify(response_body), 400)

We might also want to give the user more information to help them debug. It could be as little as adding what key was missing:

response_body = {"details": "Invalid data: missing 'title'"}

Comment on lines +31 to +32


Choose a reason for hiding this comment

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

To be consistent with whitespace inside functions, I recommend removing one of the new lines both here and above goal.

Comment on lines +45 to +47



Choose a reason for hiding this comment

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

One of the things to look at when we are in our code clean up phase is whitespace across a file. The general guideline is one newline between functions inside of a class, but what's most important is to be consistent across a codebase. A little extra whitespace is often used as a visual separation between groups of related functions, or to make it clear where imports end and implementation code begins. We lose the ability to have a visual separation have meaning if we are not consistent with how they are applied. The PEP 8 style guide has a little more info on their recommendations: https://peps.python.org/pep-0008/#blank-lines

Comment on lines +51 to +52
# response_body = dict()
# response_body = goal.to_dictionary()

Choose a reason for hiding this comment

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

We want to make sure to delete commented out code as part of clean up. When we are sharing a codebase with other folks, it's unclear what the intention of commented out code is, especially without extra comments explaining why it's there. We use versioning tools like git so we can confidently delete code and view our commit history to recover code if we ever need to revert back to something we had prior.

##CRUD
##CREATE : POST
@goals_bp.route("", methods=["POST"])
def manage_post_goals():

Choose a reason for hiding this comment

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

To me, manage_post_goals doesn't feel very specific about what work this function performs. What's a name that reflects the effects of the function, so someone wouldn't need to read the function internals to know what it does?

Comment on lines +84 to +89

if "title" in task_keys:
task.title = request_body["title"]
if "description" in task_keys:
task.description = request_body["description"]

Choose a reason for hiding this comment

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

Nice handling for partial updates!

What you have here is what I did in roundtable, but we could omit the line task_keys = request_body.keys() if we wanted. The syntax <string> in <dict> by default checks the dictionary keys, so this could also be written:

    if "title" in request_body:
        task.title = request_body["title"]
    if "description" in request_body:
        task.description = request_body["description"]

db.session.commit()

return make_response(jsonify({"details": f"Task {task.id} \"{task.title}\" successfully deleted"}), 200)

Choose a reason for hiding this comment

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

To be consistent with the PEP 8 style guide recommendations for line length, we would want to split this across a couple lines. One approach would be to separate out the dictionary to a variable then pass that variable into jsonify on this line.

Comment on lines +108 to +121
text = f"Someone just completed the task {task.title}"
channel_id = "C03ENLYJ7AT"

path = f"https://slack.com/api/chat.postMessage?channel={channel_id}&text={text}"

headers = {"Authorization": api_key}

task.completed_at = datetime.date.today()

db.session.commit()

response_body = {"task":task.to_dictionary()}
response = requests.post(path, headers=headers)

Choose a reason for hiding this comment

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

I would consider some gentle reorganization and changing of whitespace to group together the related operations in this function

    # Update task in DB
    task = get_task(id)
    task.completed_at = datetime.date.today()
    db.session.commit()
    
    # Gather info for Slack API call and send POST
    text = f"Someone just completed the task {task.title}"
    channel_id = "C03ENLYJ7AT"
    path = f"https://slack.com/api/chat.postMessage?channel={channel_id}&text={text}"
    headers = {"Authorization": api_key}
    requests.post(path, headers=headers)

    # Return the updated task info
    return {"task":task.to_dictionary()}

Comment on lines +128 to +136

task.completed_at = None

db.session.commit()

response_body = {"task":task.to_dictionary()}

return response_body

Choose a reason for hiding this comment

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

We would want to remove most of the whitespace in this function since it's separating lines that are tightly related to each other. This applies to other functions across the project with similar spacing. An example of what this could look like is:

    task = get_task(id)
    task.completed_at = None
    db.session.commit()

    return {"task":task.to_dictionary()}


tasks_bp = Blueprint("tasks_bp", __name__, url_prefix="/tasks")
api_key = os.environ.get("BOT_API_KEY")

Choose a reason for hiding this comment

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

Since api_key is only used in update_task_mark_complete_by_id we would want to declare it inside that function rather than giving it global scope where all functions have access to it.

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