Skip to content

C22 Sphinx - Brianna R. #37

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

C22 Sphinx - Brianna R. #37

wants to merge 29 commits into from

Conversation

bri-root
Copy link

@bri-root bri-root commented Nov 8, 2024

No description provided.

…or 400 invalid response and 404 not found response.
Copy link

@mikellewade mikellewade left a comment

Choose a reason for hiding this comment

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

Nice work overall, Brianna! Though I would like for you to read through the comments to see the ones I left about refactoring. There are a lot of places where you could have DRY'd up your code. Refactoring is a big part of this project because it helps train your eye for seeing similarities in your codebase as well as practicing maintainability and scalability.

Comment on lines +5 to +6
from .routes.task_routes import tasks_bp
from .routes.goal_routes import goals_bp

Choose a reason for hiding this comment

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

Don't forget that the convention for naming blueprints is to name them bp. With each blueprint being named the same thing we will need to import them under an alias like so:

from .routes.task_routes import bp as tasks_bp


class Goal(db.Model):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str]
tasks: Mapped[list["Task"]] = relationship(back_populates="goal")

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 +16
title: Mapped[str]
description: Mapped[str]
completed_at: Mapped[Optional[datetime]] = mapped_column(nullable=True)
goal_id: Mapped[Optional[int]] = mapped_column(ForeignKey("goal.id"))
goal: Mapped[Optional["Goal"]] = relationship(back_populates="tasks")

Choose a reason for hiding this comment

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

👍🏿

"id":self.id,
"title":self.title,
"description":self.description,
"is_complete":self.completed_at is not None,

Choose a reason for hiding this comment

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

Nice work here!


@classmethod
def from_dict(cls, task_data):
completed_at = datetime if task_data.get("is_complete", False) else None

Choose a reason for hiding this comment

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

Comment on lines +19 to +28
try:
new_task = Task.from_dict(request_body)

except KeyError as e:
response = {"details": "Invalid data"}
abort(make_response(response, 400))

db.session.add(new_task)
db.session.commit()

Choose a reason for hiding this comment

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

Another place that is a sign for us to refactor this logic like in our previous create route.

Comment on lines +87 to +94

task.mark_complete()
db.session.commit()

post_to_slack(task)

return {"task": task.to_dict()}, 200

Choose a reason for hiding this comment

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

Comment on lines +108 to +142
try:
task_id = int(task_id)
except:
response = {"message": f"task {task_id} invalid"}
abort(make_response(response , 400))

query = db.select(Task).where(Task.id == task_id)
task = db.session.scalar(query)

if not task:
response = {"message": "task not found"}
abort(make_response(response, 404))
return task

def post_to_slack(task):
headers = {
"Authorization": f"Bearer {SLACK_API_TOKEN}",
"Content-Type": "application/json",

}
if task.completed_at:
data = {
"text": f"Task '{task.title}' has been marked complete",
"channel": "C080MLHBX5W",
}
else:
data = {
"text": f"Task '{task.title}' has been marked incomplete",
"channel": "C080MLHBX5W",
}

r = requests.post(SLACK_API_URL, headers=headers, json=data)

return r

Choose a reason for hiding this comment

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

Both of these functions could live in our utilities file to better separate the concerns of our files.

Comment on lines +62 to +64
assert response_body == {
"message": "task not found"
}

Choose a reason for hiding this comment

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

Great work!

Comment on lines +93 to +106
response = client.put("/goals/1", json={
"title": "Build a habit of going outside daily"
})
# Assert
response_body = response.get_json()
# ---- Complete Assertions Here ----
# assertion 1 goes here
# assertion 2 goes here
# assertion 3 goes here
assert response.status_code == 200
assert "goal" in response_body
assert response_body == {
"goal" : {
"id": 1,
"title": "Build a habit of going outside daily"
}
}

Choose a reason for hiding this comment

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

Nice test, very robust!

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.

3 participants