From 0ad48e0de641a7fa26c5d1d760aa92a76d50ddea Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 20 Nov 2023 17:39:21 +0100 Subject: [PATCH] push first sql setup try --- .../clan-cli/clan_cli/webui/routers/health.py | 6 ++- pkgs/clan-cli/clan_cli/webui/sql_db.py | 0 pkgs/clan-cli/clan_cli/webui/sql_models.py | 25 +++++++++++ pkgs/clan-cli/clan_cli/webui/sql_schemas.py | 41 +++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_db.py create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_models.py create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_schemas.py diff --git a/pkgs/clan-cli/clan_cli/webui/routers/health.py b/pkgs/clan-cli/clan_cli/webui/routers/health.py index 24967e5..2deed84 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/health.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/health.py @@ -1,8 +1,10 @@ from fastapi import APIRouter +from ..api_outputs import Machine, Status router = APIRouter() @router.get("/health", include_in_schema=True) -async def health() -> str: - return "OK" +async def health() -> Machine: #str: + return Machine(name="test", status=Status.ONLINE) +# return "OK" diff --git a/pkgs/clan-cli/clan_cli/webui/sql_db.py b/pkgs/clan-cli/clan_cli/webui/sql_db.py new file mode 100644 index 0000000..e69de29 diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py new file mode 100644 index 0000000..82ff6a5 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -0,0 +1,25 @@ +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String +from sqlalchemy.orm import relationship +from .sql_db import Base + +class Repository(Base): + __tablename__ = "repositories" + + id = Column(Integer, primary_key=True, index=True) + service_name = Column(String, unique=True, index=True) + service_type = Column(String, unique=True, index=True) + end_point = Column(String, unique=True, index=True) + producer = Column(String) + producer_did = Column(String) + network = Column(String) + +class Producer(Base): + __tablename__ = "producers" + + id = Column(Integer, primary_key=True, index=True) + service_name = Column(String, unique=True, index=True) + service_type = Column(String, unique=True, index=True) + end_point = Column(String, unique=True, index=True) + usage = Column(String) # TODO enum? + status = Column(String) + action = Column(String) diff --git a/pkgs/clan-cli/clan_cli/webui/sql_schemas.py b/pkgs/clan-cli/clan_cli/webui/sql_schemas.py new file mode 100644 index 0000000..d0fa20f --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/sql_schemas.py @@ -0,0 +1,41 @@ +from pydantic import BaseModel + + +class ProducerBase(BaseModel): + title: str + description: str | None = None + + +class ProducerCreate(ProducerBase): + service_name: str + service_type: str + end_point: str + usage_str: str + status: str + action: str + + +class Producer(ProducerBase): + id: int + + class Config: + orm_mode = True + + +class RepositoryBase(BaseModel): + service_name: str + + +class RepositoryCreate(RepositoryBase): + service_type: str + end_point: str + producer_did: str + network: str + + +class Repository(RepositoryBase): + id: int + Producers: list[Producer] = [] + + class Config: + orm_mode = True