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

Add, Update and Delete shopping items #168

Merged
merged 11 commits into from
Jun 29, 2024

Conversation

andrew-codechimp
Copy link
Contributor

Proposed Changes

Implemented the shopping item mutation methods and basic tests.

Related Issues

N/A

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.56%. Comparing base (ed1ec6f) to head (67a5306).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
+ Coverage   96.80%   99.56%   +2.75%     
==========================================
  Files           4        4              
  Lines         188      230      +42     
  Branches       21       23       +2     
==========================================
+ Hits          182      229      +47     
+ Misses          4        1       -3     
+ Partials        2        0       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joostlek joostlek added the new-feature New features or options. label Jun 27, 2024
andrew-codechimp and others added 5 commits June 28, 2024 16:09
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…ions

# Conflicts:
#	poetry.lock
Comment on lines 131 to 159
class ShoppingItem(DataClassORJSONMixin, DataClassDictMixin):
"""ShoppingItem model."""

item_id: str = field(metadata=field_options(alias="id"))
list_id: str = field(metadata=field_options(alias="shoppingListId"))
note: str
display: str
checked: bool
position: int
is_food: bool = field(metadata=field_options(alias="isFood"))
disable_amount: bool = field(metadata=field_options(alias="disableAmount"))
quantity: float
label_id: str = field(metadata=field_options(alias="labelId"))
food_id: str = field(metadata=field_options(alias="foodId"))
unit_id: str = field(metadata=field_options(alias="unitId"))
item_id: Optional[str] = field(default=None, metadata=field_options(alias="id"))
list_id: Optional[str] = field(
default=None, metadata=field_options(alias="shoppingListId")
)
note: Optional[str] = field(default=None)
display: Optional[str] = field(default=None)
checked: Optional[bool] = field(default=None)
position: Optional[int] = field(default=None)
is_food: Optional[bool] = field(
default=None, metadata=field_options(alias="isFood")
)
disable_amount: Optional[bool] = field(
default=None, metadata=field_options(alias="disableAmount")
)
quantity: Optional[float] = field(default=None)
label_id: Optional[str] = field(
default=None, metadata=field_options(alias="labelId")
)
food_id: Optional[str] = field(default=None, metadata=field_options(alias="foodId"))
unit_id: Optional[str] = field(default=None, metadata=field_options(alias="unitId"))

class Config(BaseConfig): # pylint: disable=too-few-public-methods
"""Mashumaro Config."""

serialize_by_alias = True
code_generation_options = ["TO_DICT_ADD_OMIT_NONE_FLAG"]
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I think it would be better if we split the objects and have a CreateShoppingItem object. This would save us a lot of assert item.something in the code because everything is now nullable.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did start off with two but thought it was duplicating it. The CreateShoppingItem would still need all the optional/default none.
Where are you thinking the asserts will be need, on the get list?
Also CreateShoppingItem would also be used for Updates, so any suggestion on a better name?

Copy link
Owner

Choose a reason for hiding this comment

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

MutateShoppingItem

It's more that if we want to use it in Home assistant, that if we want to use the value where they need a str, the value we have currently is typed str | None, so we have to assert something is not None before mypy sees it as str.

Also, please use the union type over the Optional str | None > Optional[str]

Comment on lines 155 to 158
note: str | None = field(default=None)
display: str | None = field(default=None)
checked: bool | None = field(default=None)
position: int | None = field(default=None)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
note: str | None = field(default=None)
display: str | None = field(default=None)
checked: bool | None = field(default=None)
position: int | None = field(default=None)
note: str | None = None
display: str | None = None
checked: bool | None = None
position: int | None = None

I know this works to set it as None, but not sure if this works the same with code_generation_options = ["TO_DICT_ADD_OMIT_NONE_FLAG"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll test it out, I have a bodged version of the lib in my own integration to try this stuff.

METH_POST,
headers=HEADERS,
params=None,
json=item.to_dict(omit_none=True),
Copy link
Owner

Choose a reason for hiding this comment

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

Let's assert the raw dict here so we are directly testing what mealie is receiving. This also helps testing the changes mashumaro can make.

…ions

# Conflicts:
#	src/aiomealie/models.py
@joostlek joostlek merged commit 96adee6 into joostlek:main Jun 29, 2024
11 checks passed
@andrew-codechimp andrew-codechimp deleted the shopping-item-mutations branch June 29, 2024 09:49
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-feature New features or options.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants