-
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.
- Loading branch information
Showing
8 changed files
with
355 additions
and
7 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,21 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
|
||
from pyrb.controllers.constants import ACCOUNTS_CONFIG_PATH | ||
from pyrb.repositories.account import AccountRepository, LocalConfigAccountRepository | ||
from pyrb.services.account import AccountService | ||
|
||
|
||
def account_repo_dep() -> AccountRepository: | ||
return LocalConfigAccountRepository(config_path=ACCOUNTS_CONFIG_PATH) | ||
|
||
|
||
AccountRepoDep = Annotated[AccountRepository, Depends(account_repo_dep)] | ||
|
||
|
||
def account_service_dep(account_repo: AccountRepoDep) -> AccountService: | ||
return AccountService(account_repo) | ||
|
||
|
||
AccountServiceDep = Annotated[AccountService, Depends(account_service_dep)] |
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,22 @@ | ||
from fastapi import FastAPI, HTTPException | ||
from pydantic import BaseModel | ||
|
||
from pyrb.controllers.api.deps import AccountServiceDep | ||
from pyrb.exceptions import InitializationError | ||
from pyrb.models.account import Account | ||
|
||
app = FastAPI() | ||
|
||
|
||
class AccountResponse(BaseModel): | ||
account: Account | ||
|
||
|
||
@app.get("/accounts/default", response_model=AccountResponse) | ||
async def get_default_account(account_service: AccountServiceDep) -> AccountResponse: | ||
try: | ||
account = account_service.get() | ||
except InitializationError: | ||
raise HTTPException(status_code=404, detail="No accounts registered") | ||
|
||
return AccountResponse(account=account) |
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