Add admin user management
This commit is contained in:
+46
-1
@@ -14,6 +14,7 @@ from rich.table import Table
|
||||
|
||||
from app.core.errors import FeatureNotReadyError
|
||||
from app.schemas.portfolio import PortfolioDetailResponse, PortfolioListItem
|
||||
from app.schemas.user import UserResponse
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@@ -126,6 +127,41 @@ def print_portfolio_detail(console: Console, detail: PortfolioDetailResponse) ->
|
||||
console.print(ledger_table)
|
||||
|
||||
|
||||
def print_user_table(console: Console, users: list[UserResponse]) -> None:
|
||||
table = Table(title="Users", expand=True)
|
||||
table.add_column("ID", style="cyan", no_wrap=True)
|
||||
table.add_column("Username", no_wrap=True)
|
||||
table.add_column("Email")
|
||||
table.add_column("Created At", no_wrap=True)
|
||||
table.add_column("Updated At", no_wrap=True)
|
||||
for user in users:
|
||||
table.add_row(
|
||||
user.id,
|
||||
user.username,
|
||||
user.email or "N/A",
|
||||
user.created_at.isoformat(timespec="seconds") if user.created_at else "N/A",
|
||||
user.updated_at.isoformat(timespec="seconds") if user.updated_at else "N/A",
|
||||
)
|
||||
console.print(table)
|
||||
|
||||
|
||||
def print_user_detail(console: Console, user: UserResponse) -> None:
|
||||
console.print(
|
||||
Panel.fit(
|
||||
"\n".join(
|
||||
[
|
||||
f"id: {user.id}",
|
||||
f"username: {user.username}",
|
||||
f"email: {user.email or 'N/A'}",
|
||||
f"created_at: {user.created_at.isoformat(timespec='seconds') if user.created_at else 'N/A'}",
|
||||
f"updated_at: {user.updated_at.isoformat(timespec='seconds') if user.updated_at else 'N/A'}",
|
||||
]
|
||||
),
|
||||
title="User",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def print_json(console: Console, payload: Any) -> None:
|
||||
console.print_json(data=to_plain_data(payload))
|
||||
|
||||
@@ -139,13 +175,22 @@ def render_output(console: Console, output_format: str, payload: Any, *, empty_m
|
||||
if not payload and empty_message:
|
||||
console.print(empty_message)
|
||||
return
|
||||
print_portfolio_table(console, payload)
|
||||
if all(isinstance(item, PortfolioListItem) for item in payload):
|
||||
print_portfolio_table(console, payload)
|
||||
return
|
||||
if all(isinstance(item, UserResponse) for item in payload):
|
||||
print_user_table(console, payload)
|
||||
return
|
||||
return
|
||||
|
||||
if isinstance(payload, PortfolioDetailResponse):
|
||||
print_portfolio_detail(console, payload)
|
||||
return
|
||||
|
||||
if isinstance(payload, UserResponse):
|
||||
print_user_detail(console, payload)
|
||||
return
|
||||
|
||||
console.print(payload)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user