This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/29: Add basic schemas & add health handler in user-app (#11)
- Loading branch information
Showing
9 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
Empty file.
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,10 @@ | ||
from .base import BaseResponse, OKResponse | ||
from .enums import ResponseStatus | ||
from .health import HealthResponse | ||
|
||
__all__ = [ | ||
"ResponseStatus", | ||
"OKResponse", | ||
"BaseResponse", | ||
"HealthResponse", | ||
] |
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,11 @@ | ||
from pydantic import BaseModel | ||
|
||
from .enums import ResponseStatus | ||
|
||
|
||
class BaseResponse(BaseModel): | ||
status: ResponseStatus | ||
|
||
|
||
class OKResponse(BaseModel): | ||
status: ResponseStatus = ResponseStatus.OK |
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,6 @@ | ||
from enum import Enum | ||
|
||
|
||
class ResponseStatus(Enum): | ||
OK = "ok" | ||
ERROR = "error" |
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,6 @@ | ||
from .base import BaseResponse | ||
|
||
|
||
class HealthResponse(BaseResponse): | ||
version: str | ||
name: str |
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,9 @@ | ||
from functools import reduce | ||
|
||
|
||
def get_nested(storage: dict, *keys): | ||
return reduce( | ||
lambda value, key: value.get(key, {}) if isinstance(value, dict) else None, | ||
keys, | ||
storage, | ||
) |
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,2 +1,18 @@ | ||
async def health(): | ||
pass | ||
import os | ||
import pathlib | ||
import tomllib | ||
|
||
from sapphire.common.api.schemas import HealthResponse, ResponseStatus | ||
from sapphire.common.functions import get_nested | ||
|
||
|
||
async def health() -> HealthResponse: | ||
path_to_toml_file = pathlib.Path(os.curdir).absolute() / "pyproject.toml" | ||
with open(path_to_toml_file, "rb") as toml_file: | ||
pyproject_data = tomllib.load(toml_file) | ||
|
||
return HealthResponse( | ||
status=ResponseStatus.OK, | ||
version=get_nested(pyproject_data, "tool", "poetry", "version"), | ||
name="users", | ||
) |