Repository navigation
pull request for code review - #39
Conversation
CookieLynx
left a comment
There was a problem hiding this comment.
Looking good for the saving part!
One thing I would add is saving it to a temp directory before saving over our original files. That way, in the event of an error or power loss while writing the file, we don't end up with a broken JSON file we can no longer read from. Simply saving the new JSON to a temp file and then overriding the original save location after it's been written to should work!
I won't say much about the menu stuff yet, but the schema so far looks good!
|
Saving looks good, the temp file + replace is nice and the save error tests are good. Since this is still in progress maybe mark it as a draft? Some things I noticed while testing:
|
|
Commits done and ready for review! Implementing menu item management adds support to:
Added tests for:
Closes #34 |
CookieLynx
left a comment
There was a problem hiding this comment.
The JSON saving looks good!
The create, delete and modify menu item endpoint correctly requires the restaurant ID but also requires an ambiguous menu_section_id that is not given to the user anywhere, there currently is no way for a user to make a new menu section. This also raises questions about our current data files, as they include menuSections, and those can have menu sections as children as well. If it is possible, we should currently ignore menu sections in our endpoints completely since the user has no way of creating a menu section in their new restaurant and then no way to make a menu item since it is required in the creation. This will mean editing the menu schema to not include menu sections but just menu items list. but this may have issues with the loading of the restaurants JSON we curently have.
Alternatively, you can implement the creation of a menu section for a restaurant and from there the user can get the id of the menu section from the /restaurants/{their ID} allow the user to create a menu item but I suggest we leave this until later.
Overall I think this requires a quick dicussion between us for what to do about it.
The last thing I would recommend is adding model_config = ConfigDict(extra="forbid", str_strip_whitespace=True) to each MenuItemCreate and MenutItemUpdate classes like the restaurant create schema in main branch currently has.
Testing is great!
Overall looking good to me! Otherwise, I approve.
|
I agree the menu_section_id requirement is awkward because owners currently can't create or discover sections through the owner workflow. I added the ConfigDict(extra="forbid", str_strip_whitespace=True) validation. For the section design I think our options are between simplifying Menu to directly contain menu items for M1, keeping sections and adding section endpoints, or keeping sections internally but hiding the section ID from the menu-item API and using a default/top level section. The last option might be best if we want minimal schema and data changes. |
…n and fix conflicts
|
I recommend that we currently remove the need for a menu_section_id in the endpoint for creating a menu item for now, since it will be required due to our schema and JSON reading logic. I recommend that you create an "uncategorized" section with a hardcoded ID you reuse for every item's creation on the backend. Later, when we do more functions, we can add the ability to make menu sections but for now I think this is a good middle ground to not cause us to fix sections but also have it match our current schemas. |
|
removed the need for menu_section_id in the endpoint for creating menu item, should I make update and delete independent from section as well? |
sonoftirit
left a comment
There was a problem hiding this comment.
Nice, the uncategorized section works and the [None, item] fix is good. One problem though: if a restaurant has no menu (hasMenu is None), adding an item crashes with a 500 because of restaurant.hasMenu.hasMenuSection. That's every restaurant created with my POST /restaurants, since new ones start with no menu. Could _get_or_create_uncategorized_section create an empty Menu first when hasMenu is None?
And yes, I'd make update and delete not need the section too, item ids are unique so it'd be consistent with create. Also a blank name and a negative price still get accepted, maybe add min_length=1 on name and ge=0 on price.
pull request for teammates to view the code, my work is still incomplete but should addressed issue #27