fastapi-svelte-template/backend/todo/dependencies/todos.py

36 lines
924 B
Python
Raw Normal View History

"""Query parameters used to sort todo-items."""
from enum import Enum
from sqlalchemy import Column
from todo.models.todos import TodoItem
from todo.dependencies.common import PaginationParams, SortOrder
class SortableTodoItemField(Enum):
"""Defines which fields todo-item lists can be sorted on."""
id = 'id'
title = 'title'
done = 'done'
created = 'created'
updated = 'updated'
finished = 'finished'
@property
def field(self) -> Column:
return getattr(TodoItem, self.value)
class TodoItemSortablePaginationParams(PaginationParams):
def __init__(
self,
skip: int = 0, limit: int = 100,
sortby: SortableTodoItemField = SortableTodoItemField['updated'],
sortorder: SortOrder = SortOrder['desc'],
):
super().__init__(skip=skip, limit=limit)
self.sortby = sortby
self.sortorder = sortorder