Compare commits
7 Commits
VORKOUT-16
...
VORKOUT-18
Author | SHA1 | Date | |
---|---|---|---|
|
4aa2c12a48 | ||
|
0ab9727223 | ||
|
1d367a1bad | ||
59d2d57ee1 | |||
7fd0a732b3 | |||
571186151b | |||
1b95c9825b |
@@ -1,15 +1,15 @@
|
||||
import sys
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import loguru
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from uvicorn import run
|
||||
|
||||
from api.config import get_settings, DefaultSettings
|
||||
from api.config import DefaultSettings, get_settings
|
||||
from api.endpoints import list_of_routes
|
||||
from api.utils.common import get_hostname
|
||||
from api.services.middleware import MiddlewareAccessTokenValidadtion
|
||||
from api.utils.common import get_hostname
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
@@ -52,7 +52,6 @@ prod_origins = [""]
|
||||
|
||||
origins = dev_origins if get_settings().ENV == "local" else prod_origins
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
settings_for_application = get_settings()
|
||||
if settings_for_application.ENV == "prod":
|
||||
|
@@ -7,7 +7,7 @@ from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
from api.db import metadata, tables
|
||||
from orm import metadata, tables
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
|
38
api/api/db/alembic/versions/816be8c60ab4_.py
Normal file
38
api/api/db/alembic/versions/816be8c60ab4_.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 816be8c60ab4
|
||||
Revises: 93106fbe7d83
|
||||
Create Date: 2025-09-12 14:48:47.726269
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '816be8c60ab4'
|
||||
down_revision: Union[str, None] = '93106fbe7d83'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('ps_node', 'node_type',
|
||||
existing_type=mysql.ENUM('TYPE1', 'TYPE2', 'TYPE3'),
|
||||
type_=sa.Enum('LISTEN', 'IF', 'START', name='nodetype'),
|
||||
existing_nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('ps_node', 'node_type',
|
||||
existing_type=sa.Enum('LISTEN', 'IF', 'START', name='nodetype'),
|
||||
type_=mysql.ENUM('TYPE1', 'TYPE2', 'TYPE3'),
|
||||
existing_nullable=False)
|
||||
# ### end Alembic commands ###
|
@@ -0,0 +1,32 @@
|
||||
"""update node_link_table link_point_id default
|
||||
|
||||
Revision ID: cc3b95f1f99d
|
||||
Revises: 816be8c60ab4
|
||||
Create Date: 2025-09-12 19:17:03.125276
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'cc3b95f1f99d'
|
||||
down_revision: Union[str, None] = '816be8c60ab4'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('node_link', sa.Column('link_point_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('node_link', 'link_point_id')
|
||||
# ### end Alembic commands ###
|
@@ -6,7 +6,7 @@ from typing import Optional
|
||||
from sqlalchemy import insert, select, func, or_, and_, asc, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.tables.account import account_table
|
||||
from orm.tables.account import account_table
|
||||
from api.schemas.account.account import User
|
||||
from api.schemas.endpoints.account import all_user_adapter, AllUser, AllUserResponse, UserCreate, UserFilterDTO
|
||||
|
||||
|
@@ -4,7 +4,7 @@ from sqlalchemy import select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
from enum import Enum
|
||||
|
||||
from api.db.tables.account import account_table, account_keyring_table, KeyType, KeyStatus
|
||||
from orm.tables.account import account_table, account_keyring_table, KeyType, KeyStatus
|
||||
|
||||
from api.schemas.account.account import User
|
||||
from api.schemas.account.account_keyring import AccountKeyring
|
||||
|
@@ -6,7 +6,7 @@ from sqlalchemy import insert, select, update
|
||||
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.tables.account import account_keyring_table, KeyStatus, KeyType
|
||||
from orm.tables.account import account_keyring_table, KeyStatus, KeyType
|
||||
from api.schemas.account.account_keyring import AccountKeyring
|
||||
from api.utils.hasher import hasher
|
||||
|
||||
|
@@ -7,7 +7,7 @@ from datetime import datetime, timezone
|
||||
from sqlalchemy import insert, select, func, or_, and_, asc, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.tables.events import list_events_table
|
||||
from orm.tables.events import list_events_table
|
||||
|
||||
from api.schemas.events.list_events import ListEvent
|
||||
|
||||
|
78
api/api/db/logic/node_link.py
Normal file
78
api/api/db/logic/node_link.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from typing import Optional
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import insert, select, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.schemas.process.node_link import NodeLink
|
||||
|
||||
from orm.tables.process import ps_node_table, node_link_table
|
||||
from orm.tables.process import NodeLinkStatus
|
||||
|
||||
|
||||
|
||||
async def get_last_link_name_by_node_id(
|
||||
connection: AsyncConnection, ps_id: int
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Получает link_name из последней записи node_link по ps_id.
|
||||
Находит все node_id в ps_node по ps_id, затем ищет связи в node_link
|
||||
и возвращает link_name из самой последней записи.
|
||||
"""
|
||||
query = select(node_link_table.c.link_name).where(
|
||||
node_link_table.c.node_id.in_(
|
||||
select(ps_node_table.c.id).where(ps_node_table.c.ps_id == ps_id)
|
||||
)
|
||||
).order_by(desc(node_link_table.c.created_at)).limit(1)
|
||||
|
||||
result = await connection.execute(query)
|
||||
link_name = result.scalar_one_or_none()
|
||||
|
||||
return link_name
|
||||
|
||||
|
||||
async def get_last_node_link_by_creator_and_ps_id(
|
||||
connection: AsyncConnection, creator_id: int, node_link_id: int
|
||||
) -> Optional[NodeLink]:
|
||||
"""
|
||||
Получает последнюю созданную node_link для данного создателя и процесса.
|
||||
"""
|
||||
query = select(node_link_table).where(
|
||||
node_link_table.c.creator_id == creator_id,
|
||||
node_link_table.c.node_id.in_(
|
||||
select(ps_node_table.c.id).where(ps_node_table.c.id == node_link_id)
|
||||
)
|
||||
).order_by(desc(node_link_table.c.created_at)).limit(1)
|
||||
|
||||
node_link_db_cursor = await connection.execute(query)
|
||||
node_link_data = node_link_db_cursor.mappings().one_or_none()
|
||||
|
||||
if not node_link_data:
|
||||
return None
|
||||
|
||||
return NodeLink.model_validate(node_link_data)
|
||||
|
||||
|
||||
async def create_node_link_schema(
|
||||
connection: AsyncConnection, validated_link_schema, creator_id: int,
|
||||
) -> Optional[NodeLink]:
|
||||
"""
|
||||
Создает нове поле в таблице process_schema_table.
|
||||
"""
|
||||
query = insert(node_link_table).values(
|
||||
link_name=validated_link_schema.link_name,
|
||||
node_id=validated_link_schema.from_id,
|
||||
link_point_id=validated_link_schema.parent_port_number,
|
||||
next_node_id=validated_link_schema.to_id,
|
||||
settings={},
|
||||
creator_id=creator_id,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
status=NodeLinkStatus.ACTIVE.value,
|
||||
)
|
||||
|
||||
await connection.execute(query)
|
||||
|
||||
await connection.commit()
|
||||
|
||||
return await get_last_node_link_by_creator_and_ps_id(connection, creator_id, validated_link_schema.from_id)
|
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, Dict, Any
|
||||
import math
|
||||
|
||||
from datetime import datetime, timezone
|
||||
@@ -6,7 +6,7 @@ from datetime import datetime, timezone
|
||||
from sqlalchemy import insert, select, func, or_, and_, asc, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.tables.process import process_schema_table
|
||||
from orm.tables.process import process_schema_table
|
||||
|
||||
from api.schemas.process.process_schema import ProcessSchema
|
||||
|
||||
@@ -152,6 +152,42 @@ async def update_process_schema_by_id(connection: AsyncConnection, update_values
|
||||
await connection.commit()
|
||||
|
||||
|
||||
|
||||
async def update_process_schema_settings_by_id(
|
||||
connection: AsyncConnection,
|
||||
process_schema_id: int,
|
||||
node_data: Dict[str, Any]
|
||||
):
|
||||
"""
|
||||
Добавляет новый узел в массив 'nodes' в настройках процесса.
|
||||
Если массив 'nodes' не существует, создает его.
|
||||
"""
|
||||
# Получаем текущие settings
|
||||
query = select(process_schema_table.c.settings).where(process_schema_table.c.id == process_schema_id)
|
||||
result = await connection.execute(query)
|
||||
current_settings = result.scalar_one_or_none()
|
||||
|
||||
# Если settings пустые, создаем пустой словарь
|
||||
if current_settings is None:
|
||||
current_settings = {}
|
||||
|
||||
# Инициализируем массив nodes, если его нет
|
||||
if "nodes" not in current_settings:
|
||||
current_settings["nodes"] = []
|
||||
|
||||
# Добавляем новый узел в массив
|
||||
current_settings["nodes"].append(node_data)
|
||||
|
||||
# Обновляем поле settings
|
||||
await connection.execute(
|
||||
process_schema_table.update()
|
||||
.where(process_schema_table.c.id == process_schema_id)
|
||||
.values(settings=current_settings)
|
||||
)
|
||||
|
||||
await connection.commit()
|
||||
|
||||
|
||||
async def create_process_schema(
|
||||
connection: AsyncConnection, process_schema: ProcessSchema, creator_id: int
|
||||
) -> Optional[ProcessSchema]:
|
||||
|
106
api/api/db/logic/ps_node.py
Normal file
106
api/api/db/logic/ps_node.py
Normal file
@@ -0,0 +1,106 @@
|
||||
from typing import Optional
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import insert, select, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from orm.tables.process import ps_node_table
|
||||
|
||||
from api.schemas.process.ps_node import Ps_Node
|
||||
from model_nodes.node_start_models import StartNodeCoreSchema
|
||||
from orm.tables.process import NodeStatus,NodeType
|
||||
|
||||
|
||||
async def get_ps_node_by_id(connection: AsyncConnection, id: int) -> Optional[Ps_Node]:
|
||||
"""
|
||||
Получает process_schema по id.
|
||||
"""
|
||||
query = select(ps_node_table).where(ps_node_table.c.id == id)
|
||||
|
||||
ps_node_db_cursor = await connection.execute(query)
|
||||
|
||||
ps_node_data = ps_node_db_cursor.mappings().one_or_none()
|
||||
if not ps_node_data:
|
||||
return None
|
||||
|
||||
return Ps_Node.model_validate(ps_node_data)
|
||||
|
||||
|
||||
async def get_ps_node_by_type_and_ps_id(connection: AsyncConnection, node_type: str, ps_id: int) -> Optional[Ps_Node]:
|
||||
"""
|
||||
Получает ps_node по node_type и ps_id.
|
||||
"""
|
||||
query = select(ps_node_table).where(
|
||||
ps_node_table.c.node_type == node_type,
|
||||
ps_node_table.c.ps_id == ps_id
|
||||
)
|
||||
|
||||
ps_node_db_cursor = await connection.execute(query)
|
||||
|
||||
ps_node_data = ps_node_db_cursor.mappings().one_or_none()
|
||||
if not ps_node_data:
|
||||
return None
|
||||
|
||||
return Ps_Node.model_validate(ps_node_data)
|
||||
|
||||
async def create_ps_node_start_schema(
|
||||
connection: AsyncConnection, validated_start_schema: StartNodeCoreSchema, creator_id: int
|
||||
) -> Optional[Ps_Node]:
|
||||
"""
|
||||
Создает нове поле в таблице process_schema_table.
|
||||
"""
|
||||
query = insert(ps_node_table).values(
|
||||
ps_id=validated_start_schema.ps_id,
|
||||
node_type=NodeType.START.value,
|
||||
settings=validated_start_schema.data.model_dump(),
|
||||
creator_id=creator_id,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
status=NodeStatus.ACTIVE.value,
|
||||
)
|
||||
|
||||
await connection.execute(query)
|
||||
|
||||
await connection.commit()
|
||||
|
||||
# return validated_start_schema
|
||||
|
||||
async def get_last_ps_node_by_creator_and_ps_id(
|
||||
connection: AsyncConnection, creator_id: int, ps_id: int
|
||||
) -> Optional[Ps_Node]:
|
||||
"""
|
||||
Получает последнюю созданную ps_node для данного создателя и процесса.
|
||||
"""
|
||||
query = select(ps_node_table).where(
|
||||
ps_node_table.c.creator_id == creator_id,
|
||||
ps_node_table.c.ps_id == ps_id
|
||||
).order_by(desc(ps_node_table.c.created_at)).limit(1)
|
||||
|
||||
ps_node_db_cursor = await connection.execute(query)
|
||||
ps_node_data = ps_node_db_cursor.mappings().one_or_none()
|
||||
|
||||
if not ps_node_data:
|
||||
return None
|
||||
|
||||
return Ps_Node.model_validate(ps_node_data)
|
||||
|
||||
async def create_ps_node_schema(
|
||||
connection: AsyncConnection, validated_schema, creator_id: int,
|
||||
) -> Optional[Ps_Node]:
|
||||
"""
|
||||
Создает нове поле в таблице process_schema_table.
|
||||
"""
|
||||
query = insert(ps_node_table).values(
|
||||
ps_id=validated_schema.ps_id,
|
||||
node_type=validated_schema.node_type,
|
||||
settings=validated_schema.data.model_dump(),
|
||||
creator_id=creator_id,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
status=NodeStatus.ACTIVE.value,
|
||||
)
|
||||
|
||||
await connection.execute(query)
|
||||
|
||||
await connection.commit()
|
||||
|
||||
return await get_last_ps_node_by_creator_and_ps_id(connection, creator_id, validated_schema.ps_id)
|
@@ -1,18 +0,0 @@
|
||||
__all__ = ["BigIntegerPK", "SAEnum", "UnsignedInt"]
|
||||
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import BigInteger, Enum, Integer
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
|
||||
# class SAEnum(Enum):
|
||||
# def __init__(self, *enums: object, **kw: Any):
|
||||
# validate_strings = kw.pop("validate_strings", True)
|
||||
# super().__init__(*enums, **kw, validate_strings=validate_strings)
|
||||
|
||||
|
||||
# # https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#allowing-autoincrement-behavior-sqlalchemy-types-other-than-integer-integer
|
||||
|
||||
# BigIntegerPK = BigInteger().with_variant(Integer, "sqlite")
|
||||
UnsignedInt = Integer().with_variant(mysql.INTEGER(unsigned=True), "mysql")
|
@@ -1 +0,0 @@
|
||||
from . import account, events, process
|
@@ -1,65 +0,0 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from api.db.sql_types import UnsignedInt
|
||||
from api.db import metadata
|
||||
|
||||
|
||||
class AccountRole(enum.StrEnum):
|
||||
OWNER = "OWNER"
|
||||
ADMIN = "ADMIN"
|
||||
EDITOR = "EDITOR"
|
||||
VIEWER = "VIEWER"
|
||||
|
||||
|
||||
class AccountStatus(enum.StrEnum):
|
||||
ACTIVE = "ACTIVE"
|
||||
DISABLED = "DISABLED"
|
||||
BLOCKED = "BLOCKED"
|
||||
DELETED = "DELETED"
|
||||
|
||||
|
||||
account_table = Table(
|
||||
"account",
|
||||
metadata,
|
||||
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
|
||||
Column("name", String(100), nullable=False),
|
||||
Column("login", String(100), nullable=False),
|
||||
Column("email", String(100), nullable=True),
|
||||
Column("bind_tenant_id", String(40), nullable=True),
|
||||
Column("role", SQLAEnum(AccountRole), nullable=False),
|
||||
Column("meta", JSON, default={}),
|
||||
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=True),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("status", SQLAEnum(AccountStatus), nullable=False),
|
||||
Index("idx_login", "login"),
|
||||
Index("idx_name", "name"),
|
||||
)
|
||||
|
||||
|
||||
class KeyType(enum.StrEnum):
|
||||
PASSWORD = "PASSWORD"
|
||||
ACCESS_TOKEN = "ACCESS_TOKEN"
|
||||
REFRESH_TOKEN = "REFRESH_TOKEN"
|
||||
API_KEY = "API_KEY"
|
||||
|
||||
|
||||
class KeyStatus(enum.StrEnum):
|
||||
ACTIVE = "ACTIVE"
|
||||
EXPIRED = "EXPIRED"
|
||||
DELETED = "DELETED"
|
||||
|
||||
|
||||
account_keyring_table = Table(
|
||||
"account_keyring",
|
||||
metadata,
|
||||
Column("owner_id", UnsignedInt, ForeignKey("account.id"), primary_key=True, nullable=False),
|
||||
Column("key_type", SQLAEnum(KeyType), primary_key=True, nullable=False),
|
||||
Column("key_id", String(40), primary_key=True, default=None),
|
||||
Column("key_value", String(512), nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("expiry", DateTime(timezone=True), nullable=True),
|
||||
Column("status", SQLAEnum(KeyStatus), nullable=False),
|
||||
)
|
@@ -1,33 +0,0 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from api.db.sql_types import UnsignedInt
|
||||
|
||||
from api.db import metadata
|
||||
|
||||
|
||||
class EventState(enum.StrEnum):
|
||||
AUTO = "AUTO"
|
||||
DESCRIPTED = "DESCRIPTED"
|
||||
|
||||
|
||||
class EventStatus(enum.StrEnum):
|
||||
ACTIVE = "ACTIVE"
|
||||
DISABLED = "DISABLED"
|
||||
DELETED = "DELETED"
|
||||
|
||||
|
||||
list_events_table = Table(
|
||||
"list_events",
|
||||
metadata,
|
||||
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
|
||||
Column("name", String(40, collation="latin1_bin"), nullable=False, unique=True),
|
||||
Column("title", String(64), nullable=False),
|
||||
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("schema", JSON, default={}),
|
||||
Column("state", SQLAEnum(EventState), nullable=False),
|
||||
Column("status", SQLAEnum(EventStatus), nullable=False),
|
||||
)
|
@@ -1,107 +0,0 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import (
|
||||
Table,
|
||||
Column,
|
||||
String,
|
||||
Text,
|
||||
Enum as SQLAEnum,
|
||||
JSON,
|
||||
ForeignKey,
|
||||
DateTime,
|
||||
Index,
|
||||
PrimaryKeyConstraint,
|
||||
)
|
||||
from sqlalchemy.sql import func
|
||||
from enum import Enum
|
||||
|
||||
from api.db.sql_types import UnsignedInt
|
||||
|
||||
from api.db import metadata
|
||||
|
||||
|
||||
class ProcessStatus(enum.StrEnum):
|
||||
ACTIVE = "ACTIVE"
|
||||
STOPPING = "STOPPING"
|
||||
STOPPED = "STOPPED"
|
||||
DELETED = "DELETED"
|
||||
|
||||
|
||||
process_schema_table = Table(
|
||||
"process_schema",
|
||||
metadata,
|
||||
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
|
||||
Column("title", String(100), nullable=False),
|
||||
Column("description", Text, nullable=False),
|
||||
Column("owner_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("settings", JSON, default={}),
|
||||
Column("status", SQLAEnum(ProcessStatus), nullable=False),
|
||||
Index(
|
||||
"idx_owner_id",
|
||||
"owner_id",
|
||||
),
|
||||
)
|
||||
|
||||
process_version_archive_table = Table(
|
||||
"process_version_archive",
|
||||
metadata,
|
||||
Column("id", UnsignedInt, autoincrement=True, nullable=False),
|
||||
Column("ps_id", UnsignedInt, ForeignKey("process_schema.id"), nullable=False),
|
||||
Column("version", UnsignedInt, default=1, nullable=False),
|
||||
Column("snapshot", JSON, default={}),
|
||||
Column("owner_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("is_last", UnsignedInt, default=0),
|
||||
PrimaryKeyConstraint("id", "version"),
|
||||
)
|
||||
|
||||
|
||||
class NodeStatus(enum.StrEnum):
|
||||
ACTIVE = "ACTIVE"
|
||||
DISABLED = "DISABLED"
|
||||
DELETED = "DELETED"
|
||||
|
||||
|
||||
class NodeType(Enum):
|
||||
TYPE1 = "Type1"
|
||||
TYPE2 = "Type2"
|
||||
TYPE3 = "Type3"
|
||||
|
||||
|
||||
ps_node_table = Table(
|
||||
"ps_node",
|
||||
metadata,
|
||||
Column("id", UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
|
||||
Column("ps_id", UnsignedInt, ForeignKey("process_schema.id"), nullable=False),
|
||||
Column("node_type", SQLAEnum(NodeType), nullable=False),
|
||||
Column("settings", JSON, default={}),
|
||||
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("status", SQLAEnum(NodeStatus), nullable=False),
|
||||
Index("idx_ps_id", "ps_id"),
|
||||
)
|
||||
|
||||
|
||||
class NodeLinkStatus(enum.StrEnum):
|
||||
ACTIVE = "ACTIVE"
|
||||
STOPPING = "STOPPING"
|
||||
STOPPED = "STOPPED"
|
||||
DELETED = "DELETED"
|
||||
|
||||
|
||||
node_link_table = Table(
|
||||
"node_link",
|
||||
metadata,
|
||||
Column("id", UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
|
||||
Column("link_name", String(20), nullable=False),
|
||||
Column("node_id", UnsignedInt, ForeignKey("ps_node.id"), nullable=False),
|
||||
Column("next_node_id", UnsignedInt, ForeignKey("ps_node.id"), nullable=False),
|
||||
Column("settings", JSON, default={}),
|
||||
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||
Column("status", SQLAEnum(NodeLinkStatus), nullable=False),
|
||||
Index("idx_node_id", "node_id"),
|
||||
Index("idx_next_node_id", "next_node_id"),
|
||||
)
|
@@ -4,8 +4,9 @@ from api.endpoints.account import api_router as account_router
|
||||
from api.endpoints.keyring import api_router as keyring_router
|
||||
from api.endpoints.list_events import api_router as listevents_router
|
||||
from api.endpoints.process_schema import api_router as processschema_router
|
||||
from api.endpoints.ps_node import api_router as ps_node_router
|
||||
|
||||
list_of_routes = [auth_router, profile_router, account_router, keyring_router, listevents_router, processschema_router]
|
||||
list_of_routes = [auth_router, profile_router, account_router, keyring_router, listevents_router, processschema_router, ps_node_router]
|
||||
|
||||
__all__ = [
|
||||
"list_of_routes",
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from typing import List, Optional
|
||||
|
||||
from typing import Optional, List
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from orm.tables.account import AccountStatus
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.connection.session import get_connection_dep
|
||||
@@ -12,10 +13,9 @@ from api.db.logic.account import (
|
||||
update_user_by_id,
|
||||
)
|
||||
from api.db.logic.keyring import create_password_key, update_password_key
|
||||
from api.db.tables.account import AccountStatus
|
||||
from api.schemas.account.account import User
|
||||
from api.schemas.base import bearer_schema
|
||||
from api.schemas.endpoints.account import AllUserResponse, UserCreate, UserUpdate, UserFilterDTO
|
||||
from api.schemas.endpoints.account import AllUserResponse, UserCreate, UserFilterDTO, UserUpdate
|
||||
from api.services.auth import get_current_user
|
||||
from api.services.user_role_validation import db_user_role_validation
|
||||
|
||||
@@ -26,7 +26,7 @@ api_router = APIRouter(
|
||||
|
||||
|
||||
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllUserResponse)
|
||||
async def get_all_account(
|
||||
async def get_all_account_endpoint(
|
||||
page: int = Query(1, description="Page number", gt=0),
|
||||
limit: int = Query(10, description="КNumber of items per page", gt=0),
|
||||
search: Optional[str] = Query(None, description="Search term to filter by name or login or email"),
|
||||
@@ -62,7 +62,7 @@ async def get_all_account(
|
||||
|
||||
|
||||
@api_router.get("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||
async def get_account(
|
||||
async def get_account_endpoint(
|
||||
user_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
@@ -78,7 +78,7 @@ async def get_account(
|
||||
|
||||
|
||||
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||
async def create_account(
|
||||
async def create_account_endpoint(
|
||||
user: UserCreate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
@@ -98,7 +98,7 @@ async def create_account(
|
||||
|
||||
|
||||
@api_router.put("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=UserUpdate)
|
||||
async def update_account(
|
||||
async def update_account_endpoint(
|
||||
user_id: int,
|
||||
user_update: UserUpdate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
@@ -126,7 +126,7 @@ async def update_account(
|
||||
|
||||
|
||||
@api_router.delete("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||
async def delete_account(
|
||||
async def delete_account_endpoint(
|
||||
user_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
|
@@ -49,7 +49,7 @@ def get_config():
|
||||
|
||||
|
||||
@api_router.post("", response_model=Tokens)
|
||||
async def login_for_access_token(
|
||||
async def login_for_access_token_endpoint(
|
||||
user: Auth,
|
||||
response: Response,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
@@ -84,7 +84,7 @@ async def login_for_access_token(
|
||||
|
||||
|
||||
@api_router.post("/refresh", response_model=Tokens)
|
||||
async def refresh(
|
||||
async def refresh_endpoint(
|
||||
request: Request,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
Authorize: AuthJWT = Depends(),
|
||||
|
@@ -1,31 +1,20 @@
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
Body,
|
||||
Depends,
|
||||
Form,
|
||||
HTTPException,
|
||||
Response,
|
||||
status,
|
||||
)
|
||||
|
||||
|
||||
from orm.tables.account import KeyStatus
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.connection.session import get_connection_dep
|
||||
|
||||
from api.db.logic.keyring import get_key_by_id, create_key, update_key_by_id
|
||||
|
||||
|
||||
from api.db.tables.account import KeyStatus
|
||||
from api.db.logic.keyring import create_key, get_key_by_id, update_key_by_id
|
||||
from api.schemas.account.account_keyring import AccountKeyring
|
||||
from api.schemas.base import bearer_schema
|
||||
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate
|
||||
|
||||
from api.schemas.account.account_keyring import AccountKeyring
|
||||
from api.services.auth import get_current_user
|
||||
|
||||
from api.services.user_role_validation import db_user_role_validation
|
||||
|
||||
|
||||
api_router = APIRouter(
|
||||
prefix="/keyring",
|
||||
tags=["User KeyringModel"],
|
||||
@@ -33,7 +22,7 @@ api_router = APIRouter(
|
||||
|
||||
|
||||
@api_router.get("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||
async def get_keyring(
|
||||
async def get_keyring_endpoint (
|
||||
key_id: str, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
|
||||
):
|
||||
authorize_user = await db_user_role_validation(connection, current_user)
|
||||
@@ -47,7 +36,7 @@ async def get_keyring(
|
||||
|
||||
|
||||
@api_router.post("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||
async def create_keyring(
|
||||
async def create_keyring_endpoint(
|
||||
user_id: int,
|
||||
key_id: str,
|
||||
key: AccountKeyringUpdate,
|
||||
@@ -73,7 +62,7 @@ async def create_keyring(
|
||||
|
||||
|
||||
@api_router.put("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||
async def update_keyring(
|
||||
async def update_keyring_endpoint(
|
||||
user_id: int,
|
||||
key_id: str,
|
||||
keyring_update: AccountKeyringUpdate,
|
||||
@@ -99,7 +88,7 @@ async def update_keyring(
|
||||
|
||||
|
||||
@api_router.delete("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||
async def delete_keyring(
|
||||
async def delete_keyring_endpoint(
|
||||
user_id: int,
|
||||
key_id: str,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
|
@@ -1,37 +1,27 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
|
||||
from typing import Optional, List
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from orm.tables.events import EventStatus
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.connection.session import get_connection_dep
|
||||
|
||||
from api.db.logic.account import get_user_by_login
|
||||
|
||||
from api.db.logic.list_events import (
|
||||
get_list_events_by_name,
|
||||
get_list_events_by_id,
|
||||
create_list_events,
|
||||
update_list_events_by_id,
|
||||
get_list_events_by_id,
|
||||
get_list_events_by_name,
|
||||
get_list_events_page_DTO,
|
||||
update_list_events_by_id,
|
||||
)
|
||||
|
||||
|
||||
from api.schemas.events.list_events import ListEvent
|
||||
from api.db.tables.events import EventStatus
|
||||
|
||||
from api.schemas.base import bearer_schema
|
||||
|
||||
from api.schemas.endpoints.list_events import ListEventUpdate, AllListEventResponse, ListEventFilterDTO
|
||||
|
||||
from api.schemas.endpoints.list_events import AllListEventResponse, ListEventFilterDTO, ListEventUpdate
|
||||
from api.schemas.events.list_events import ListEvent
|
||||
from api.services.auth import get_current_user
|
||||
|
||||
from api.services.user_role_validation import (
|
||||
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
|
||||
db_user_role_validation_for_list_events_and_process_schema,
|
||||
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
|
||||
)
|
||||
|
||||
|
||||
api_router = APIRouter(
|
||||
prefix="/list_events",
|
||||
tags=["list events"],
|
||||
@@ -39,7 +29,7 @@ api_router = APIRouter(
|
||||
|
||||
|
||||
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllListEventResponse)
|
||||
async def get_all_list_events(
|
||||
async def get_all_list_events_endpoint(
|
||||
page: int = Query(1, description="Page number", gt=0),
|
||||
limit: int = Query(10, description="Number of items per page", gt=0),
|
||||
search: Optional[str] = Query(None, description="Search term to filter by title or name"),
|
||||
@@ -82,7 +72,7 @@ async def get_all_list_events(
|
||||
|
||||
|
||||
@api_router.get("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||
async def get_list_events(
|
||||
async def get_list_events_endpoint(
|
||||
list_events_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
@@ -103,7 +93,7 @@ async def get_list_events(
|
||||
|
||||
|
||||
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||
async def create_list_events(
|
||||
async def create_list_events_endpoint(
|
||||
list_events: ListEventUpdate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
@@ -151,7 +141,7 @@ async def update_list_events(
|
||||
|
||||
|
||||
@api_router.delete("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||
async def delete_list_events(
|
||||
async def delete_list_events_endpoint(
|
||||
list_events_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
|
@@ -1,44 +1,54 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from typing import List, Optional
|
||||
|
||||
from typing import Optional, List
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from orm.tables.process import ProcessStatus
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.connection.session import get_connection_dep
|
||||
|
||||
from api.db.logic.account import get_user_by_login
|
||||
|
||||
from api.db.logic.process_schema import (
|
||||
get_process_schema_by_title,
|
||||
create_process_schema,
|
||||
get_process_schema_by_id,
|
||||
update_process_schema_by_id,
|
||||
get_process_schema_by_title,
|
||||
get_process_schema_page_DTO,
|
||||
update_process_schema_by_id,
|
||||
)
|
||||
|
||||
from api.schemas.process.process_schema import ProcessSchema
|
||||
|
||||
from api.db.tables.process import ProcessStatus
|
||||
|
||||
from api.schemas.base import bearer_schema
|
||||
|
||||
from api.schemas.endpoints.process_schema import ProcessSchemaUpdate, AllProcessSchemaResponse, ProcessSchemaFilterDTO
|
||||
|
||||
from api.schemas.endpoints.process_schema import AllProcessSchemaResponse, ProcessSchemaFilterDTO, ProcessSchemaUpdate
|
||||
from api.schemas.process.process_schema import ProcessSchema, ProcessSchemaSettingsNode, ProcessSchemaResponse
|
||||
from api.schemas.process.ps_node import Ps_NodeFrontResponseNode
|
||||
from api.schemas.process.ps_node import Ps_NodeFrontResponse
|
||||
from api.services.auth import get_current_user
|
||||
|
||||
from api.services.user_role_validation import (
|
||||
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
|
||||
db_user_role_validation_for_list_events_and_process_schema,
|
||||
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
|
||||
)
|
||||
|
||||
|
||||
from api.db.logic.ps_node import create_ps_node_schema
|
||||
|
||||
from api.db.logic.process_schema import update_process_schema_settings_by_id
|
||||
|
||||
from orm.tables.process import NodeType
|
||||
|
||||
from api.utils.to_camel_dict import to_camel_dict
|
||||
|
||||
from core import VorkNodeRegistry
|
||||
|
||||
from model_nodes import ListenNodeData
|
||||
|
||||
|
||||
api_router = APIRouter(
|
||||
prefix="/process_schema",
|
||||
tags=["process schema"],
|
||||
)
|
||||
|
||||
|
||||
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllProcessSchemaResponse)
|
||||
async def get_all_process_schema(
|
||||
@api_router.get("", dependencies=[Depends(bearer_schema)],
|
||||
|
||||
# response_model=AllProcessSchemaResponse
|
||||
)
|
||||
async def get_all_process_schema_endpoint(
|
||||
page: int = Query(1, description="Page number", gt=0),
|
||||
limit: int = Query(10, description="Number of items per page", gt=0),
|
||||
search: Optional[str] = Query(None, description="Search term to filter by title or description"),
|
||||
@@ -77,11 +87,11 @@ async def get_all_process_schema(
|
||||
if process_schema_page is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||
|
||||
return process_schema_page
|
||||
return to_camel_dict(process_schema_page.model_dump())
|
||||
|
||||
|
||||
@api_router.get("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def get_process_schema(
|
||||
async def get_process_schema_endpoint(
|
||||
process_schema_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
@@ -98,11 +108,13 @@ async def get_process_schema(
|
||||
if process_schema_id is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||
|
||||
return process_schema_validation
|
||||
return to_camel_dict(process_schema_validation.model_dump())
|
||||
|
||||
|
||||
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def create_processschema(
|
||||
@api_router.post("", dependencies=[Depends(bearer_schema)],
|
||||
response_model=ProcessSchemaResponse
|
||||
)
|
||||
async def create_processschema_endpoint(
|
||||
process_schema: ProcessSchemaUpdate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
@@ -111,9 +123,61 @@ async def create_processschema(
|
||||
process_schema_validation = await get_process_schema_by_title(connection, process_schema.title)
|
||||
|
||||
if process_schema_validation is None:
|
||||
|
||||
await create_process_schema(connection, process_schema, user_validation.id)
|
||||
process_schema_new = await get_process_schema_by_title(connection, process_schema.title)
|
||||
return process_schema_new
|
||||
|
||||
start_node_data = ListenNodeData(
|
||||
ps_id=process_schema_new.id,
|
||||
node_type=NodeType.START.value,
|
||||
is_start="True"
|
||||
)
|
||||
|
||||
start_node_links = {}
|
||||
|
||||
registery = VorkNodeRegistry()
|
||||
|
||||
vork_node = registery.get("LISTEN")
|
||||
|
||||
node_descriptor = vork_node.form()
|
||||
|
||||
|
||||
start_node = vork_node(data=start_node_data.model_dump(), links=start_node_links)
|
||||
|
||||
validated_start_schema = start_node.validate()
|
||||
|
||||
print(validated_start_schema)
|
||||
|
||||
db_start_schema = await create_ps_node_schema(connection, validated_start_schema, user_validation.id)
|
||||
|
||||
node = ProcessSchemaSettingsNode(
|
||||
id=db_start_schema.id,
|
||||
node_type=NodeType.LISTEN.value,
|
||||
data=validated_start_schema.data.model_dump(),
|
||||
from_node=None,
|
||||
links=None)
|
||||
|
||||
settings_dict = {"node": node.model_dump(mode='json')}
|
||||
|
||||
await update_process_schema_settings_by_id(connection, process_schema_new.id, settings_dict)
|
||||
|
||||
process_schema_new = await get_process_schema_by_title(connection, process_schema.title)
|
||||
|
||||
ps_node_front_response = Ps_NodeFrontResponse(
|
||||
description=node_descriptor,
|
||||
node=Ps_NodeFrontResponseNode(
|
||||
id=db_start_schema.id,
|
||||
node_type=NodeType.LISTEN.value,
|
||||
data=validated_start_schema.data.model_dump()),
|
||||
link=None)
|
||||
|
||||
|
||||
response_data = {
|
||||
"process_schema": process_schema_new.model_dump(),
|
||||
"node_listen": ps_node_front_response.model_dump()}
|
||||
|
||||
return to_camel_dict(response_data)
|
||||
|
||||
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -122,7 +186,7 @@ async def create_processschema(
|
||||
|
||||
|
||||
@api_router.put("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def update_process_schema(
|
||||
async def update_process_schema_endpoint(
|
||||
process_schema_id: int,
|
||||
process_schema_update: ProcessSchemaUpdate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
@@ -150,7 +214,7 @@ async def update_process_schema(
|
||||
|
||||
|
||||
@api_router.delete("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def delete_process_schema(
|
||||
async def delete_process_schema_endpoint(
|
||||
process_schema_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
|
@@ -4,18 +4,14 @@ from fastapi import (
|
||||
HTTPException,
|
||||
status,
|
||||
)
|
||||
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.connection.session import get_connection_dep
|
||||
from api.db.logic.account import get_user_by_id, update_user_by_id, get_user_by_login
|
||||
from api.schemas.base import bearer_schema
|
||||
from api.services.auth import get_current_user
|
||||
|
||||
from api.schemas.endpoints.account import UserUpdate
|
||||
from api.db.logic.account import get_user_by_id, get_user_by_login, update_user_by_id
|
||||
from api.schemas.account.account import User
|
||||
|
||||
from api.schemas.base import bearer_schema
|
||||
from api.schemas.endpoints.account import UserUpdate
|
||||
from api.services.auth import get_current_user
|
||||
|
||||
api_router = APIRouter(
|
||||
prefix="/profile",
|
||||
|
117
api/api/endpoints/ps_node.py
Normal file
117
api/api/endpoints/ps_node.py
Normal file
@@ -0,0 +1,117 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException,status
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.connection.session import get_connection_dep
|
||||
from api.db.logic.account import get_user_by_login
|
||||
|
||||
from api.schemas.base import bearer_schema
|
||||
from api.schemas.process.process_schema import ProcessSchemaSettingsNodeLink, ProcessSchemaSettingsNode
|
||||
from api.schemas.process.ps_node import Ps_NodeFrontResponseNode, Ps_NodeRequest
|
||||
from api.schemas.process.ps_node import Ps_NodeFrontResponse
|
||||
from api.services.auth import get_current_user
|
||||
|
||||
|
||||
from api.db.logic.ps_node import create_ps_node_schema
|
||||
from api.db.logic.node_link import get_last_link_name_by_node_id, create_node_link_schema
|
||||
|
||||
from api.db.logic.process_schema import update_process_schema_settings_by_id
|
||||
|
||||
from core import VorkNodeRegistry, VorkNodeLink
|
||||
|
||||
from model_nodes import VorkNodeLinkData
|
||||
from api.utils.to_camel_dict import to_camel_dict
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
api_router = APIRouter(
|
||||
prefix="/ps_node",
|
||||
tags=["ps node"],
|
||||
)
|
||||
|
||||
|
||||
@api_router.post("", dependencies=[Depends(bearer_schema)],response_model=Ps_NodeFrontResponse)
|
||||
|
||||
async def create_ps_node_endpoint(
|
||||
ps_node: Ps_NodeRequest,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
|
||||
user_validation = await get_user_by_login(connection, current_user)
|
||||
|
||||
registery = VorkNodeRegistry()
|
||||
|
||||
vork_node = registery.get(ps_node.data["node_type"])
|
||||
|
||||
if vork_node is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Node not found")
|
||||
|
||||
node_descriptor = vork_node.form()
|
||||
try:
|
||||
node_instance = vork_node(data=ps_node.data, links=ps_node.links)
|
||||
|
||||
node_instance_validated = node_instance.validate()
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
|
||||
|
||||
|
||||
db_ps_node = await create_ps_node_schema(connection, node_instance_validated, user_validation.id)
|
||||
link_name = await get_last_link_name_by_node_id(connection, db_ps_node.ps_id)
|
||||
|
||||
|
||||
|
||||
link_data = VorkNodeLinkData(
|
||||
parent_port_number=node_instance_validated.parent_port_number,
|
||||
to_id=db_ps_node.id,
|
||||
from_id=node_instance_validated.parent_id,
|
||||
last_link_name=link_name)
|
||||
|
||||
|
||||
|
||||
link = VorkNodeLink(data=link_data.model_dump())
|
||||
|
||||
validated_link = link.validate()
|
||||
|
||||
|
||||
|
||||
|
||||
db_node_link = await create_node_link_schema(connection, validated_link, user_validation.id)
|
||||
|
||||
|
||||
|
||||
|
||||
links_settings = ProcessSchemaSettingsNodeLink(
|
||||
id=db_node_link.id,
|
||||
link_name=db_node_link.link_name,
|
||||
parent_port_number=db_node_link.link_point_id,
|
||||
from_id=db_node_link.node_id,
|
||||
to_id=db_node_link.next_node_id,
|
||||
)
|
||||
|
||||
node_settings = ProcessSchemaSettingsNode(
|
||||
id=db_ps_node.id,
|
||||
node_type=db_ps_node.node_type,
|
||||
data=node_instance_validated.data.model_dump(),
|
||||
from_node=None,
|
||||
links=links_settings.model_dump())
|
||||
|
||||
|
||||
settings_dict = {"node": node_settings.model_dump(mode='json')}
|
||||
|
||||
await update_process_schema_settings_by_id(connection, db_ps_node.ps_id, settings_dict)
|
||||
|
||||
|
||||
ps_node_front_response = Ps_NodeFrontResponse(
|
||||
description=node_descriptor,
|
||||
node=Ps_NodeFrontResponseNode(
|
||||
id=db_ps_node.id,
|
||||
node_type=db_ps_node.node_type,
|
||||
data=to_camel_dict(node_instance_validated.data.model_dump())),
|
||||
link=links_settings.model_dump())
|
||||
|
||||
|
||||
return ps_node_front_response
|
@@ -1,8 +1,8 @@
|
||||
import datetime
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from orm.tables.account import AccountRole, AccountStatus
|
||||
from pydantic import EmailStr, Field
|
||||
from api.db.tables.account import AccountRole, AccountStatus
|
||||
|
||||
from api.schemas.base import Base
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import datetime
|
||||
from typing import Optional
|
||||
from pydantic import Field
|
||||
from datetime import datetime
|
||||
from api.db.tables.account import KeyType, KeyStatus
|
||||
from typing import Optional
|
||||
|
||||
from orm.tables.account import KeyStatus, KeyType
|
||||
from pydantic import Field
|
||||
|
||||
from api.schemas.base import Base
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional, Dict
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from orm.tables.account import AccountRole, AccountStatus
|
||||
from pydantic import EmailStr, Field, TypeAdapter
|
||||
|
||||
from api.db.tables.account import AccountRole, AccountStatus
|
||||
from api.schemas.base import Base
|
||||
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from typing import Optional
|
||||
|
||||
from orm.tables.account import KeyStatus, KeyType
|
||||
from pydantic import Field
|
||||
from api.db.tables.account import KeyType, KeyStatus
|
||||
|
||||
from api.schemas.base import Base
|
||||
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from api.schemas.base import Base
|
||||
|
||||
|
||||
# Таблица для получения информации из запроса
|
||||
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
from pydantic import Field, TypeAdapter
|
||||
from typing import Optional, Dict, Any, List
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from orm.tables.events import EventState, EventStatus
|
||||
from pydantic import Field, TypeAdapter
|
||||
|
||||
from api.schemas.base import Base
|
||||
from api.db.tables.events import EventState, EventStatus
|
||||
|
||||
|
||||
class ListEventUpdate(Base):
|
||||
|
@@ -1,10 +1,10 @@
|
||||
from pydantic import Field, TypeAdapter
|
||||
from typing import Optional, Dict, Any, List
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from orm.tables.process import ProcessStatus
|
||||
from pydantic import Field, TypeAdapter
|
||||
|
||||
from api.schemas.base import Base
|
||||
from api.db.tables.process import ProcessStatus
|
||||
|
||||
|
||||
class ProcessSchemaUpdate(Base):
|
||||
|
@@ -1,9 +1,10 @@
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from orm.tables.events import EventState, EventStatus
|
||||
from pydantic import Field
|
||||
|
||||
from api.schemas.base import Base
|
||||
from api.db.tables.events import EventState, EventStatus
|
||||
|
||||
|
||||
class ListEvent(Base):
|
||||
|
@@ -1,15 +1,17 @@
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from orm.tables.process import NodeStatus
|
||||
from pydantic import Field
|
||||
|
||||
from api.schemas.base import Base
|
||||
from api.db.tables.process import NodeStatus
|
||||
|
||||
|
||||
class MyModel(Base):
|
||||
class NodeLink(Base):
|
||||
id: int
|
||||
link_name: str = Field(..., max_length=20)
|
||||
node_id: int
|
||||
link_point_id: int
|
||||
next_node_id: int
|
||||
settings: Dict[str, Any]
|
||||
creator_id: int
|
||||
|
@@ -1,9 +1,11 @@
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from orm.tables.process import ProcessStatus, NodeType
|
||||
from pydantic import Field
|
||||
|
||||
from api.schemas.base import Base
|
||||
from api.db.tables.process import ProcessStatus
|
||||
from api.schemas.process.ps_node import Ps_NodeFrontResponse
|
||||
|
||||
|
||||
class ProcessSchema(Base):
|
||||
@@ -15,3 +17,24 @@ class ProcessSchema(Base):
|
||||
created_at: datetime
|
||||
settings: Dict[str, Any]
|
||||
status: ProcessStatus
|
||||
|
||||
|
||||
class ProcessSchemaSettingsNodeLink(Base):
|
||||
id: int
|
||||
link_name: str
|
||||
parent_port_number: int
|
||||
from_id: int
|
||||
to_id: int
|
||||
|
||||
|
||||
class ProcessSchemaSettingsNode(Base):
|
||||
id: int
|
||||
node_type: NodeType
|
||||
from_node: Optional[Dict[str, Any]] = None
|
||||
data: Dict[str, Any]# Переименовано с 'from' на 'from_node'
|
||||
links: Optional[ProcessSchemaSettingsNodeLink] = None
|
||||
|
||||
|
||||
class ProcessSchemaResponse(Base):
|
||||
process_schema: ProcessSchema
|
||||
node_listen: Ps_NodeFrontResponse
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from typing import Dict, Any
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from api.schemas.base import Base
|
||||
|
||||
|
@@ -1,15 +1,42 @@
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from orm.tables.process import NodeStatus, NodeType
|
||||
from pydantic import Field
|
||||
|
||||
from api.schemas.base import Base
|
||||
from api.db.tables.process import NodeType, NodeStatus
|
||||
|
||||
|
||||
class Ps_NodeRequest(Base):
|
||||
data: Dict[str, Any]
|
||||
links: Dict[str, Any]
|
||||
|
||||
class Ps_Node(Base):
|
||||
id: int
|
||||
ps_id: int
|
||||
node_type: NodeType
|
||||
settings: dict
|
||||
creator_id: Dict[str, Any]
|
||||
creator_id: int
|
||||
created_at: datetime
|
||||
status: NodeStatus
|
||||
|
||||
|
||||
|
||||
class Ps_NodeFrontResponseLink(Base):
|
||||
id: int
|
||||
link_name: str
|
||||
parent_port_number: int
|
||||
from_id: int
|
||||
to_id: int
|
||||
|
||||
|
||||
class Ps_NodeFrontResponseNode(Base):
|
||||
id: int
|
||||
node_type: NodeType
|
||||
data: Dict[str, Any]# Переименовано с 'from' на 'from_node'
|
||||
|
||||
|
||||
class Ps_NodeFrontResponse(Base):
|
||||
description: Optional[Dict[str, Any]] = None
|
||||
node: Optional[Ps_NodeFrontResponseNode] = None
|
||||
link: Optional[Ps_NodeFrontResponseLink] = None
|
||||
|
@@ -1,10 +1,10 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import HTTPException, Request
|
||||
from orm.tables.account import AccountStatus
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.logic.auth import get_user
|
||||
from api.db.tables.account import AccountStatus
|
||||
from api.schemas.endpoints.account import AllUser
|
||||
from api.utils.hasher import hasher
|
||||
|
||||
|
@@ -1,15 +1,15 @@
|
||||
from fastapi_jwt_auth import AuthJWT
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
import re
|
||||
from re import escape
|
||||
|
||||
from fastapi import (
|
||||
Request,
|
||||
status,
|
||||
)
|
||||
|
||||
from fastapi.responses import JSONResponse
|
||||
from api.config import get_settings
|
||||
from fastapi_jwt_auth import AuthJWT
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
import re
|
||||
from re import escape
|
||||
from api.config import get_settings
|
||||
|
||||
|
||||
class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware):
|
||||
|
@@ -2,8 +2,9 @@ from fastapi import (
|
||||
HTTPException,
|
||||
status,
|
||||
)
|
||||
from orm.tables.account import AccountRole
|
||||
|
||||
from api.db.logic.account import get_user_by_login
|
||||
from api.db.tables.account import AccountRole
|
||||
|
||||
|
||||
async def db_user_role_validation(connection, current_user):
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from orm.tables.account import account_keyring_table, account_table, AccountRole, KeyStatus, KeyType
|
||||
|
||||
from api.db.connection.session import get_connection
|
||||
from api.db.tables.account import account_keyring_table, account_table, AccountRole, KeyStatus, KeyType
|
||||
from api.utils.hasher import hasher
|
||||
from api.utils.key_id_gen import KeyIdGenerator
|
||||
|
||||
|
9
api/api/utils/to_camel_dict.py
Normal file
9
api/api/utils/to_camel_dict.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from pydantic.alias_generators import to_camel
|
||||
|
||||
def to_camel_dict(obj):
|
||||
if isinstance(obj, dict):
|
||||
return {to_camel(key): to_camel_dict(value) for key, value in obj.items()}
|
||||
elif isinstance(obj, list):
|
||||
return [to_camel_dict(item) for item in obj]
|
||||
else:
|
||||
return obj
|
2155
api/poetry.lock
generated
2155
api/poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,9 @@ dependencies = [
|
||||
"cryptography (>=44.0.2,<45.0.0)",
|
||||
"pydantic[email] (>=2.11.3,<3.0.0)",
|
||||
"python-multipart (>=0.0.20,<0.0.21)",
|
||||
"requests (>=2.31.0,<3.0.0)",
|
||||
"fastapi-jwt-auth @ git+https://github.com/vvpreo/fastapi-jwt-auth",
|
||||
"core-library @ git+https://gitea.heado.ru/Vorkout/core.git@VORKOUT-18",
|
||||
]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user