Skip to content

Commit

Permalink
feat: add frontend dashboard endpoint & placeholder data
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0n committed Jan 7, 2025
1 parent b017625 commit 3157eb0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
31 changes: 31 additions & 0 deletions ruyi_backend/app/frontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from fastapi import APIRouter

from ..db.conn import DIMainDB
from ..schema.frontend import DashboardDataV1, DashboardEventDetailV1

router = APIRouter()


@router.post("/fe/dashboard")
async def get_dashboard_data_v1(main_db: DIMainDB) -> DashboardDataV1:
# TODO: query the crunched numbers
_ = main_db

# this is placeholder data
top_pkgs = {
"toolchain/gnu-milkv-milkv-duo-musl-bin": DashboardEventDetailV1(total=4),
"toolchain/gnu-upstream": DashboardEventDetailV1(total=3),
"toolchain/gnu-plct": DashboardEventDetailV1(total=2),
"board-image/buildroot-sdk-milkv-duo": DashboardEventDetailV1(total=1),
}
top_cmds = {
"riscv64-unknown-linux-musl-gcc": DashboardEventDetailV1(total=100),
"riscv64-unknown-linux-musl-g++": DashboardEventDetailV1(total=50),
"riscv64-unknown-linux-musl-ld": DashboardEventDetailV1(total=5),
}
return DashboardDataV1(
downloads=DashboardEventDetailV1(total=20),
installs=DashboardEventDetailV1(total=5),
top_packages=top_pkgs,
top_commands=top_cmds,
)
6 changes: 3 additions & 3 deletions ruyi_backend/config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class EnvConfig(BaseSettings, case_sensitive=False):


def get_env_config() -> EnvConfig:
if _ENV_CONFIG is not None:
if _ENV_CONFIG is None:
init_env_config()
return _ENV_CONFIG
raise RuntimeError("EnvConfig not initialized")
assert _ENV_CONFIG is not None
return _ENV_CONFIG


def init_env_config() -> None:
Expand Down
12 changes: 12 additions & 0 deletions ruyi_backend/schema/frontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pydantic import BaseModel


class DashboardEventDetailV1(BaseModel):
total: int


class DashboardDataV1(BaseModel):
downloads: DashboardEventDetailV1 | None
installs: DashboardEventDetailV1 | None
top_packages: dict[str, DashboardEventDetailV1 | None]
top_commands: dict[str, DashboardEventDetailV1 | None]

0 comments on commit 3157eb0

Please sign in to comment.