auth response and error codes imp
This commit is contained in:
@@ -6,7 +6,9 @@ including pagination, ordering, and complex query building.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Any, TypeVar, Type
|
||||
from typing import Any, TypeVar, Type, Union
|
||||
|
||||
from sqlalchemy import ColumnExpressionArgument
|
||||
from sqlalchemy.orm import Query, Session
|
||||
from sqlalchemy.sql.elements import BinaryExpression
|
||||
|
||||
@@ -103,10 +105,8 @@ class QueryModel(ArgumentModel):
|
||||
@classmethod
|
||||
def filter_one(
|
||||
cls: Type[T],
|
||||
*args: Any,
|
||||
*args: Union[BinaryExpression, ColumnExpressionArgument],
|
||||
db: Session,
|
||||
system: bool = False,
|
||||
expired: bool = False,
|
||||
) -> PostgresResponse:
|
||||
"""
|
||||
Filter single record by expressions.
|
||||
@@ -120,10 +120,19 @@ class QueryModel(ArgumentModel):
|
||||
Returns:
|
||||
Query response with single record
|
||||
"""
|
||||
if not system:
|
||||
args = cls.get_active_and_confirmed_query_arg(args)
|
||||
if not expired:
|
||||
args = cls.get_not_expired_query_arg(args)
|
||||
args = cls.get_active_and_confirmed_query_arg(args)
|
||||
args = cls.get_not_expired_query_arg(args)
|
||||
query = cls._query(db=db).filter(*args)
|
||||
return PostgresResponse(
|
||||
pre_query=cls._query(db=db), query=query, is_array=False
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def filter_one_system(
|
||||
cls,
|
||||
*args: Union[BinaryExpression, ColumnExpressionArgument],
|
||||
db: Session,
|
||||
):
|
||||
query = cls._query(db=db).filter(*args)
|
||||
return PostgresResponse(
|
||||
pre_query=cls._query(db=db), query=query, is_array=False
|
||||
@@ -131,7 +140,7 @@ class QueryModel(ArgumentModel):
|
||||
|
||||
@classmethod
|
||||
def filter_all_system(
|
||||
cls: Type[T], *args: BinaryExpression, db: Session
|
||||
cls: Type[T], *args: Union[BinaryExpression, ColumnExpressionArgument], db: Session
|
||||
) -> PostgresResponse:
|
||||
"""
|
||||
Filter multiple records by expressions without status filtering.
|
||||
@@ -143,12 +152,13 @@ class QueryModel(ArgumentModel):
|
||||
Returns:
|
||||
Query response with matching records
|
||||
"""
|
||||
|
||||
query = cls._query(db)
|
||||
query = query.filter(*args)
|
||||
return PostgresResponse(pre_query=cls._query(db), query=query, is_array=True)
|
||||
|
||||
@classmethod
|
||||
def filter_all(cls: Type[T], *args: Any, db: Session) -> PostgresResponse:
|
||||
def filter_all(cls: Type[T], *args: Union[BinaryExpression, ColumnExpressionArgument], db: Session) -> PostgresResponse:
|
||||
"""
|
||||
Filter multiple records by expressions.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user