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

Feature: Shopping List Item Pagination Route #2145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mealie/routes/groups/controller_shopping_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ShoppingListCreate,
ShoppingListItemCreate,
ShoppingListItemOut,
ShoppingListItemPagination,
ShoppingListItemsCollectionOut,
ShoppingListItemUpdate,
ShoppingListItemUpdateBulk,
Expand Down Expand Up @@ -101,6 +102,12 @@ def mixins(self):
self.logger,
)

@item_router.get("", response_model=ShoppingListItemPagination)
def get_all(self, q: PaginationQuery = Depends()):
response = self.repo.page_all(pagination=q, override=ShoppingListItemOut)
response.set_pagination_guides(router.url_path_for("get_all"), q.dict())
return response

@item_router.post("/create-bulk", response_model=ShoppingListItemsCollectionOut, status_code=201)
def create_many(self, data: list[ShoppingListItemCreate]):
items = self.service.bulk_create_items(data)
Expand Down
4 changes: 4 additions & 0 deletions mealie/schema/group/group_shopping_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class ShoppingListItemsCollectionOut(MealieModel):
deleted_items: list[ShoppingListItemOut] = []


class ShoppingListItemPagination(PaginationBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

There really is no need for this, since PaginationBase is generic to begin with and this subclass doesnt add anything in particular. You can just use PaginationBase[ShoppingListItemOut] instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah the only reason I added it is because we have them for all other get_all routes, so I wanted to keep it consistent with the rest of the code base

items: list[ShoppingListItemOut]


class ShoppingListCreate(MealieModel):
name: str | None = None
extras: dict | None = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def test_shopping_list_items_get_one(
assert response.status_code == 200


def test_shopping_list_items_get_all(
api_client: TestClient,
unique_user: TestUser,
list_with_items: ShoppingListOut,
) -> None:
params = {"page": 1, "perPage": -1, "queryFilter": f"shopping_list_id={list_with_items.id}"}
response = api_client.get(api_routes.groups_shopping_items, params=params, headers=unique_user.token)
pagination_json = utils.assert_derserialize(response, 200)
assert len(pagination_json["items"]) == len(list_with_items.list_items)


def test_shopping_list_items_get_one_404(api_client: TestClient, unique_user: TestUser) -> None:
response = api_client.get(api_routes.groups_shopping_items_item_id(uuid4()), headers=unique_user.token)
assert response.status_code == 404
Expand Down