-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use pydantic V2 field validators
- Loading branch information
Showing
22 changed files
with
271 additions
and
437 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
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 |
---|---|---|
@@ -1,27 +1,3 @@ | ||
from aio_proxy.decorators.value_exception import value_exception_handler | ||
|
||
MAX_PAGE_VALUE = 1000 | ||
MIN_PAGE_NUMBER = 0 | ||
|
||
|
||
@value_exception_handler( | ||
error="Veuillez indiquer un numéro de page entier entre 1 et 1000, par défaut 1." | ||
) | ||
def parse_and_validate_page(request) -> int: | ||
"""Extract and Check the validity of page number. | ||
Args: | ||
request: HTTP request. | ||
Returns: | ||
page(int) if valid. | ||
default 1. | ||
Raises: | ||
ValueError: if page is not integer, lower than 1 or higher than 1000. | ||
""" | ||
page = int(request.rel_url.query.get("page", 1)) - 1 # default 1 | ||
# 1000 is elasticsearch's default page limit | ||
if page <= MIN_PAGE_NUMBER - 1 or page >= MAX_PAGE_VALUE: | ||
raise ValueError | ||
return page | ||
def parse_int(request, param) -> int: | ||
integer = int(request.rel_url.query.get(param)) | ||
return integer |
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
Oops, something went wrong.