-
Notifications
You must be signed in to change notification settings - Fork 36
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
Kunzite 2 - Angie, Danica, Alejandra #7
base: main
Are you sure you want to change the base?
Conversation
…and PUT endpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very light bit of feedback.
owner=board_data["owner"] | ||
) | ||
except (ValueError, KeyError): | ||
abort(make_response(jsonify({"details": "Invalid data"}), 400)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually, the three flask functions here are at a different "layer" of the backend logic. Models are at a pretty low layer (they're far from the incoming request) while the endpoints are at a higher layer (they are aware of flask and endpoints and all that). We should try to minimize unnecessary dependencies where possible, with special emphasis on avoiding cases where a lower layer depends on a higher layer.
Remember that one of the key benefits of errors is that they allow us to separate the concerns of reporting that something has gone wrong, and resolving that situation. This lets us move the resolution code to places that have more context.
Here, we should avoid importing abort
, make_response
, and jsonify
fromflask
and not hanlde the error here. We should let the errors escape the function, and put the error handling closer to the endpoint code. This needn't be directly in and endpoint. Rather, it could be in a helper function that "lives" at the same layer as endpoints.
def get_id(entry): | ||
return entry['board_id'] | ||
|
||
boards_response.sort(key=get_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using sort
, we can have the database return the records in sorted order to begin with by using order_by
on the Board.query
.
cards_bp = Blueprint("cards", __name__, url_prefix="/cards") | ||
|
||
|
||
@cards_bp.route("/<card_id>/like", methods=["PUT"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels more like a PATCH method to me, since we're not replacing the entire resource.
No description provided.