"""Query parameters used to sort users.""" from enum import Enum from sqlalchemy import Column from todo.models.users import User from todo.dependencies.common import PaginationParams, SortOrder class SortableUserField(Enum): """Defines which fields user lists can be sorted on.""" id = 'id' email = 'email' created = 'created' updated = 'updated' first_name = 'first_name' last_name = 'last_name' is_admin = 'is_admin' @property def field(self) -> Column: return getattr(User, self.value) class UserSortablePaginationParams(PaginationParams): def __init__( self, skip: int = 0, limit: int = 100, sortby: SortableUserField = SortableUserField['id'], sortorder: SortOrder = SortOrder['asc'], ): super().__init__(skip=skip, limit=limit) self.sortby = sortby self.sortorder = sortorder