-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8814d8b
commit 0a9a523
Showing
11 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
Empty file.
5 changes: 5 additions & 0 deletions
5
src/zrb/builtin/project/add/fastapp/application/fastapp-template/common/schema.py
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,5 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class BasicResponse(BaseModel): | ||
message: str |
8 changes: 0 additions & 8 deletions
8
src/zrb/builtin/project/add/fastapp/application/fastapp-template/main.py
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,13 +1,5 @@ | ||
from typing import Union | ||
|
||
from .common.app import app | ||
from .module.auth import route as auth_route | ||
from .module.gateway import route as gateway_route | ||
|
||
assert gateway_route | ||
assert auth_route | ||
|
||
|
||
@app.get("/items/{item_id}") | ||
def read_item(item_id: int, q: Union[str, None] = None): | ||
return {"item_id": item_id, "q": q} |
17 changes: 13 additions & 4 deletions
17
src/zrb/builtin/project/add/fastapp/application/fastapp-template/module/auth/route.py
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,9 +1,18 @@ | ||
from ...common.app import app | ||
from ...common.schema import BasicResponse | ||
from ...config import APP_MODE, APP_MODULES | ||
from .usecase import usecase | ||
from .user.usecase import user_usecase | ||
|
||
if APP_MODE == "microservices" and "library" in APP_MODULES: | ||
if APP_MODE == "microservices" and "auth" in APP_MODULES: | ||
|
||
@app.get("/library/greeting") | ||
@app.api_route("/health", methods=["GET", "HEAD"], response_class=BasicResponse) | ||
async def health(): | ||
return BasicResponse(message="ok") | ||
|
||
@app.api_route("/readiness", methods=["GET", "HEAD"], response_class=BasicResponse) | ||
async def readiness(): | ||
return BasicResponse(message="ok") | ||
|
||
@app.get("/user/greeting") | ||
def greet(name: str) -> str: | ||
return usecase.greet(name) | ||
return user_usecase.greet(name) |
Empty file.
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions
21
src/zrb/builtin/project/add/fastapp/application/fastapp-template/module/auth/user/usecase.py
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,21 @@ | ||
from ....schema.user import NewUserData, User, UserData | ||
|
||
|
||
class Usecase: | ||
def get_user_by_id(id: str) -> UserData: | ||
pass | ||
|
||
def get_user() -> list[UserData]: | ||
pass | ||
|
||
def insert_user(data: NewUserData) -> User: | ||
pass | ||
|
||
def insert_users(data: list[NewUserData]) -> list[User]: | ||
pass | ||
|
||
def update_user(id: str, data: NewUserData) -> User: | ||
pass | ||
|
||
|
||
user_usecase = Usecase() |
13 changes: 11 additions & 2 deletions
13
src/zrb/builtin/project/add/fastapp/application/fastapp-template/module/gateway/route.py
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,11 +1,20 @@ | ||
from fastapi.responses import PlainTextResponse | ||
|
||
from ...common.app import app | ||
from ...common.schema import BasicResponse | ||
from ...config import APP_MODE, APP_MODULES | ||
from ..auth.client.factory import client | ||
from ..auth.client.factory import client as auth_client | ||
|
||
if APP_MODE == "monolith" or "gateway" in APP_MODULES: | ||
|
||
@app.api_route("/health", methods=["GET", "HEAD"], response_class=BasicResponse) | ||
async def health(): | ||
return BasicResponse(message="ok") | ||
|
||
@app.api_route("/readiness", methods=["GET", "HEAD"], response_class=BasicResponse) | ||
async def readiness(): | ||
return BasicResponse(message="ok") | ||
|
||
@app.get("/", response_class=PlainTextResponse) | ||
async def read_root(): | ||
return await client.greet("world") | ||
return await auth_client.greet("world") |
Empty file.
13 changes: 13 additions & 0 deletions
13
src/zrb/builtin/project/add/fastapp/application/fastapp-template/schema/user.py
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,13 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class UserData(BaseModel): | ||
username: str | ||
|
||
|
||
class NewUserData(UserData): | ||
password: str | ||
|
||
|
||
class User(UserData): | ||
id: str |