mirror of
https://github.com/hay-kot/mealie.git
synced 2025-07-16 10:03:54 -07:00
rewrite get_all routes to use a pagination pattern to allow for better implementations of search, filter, and sorting on the frontend or by any client without fetching all the data. Additionally we added a CI check for running the Nuxt built to confirm that no TS errors were present. Finally, I had to remove the header support for the Shopping lists as the browser caching based off last_updated header was not allowing it to read recent updates due to how we're handling the updated_at property in the database with nested fields. This will have to be looked at in the future to reimplement. I'm unsure how many other routes have a similar issue. Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
from functools import cached_property
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import UUID4
|
|
|
|
from mealie.routes._base.base_controllers import BaseUserController
|
|
from mealie.routes._base.controller import controller
|
|
from mealie.routes._base.mixins import HttpRepo
|
|
from mealie.schema import mapper
|
|
from mealie.schema.group.webhook import CreateWebhook, ReadWebhook, SaveWebhook, WebhookPagination
|
|
from mealie.schema.response.pagination import PaginationQuery
|
|
|
|
router = APIRouter(prefix="/groups/webhooks", tags=["Groups: Webhooks"])
|
|
|
|
|
|
@controller(router)
|
|
class ReadWebhookController(BaseUserController):
|
|
@cached_property
|
|
def repo(self):
|
|
return self.repos.webhooks.by_group(self.group_id)
|
|
|
|
@property
|
|
def mixins(self) -> HttpRepo:
|
|
return HttpRepo[CreateWebhook, SaveWebhook, CreateWebhook](self.repo, self.deps.logger)
|
|
|
|
@router.get("", response_model=WebhookPagination)
|
|
def get_all(self, q: PaginationQuery = Depends(PaginationQuery)):
|
|
response = self.repo.page_all(
|
|
pagination=q,
|
|
override=ReadWebhook,
|
|
)
|
|
|
|
response.set_pagination_guides(router.url_path_for("get_all"), q.dict())
|
|
return response
|
|
|
|
@router.post("", response_model=ReadWebhook, status_code=201)
|
|
def create_one(self, data: CreateWebhook):
|
|
save = mapper.cast(data, SaveWebhook, group_id=self.group.id)
|
|
return self.mixins.create_one(save)
|
|
|
|
@router.get("/{item_id}", response_model=ReadWebhook)
|
|
def get_one(self, item_id: UUID4):
|
|
return self.mixins.get_one(item_id)
|
|
|
|
@router.put("/{item_id}", response_model=ReadWebhook)
|
|
def update_one(self, item_id: UUID4, data: CreateWebhook):
|
|
return self.mixins.update_one(data, item_id)
|
|
|
|
@router.delete("/{item_id}", response_model=ReadWebhook)
|
|
def delete_one(self, item_id: UUID4):
|
|
return self.mixins.delete_one(item_id) # type: ignore
|