mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-08 03:15:09 -04:00
Add helper to parse an enum from query args & use it. (#14956)
The `parse_enum` helper pulls an enum value from the query string (by delegating down to the parse_string helper with values generated from the enum). This is used to pull out "f" and "b" in most places and then we thread the resulting Direction enum throughout more code.
This commit is contained in:
parent
230a831c73
commit
1182ae5063
25 changed files with 176 additions and 96 deletions
|
@ -18,7 +18,7 @@ import attr
|
|||
|
||||
from synapse.api.constants import Direction
|
||||
from synapse.api.errors import SynapseError
|
||||
from synapse.http.servlet import parse_integer, parse_string
|
||||
from synapse.http.servlet import parse_enum, parse_integer, parse_string
|
||||
from synapse.http.site import SynapseRequest
|
||||
from synapse.storage.databases.main import DataStore
|
||||
from synapse.types import StreamToken
|
||||
|
@ -44,15 +44,9 @@ class PaginationConfig:
|
|||
store: "DataStore",
|
||||
request: SynapseRequest,
|
||||
default_limit: int,
|
||||
default_dir: str = "f",
|
||||
default_dir: Direction = Direction.FORWARDS,
|
||||
) -> "PaginationConfig":
|
||||
direction_str = parse_string(
|
||||
request,
|
||||
"dir",
|
||||
default=default_dir,
|
||||
allowed_values=[Direction.FORWARDS.value, Direction.BACKWARDS.value],
|
||||
)
|
||||
direction = Direction(direction_str)
|
||||
direction = parse_enum(request, "dir", Direction, default=default_dir)
|
||||
|
||||
from_tok_str = parse_string(request, "from")
|
||||
to_tok_str = parse_string(request, "to")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue