-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factorize getting the request parameters length and offset (#1934)
* Extract function get_request_parameter_offset * Align offset error messages * Move get_request_parameter_offset to libapi * Extract function get_request_parameter_length * Align length error messages * Add too large length error to openapi.json * Move get_request_parameter_length to libapi
- Loading branch information
1 parent
54ebe02
commit 487b578
Showing
5 changed files
with
51 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from libcommon.utils import MAX_NUM_ROWS_PER_PAGE | ||
from starlette.requests import Request | ||
|
||
from libapi.exceptions import InvalidParameterError | ||
|
||
|
||
def get_request_parameter_length(request: Request) -> int: | ||
length = int(request.query_params.get("length", MAX_NUM_ROWS_PER_PAGE)) | ||
if length < 0: | ||
raise InvalidParameterError("Parameter 'length' must be positive") | ||
elif length > MAX_NUM_ROWS_PER_PAGE: | ||
raise InvalidParameterError(f"Parameter 'length' must not be greater than {MAX_NUM_ROWS_PER_PAGE}") | ||
return length | ||
|
||
|
||
def get_request_parameter_offset(request: Request) -> int: | ||
offset = int(request.query_params.get("offset", 0)) | ||
if offset < 0: | ||
raise InvalidParameterError(message="Parameter 'offset' must be positive") | ||
return offset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters