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

Scissors- Marisa M #70

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

Supermobarbie
Copy link

No description provided.

Copy link

@beccaelenzil beccaelenzil 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 on your first Flask project. Your code is clear and logical. Your consistent spacing and indentation made it a pleasure to read. Good use of instance methods on the Task and Goal model to DRY up your code. I've left a few inline comments on ways you could consider refactoring. Please let me know if you have any questions.

return self.completed_at != None


def make_json(self):

Choose a reason for hiding this comment

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

Good use of a helper method. Consider DRYing up your code by building the dictionary

json = 
{"id": self.task_id,                    
"title": self.title,
 "description": self.description,
"is_complete": self.is_complete()}

and conditionally adding the goal_id like this:

if self.goal_id:
    json["goal_id] = self.goal_id

and then returning {"task": json}

Comment on lines +30 to +33
"id": task.task_id,
"title": task.title,
"description": task.description,
"is_complete": task.is_complete()

Choose a reason for hiding this comment

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

We could use the task instance method here task.make_json to DRY up the code and reduce room for errors.

})
return jsonify(tasks_response)

elif request.method == "POST":

Choose a reason for hiding this comment

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

With regards to the point in separating out the functions for each route (that you noted in Learn), this way of organizing your code can increase readability by reducing indentation and making meaningful function names. For instance, if we separate out GET and POST, we might call one function def all_tasks() and the other def create_task().

Comment on lines +53 to +56
task = Task.query.get(task_id)

if task is None:
return make_response("", 404)

Choose a reason for hiding this comment

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

Comment on lines +87 to +95
API_KEY = os.environ.get("API_KEY")
PATH = "https://slack.com/api/chat.postMessage"
query_params = {
"channel": "task-notifications",
"text": f"Someone just completed the task {task.title}."
}
task.completed_at = datetime.utcnow()
db.session.commit()
requests.post(PATH, data=query_params, headers={"Authorization":API_KEY})

Choose a reason for hiding this comment

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

Consider moving this functionality into a helper function increase readability and changeability.

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