-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from jodal/search-enhet
Add search APIs
- Loading branch information
Showing
15 changed files
with
1,325 additions
and
280 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
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,60 @@ | ||
from typing import Generic, List, TypeVar | ||
|
||
from pydantic import ( | ||
AliasPath, | ||
BaseModel, | ||
Field, | ||
) | ||
|
||
from brreg.enhetsregisteret._responses import Enhet, Underenhet | ||
|
||
__all__ = [ | ||
"EnhetPage", | ||
"UnderenhetPage", | ||
] | ||
|
||
|
||
T = TypeVar("T", bound=BaseModel) | ||
|
||
|
||
class Page(BaseModel, Generic[T]): | ||
"""The fields here are available on all page objects.""" | ||
|
||
#: The items on this page. | ||
items: List[T] | ||
|
||
#: The number of elements on this page. | ||
page_size: int = Field( | ||
validation_alias=AliasPath("page", "size"), | ||
) | ||
|
||
#: The page number, starting at 0. | ||
page_number: int = Field( | ||
validation_alias=AliasPath("page", "number"), | ||
) | ||
|
||
#: The total number of elements available. | ||
total_elements: int = Field( | ||
validation_alias=AliasPath("page", "totalElements"), | ||
) | ||
|
||
#: The total number of pages available. | ||
total_pages: int = Field( | ||
validation_alias=AliasPath("page", "totalPages"), | ||
) | ||
|
||
|
||
class EnhetPage(Page[Enhet]): | ||
"""Response type for enhet search.""" | ||
|
||
items: List[Enhet] = Field( | ||
validation_alias=AliasPath("_embedded", "enheter"), | ||
) | ||
|
||
|
||
class UnderenhetPage(Page[Underenhet]): | ||
"""Response type for underenhet search.""" | ||
|
||
items: List[Underenhet] = Field( | ||
validation_alias=AliasPath("_embedded", "underenheter"), | ||
) |
Oops, something went wrong.