generated from Luis/nextjs-python-web-template
Stash changes
This commit is contained in:
@@ -13,12 +13,14 @@ from ..errors import ClanError
|
||||
from . import sql_models
|
||||
from .assets import asset_path
|
||||
from .error_handlers import clan_error_handler, sql_error_handler
|
||||
from .routers import health, root, socket_manager2, sql_connect # sql router hinzufügen
|
||||
from .routers import endpoints, health, root, socket_manager2 # sql router hinzufügen
|
||||
from .sql_db import engine
|
||||
from .tags import tags_metadata
|
||||
|
||||
origins = [
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
"http://0.0.0.0:3000",
|
||||
]
|
||||
# Logging setup
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -50,7 +52,7 @@ def setup_app() -> FastAPI:
|
||||
|
||||
app.include_router(health.router)
|
||||
# sql methodes
|
||||
app.include_router(sql_connect.router)
|
||||
app.include_router(endpoints.router)
|
||||
|
||||
app.include_router(socket_manager2.router)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from ..schemas import (
|
||||
Resolution,
|
||||
Service,
|
||||
ServiceCreate,
|
||||
ServicesByName,
|
||||
)
|
||||
from ..tags import Tags
|
||||
|
||||
@@ -57,6 +58,24 @@ async def get_service_by_did(
|
||||
return service
|
||||
|
||||
|
||||
@router.get(
|
||||
"/api/v1/services_by_entity_name",
|
||||
response_model=ServicesByName,
|
||||
tags=[Tags.services],
|
||||
)
|
||||
async def get_services_by_name(
|
||||
entity_name: str,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
db: Session = Depends(sql_db.get_db),
|
||||
) -> ServicesByName:
|
||||
entity = sql_crud.get_entity_by_name(db, name=entity_name)
|
||||
if entity is None:
|
||||
raise ClanError(f"Entity with name '{entity_name}' not found")
|
||||
services = sql_crud.get_services_by_entity_did(db, entity_did=str(entity.did))
|
||||
return ServicesByName(entity=entity, services=services) # type: ignore
|
||||
|
||||
|
||||
@router.delete("/api/v1/{entity_did}/service", tags=[Tags.services])
|
||||
async def delete_service(
|
||||
entity_did: str = "did:sov:test:1234",
|
||||
@@ -66,33 +85,11 @@ async def delete_service(
|
||||
return {"message": "service deleted"}
|
||||
|
||||
|
||||
#########################
|
||||
# #
|
||||
# Client #
|
||||
# #
|
||||
#########################
|
||||
@router.get(
|
||||
"/api/v1/{entity_did}/clients", response_model=List[Service], tags=[Tags.clients]
|
||||
)
|
||||
async def get_all_clients(
|
||||
entity_did: str = "did:sov:test:1234",
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
db: Session = Depends(sql_db.get_db),
|
||||
) -> List[sql_models.Service]:
|
||||
clients = sql_crud.get_services_without_entity_id(
|
||||
db, entity_did, skip=skip, limit=limit
|
||||
)
|
||||
return clients
|
||||
|
||||
|
||||
#########################
|
||||
# #
|
||||
# REPOSITORY #
|
||||
# #
|
||||
#########################
|
||||
|
||||
|
||||
@router.get(
|
||||
"/api/v1/repositories",
|
||||
response_model=List[Service],
|
||||
@@ -117,6 +114,16 @@ async def create_entity(
|
||||
return sql_crud.create_entity(db, entity)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/api/v1/entity_by_name", response_model=Optional[Entity], tags=[Tags.entities]
|
||||
)
|
||||
async def get_entity_by_name(
|
||||
entity_name: str, db: Session = Depends(sql_db.get_db)
|
||||
) -> Optional[sql_models.Entity]:
|
||||
entity = sql_crud.get_entity_by_name(db, name=entity_name)
|
||||
return entity
|
||||
|
||||
|
||||
@router.get("/api/v1/entities", response_model=List[Entity], tags=[Tags.entities])
|
||||
async def get_all_entities(
|
||||
skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db)
|
||||
@@ -1,7 +1,8 @@
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Status(Enum):
|
||||
@@ -15,43 +16,23 @@ class Machine(BaseModel):
|
||||
status: Status
|
||||
|
||||
|
||||
#########################
|
||||
# #
|
||||
# Service #
|
||||
# #
|
||||
#########################
|
||||
class ServiceBase(BaseModel):
|
||||
uuid: str = "8e285c0c-4e40-430a-a477-26b3b81e30df"
|
||||
service_name: str = "Carlos Printing"
|
||||
service_type: str = "3D Printing"
|
||||
endpoint_url: str = "http://127.0.0.1:8000"
|
||||
status: str = "unknown"
|
||||
other: dict = {"action": ["register", "deregister", "delete", "create"]}
|
||||
|
||||
|
||||
class ServiceCreate(ServiceBase):
|
||||
entity_did: str = "did:sov:test:1234"
|
||||
|
||||
|
||||
class Service(ServiceCreate):
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
#########################
|
||||
# #
|
||||
# Entity #
|
||||
# #
|
||||
#########################
|
||||
class EntityBase(BaseModel):
|
||||
did: str = "did:sov:test:1234"
|
||||
name: str = "C1"
|
||||
ip: str = "127.0.0.1"
|
||||
visible: bool = True
|
||||
other: dict = {
|
||||
"network": "Carlos Home Network",
|
||||
"roles": ["service repository", "service prosumer"],
|
||||
}
|
||||
did: str = Field(..., example="did:sov:test:1234")
|
||||
name: str = Field(..., example="C1")
|
||||
ip: str = Field(..., example="127.0.0.1")
|
||||
visible: bool = Field(..., example=True)
|
||||
other: dict = Field(
|
||||
...,
|
||||
example={
|
||||
"network": "Carlos Home Network",
|
||||
"roles": ["service repository", "service prosumer"],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class EntityCreate(EntityBase):
|
||||
@@ -59,7 +40,42 @@ class EntityCreate(EntityBase):
|
||||
|
||||
|
||||
class Entity(EntityCreate):
|
||||
attached: bool
|
||||
attached: bool = Field(...)
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
#########################
|
||||
# #
|
||||
# Service #
|
||||
# #
|
||||
#########################
|
||||
class ServiceBase(BaseModel):
|
||||
uuid: str = Field(..., example="8e285c0c-4e40-430a-a477-26b3b81e30df")
|
||||
service_name: str = Field(..., example="Carlos Printing")
|
||||
service_type: str = Field(..., example="3D Printing")
|
||||
endpoint_url: str = Field(..., example="http://127.0.0.1:8000")
|
||||
status: str = Field(..., example="unknown")
|
||||
other: dict = Field(
|
||||
..., example={"action": ["register", "deregister", "delete", "create"]}
|
||||
)
|
||||
|
||||
|
||||
class ServiceCreate(ServiceBase):
|
||||
entity_did: str = Field(..., example="did:sov:test:1234")
|
||||
|
||||
|
||||
class Service(ServiceCreate):
|
||||
entity: Entity
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ServicesByName(BaseModel):
|
||||
entity: Entity
|
||||
services: List[Service]
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
@@ -71,10 +87,10 @@ class Entity(EntityCreate):
|
||||
# #
|
||||
#########################
|
||||
class ResolutionBase(BaseModel):
|
||||
requester_name: str = "C1"
|
||||
requester_did: str = "did:sov:test:1122"
|
||||
resolved_did: str = "did:sov:test:1234"
|
||||
other: dict = {"test": "test"}
|
||||
requester_name: str = Field(..., example="C1")
|
||||
requester_did: str = Field(..., example="did:sov:test:1122")
|
||||
resolved_did: str = Field(..., example="did:sov:test:1234")
|
||||
other: dict = Field(..., example={"test": "test"})
|
||||
|
||||
|
||||
class ResolutionCreate(ResolutionBase):
|
||||
|
||||
@@ -81,6 +81,10 @@ def get_entity_by_did(db: Session, did: str) -> Optional[sql_models.Entity]:
|
||||
return db.query(sql_models.Entity).filter(sql_models.Entity.did == did).first()
|
||||
|
||||
|
||||
def get_entity_by_name(db: Session, name: str) -> Optional[sql_models.Entity]:
|
||||
return db.query(sql_models.Entity).filter(sql_models.Entity.name == name).first()
|
||||
|
||||
|
||||
# get attached
|
||||
def get_attached_entities(
|
||||
db: Session, skip: int = 0, limit: int = 100
|
||||
|
||||
@@ -19,7 +19,7 @@ class Entity(Base):
|
||||
|
||||
## Queryable body ##
|
||||
did = Column(String, primary_key=True, index=True)
|
||||
name = Column(String, index=True)
|
||||
name = Column(String, index=True, unique=True)
|
||||
ip = Column(String, index=True)
|
||||
attached = Column(Boolean, index=True)
|
||||
visible = Column(Boolean, index=True)
|
||||
|
||||
Reference in New Issue
Block a user