fix: rename process schema
This commit is contained in:
@@ -117,59 +117,59 @@ async def get_process_schema_by_title(connection: AsyncConnection, title: str) -
|
||||
"""
|
||||
query = select(process_schema_table).where(process_schema_table.c.title == title)
|
||||
|
||||
processschema_db_cursor = await connection.execute(query)
|
||||
process_schema_db_cursor = await connection.execute(query)
|
||||
|
||||
processschema_data = processschema_db_cursor.mappings().one_or_none()
|
||||
if not processschema_data:
|
||||
process_schema_data = process_schema_db_cursor.mappings().one_or_none()
|
||||
if not process_schema_data:
|
||||
return None
|
||||
|
||||
return ProcessSchema.model_validate(processschema_data)
|
||||
return ProcessSchema.model_validate(process_schema_data)
|
||||
|
||||
|
||||
async def get_process_schema_by_id(connection: AsyncConnection, id: int) -> Optional[ProcessSchema]:
|
||||
"""
|
||||
Получает processschema по id.
|
||||
Получает process_schema по id.
|
||||
"""
|
||||
query = select(process_schema_table).where(process_schema_table.c.id == id)
|
||||
|
||||
processschema_db_cursor = await connection.execute(query)
|
||||
process_schema_db_cursor = await connection.execute(query)
|
||||
|
||||
processschema_data = processschema_db_cursor.mappings().one_or_none()
|
||||
if not processschema_data:
|
||||
process_schema_data = process_schema_db_cursor.mappings().one_or_none()
|
||||
if not process_schema_data:
|
||||
return None
|
||||
|
||||
return ProcessSchema.model_validate(processschema_data)
|
||||
return ProcessSchema.model_validate(process_schema_data)
|
||||
|
||||
|
||||
async def update_process_schema_by_id(connection: AsyncConnection, update_values, processschema):
|
||||
async def update_process_schema_by_id(connection: AsyncConnection, update_values, process_schema):
|
||||
"""
|
||||
Вносит изменеия в нужное поле таблицы process_schema_table.
|
||||
"""
|
||||
await connection.execute(
|
||||
process_schema_table.update().where(process_schema_table.c.id == processschema.id).values(**update_values)
|
||||
process_schema_table.update().where(process_schema_table.c.id == process_schema.id).values(**update_values)
|
||||
)
|
||||
|
||||
await connection.commit()
|
||||
|
||||
|
||||
async def create_process_schema(
|
||||
connection: AsyncConnection, processschema: ProcessSchema, creator_id: int
|
||||
connection: AsyncConnection, process_schema: ProcessSchema, creator_id: int
|
||||
) -> Optional[ProcessSchema]:
|
||||
"""
|
||||
Создает нове поле в таблице process_schema_table.
|
||||
"""
|
||||
query = insert(process_schema_table).values(
|
||||
title=processschema.title,
|
||||
description=processschema.description,
|
||||
owner_id=processschema.owner_id,
|
||||
title=process_schema.title,
|
||||
description=process_schema.description,
|
||||
owner_id=process_schema.owner_id,
|
||||
creator_id=creator_id,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
settings=processschema.settings,
|
||||
status=processschema.status.value,
|
||||
settings=process_schema.settings,
|
||||
status=process_schema.status.value,
|
||||
)
|
||||
|
||||
await connection.execute(query)
|
||||
|
||||
await connection.commit()
|
||||
|
||||
return processschema
|
||||
return process_schema
|
@@ -3,7 +3,7 @@ from api.endpoints.profile import api_router as profile_router
|
||||
from api.endpoints.account import api_router as account_router
|
||||
from api.endpoints.keyring import api_router as keyring_router
|
||||
from api.endpoints.listevents import api_router as listevents_router
|
||||
from api.endpoints.processschema import api_router as processschema_router
|
||||
from api.endpoints.process_schema import api_router as processschema_router
|
||||
|
||||
list_of_routes = [auth_router, profile_router, account_router, keyring_router, listevents_router, processschema_router]
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
|
||||
from typing import Optional, Dict, Any, List
|
||||
from typing import Optional, List
|
||||
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.processschema import (
|
||||
from api.db.logic.process_schema import (
|
||||
get_process_schema_by_title,
|
||||
create_process_schema,
|
||||
get_process_schema_by_id,
|
||||
@@ -32,7 +32,7 @@ from api.services.user_role_validation import (
|
||||
|
||||
|
||||
api_router = APIRouter(
|
||||
prefix="/process-schema",
|
||||
prefix="/process_schema",
|
||||
tags=["process schema"],
|
||||
)
|
||||
|
||||
@@ -78,40 +78,40 @@ async def get_all_process_schema(
|
||||
return process_schema_page
|
||||
|
||||
|
||||
@api_router.get("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
@api_router.get("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def get_process_schema(
|
||||
processschema_id: int,
|
||||
process_schema_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
processschema_validation = await get_process_schema_by_id(connection, processschema_id)
|
||||
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
|
||||
|
||||
if processschema_validation is None:
|
||||
if process_schema_validation is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||
|
||||
authorize_user = await db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
|
||||
connection, current_user, processschema_validation.creator_id
|
||||
connection, current_user, process_schema_validation.creator_id
|
||||
)
|
||||
|
||||
if processschema_id is None:
|
||||
if process_schema_id is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||
|
||||
return processschema_validation
|
||||
return process_schema_validation
|
||||
|
||||
|
||||
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def create_processschema(
|
||||
processschema: ProcessSchemaUpdate,
|
||||
process_schema: ProcessSchemaUpdate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
user_validation = await get_user_by_login(connection, current_user)
|
||||
processschema_validation = await get_process_schema_by_title(connection, processschema.title)
|
||||
process_schema_validation = await get_process_schema_by_title(connection, process_schema.title)
|
||||
|
||||
if processschema_validation is None:
|
||||
await create_process_schema(connection, processschema, user_validation.id)
|
||||
processschema_new = await get_process_schema_by_title(connection, processschema.title)
|
||||
return processschema_new
|
||||
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
|
||||
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -119,58 +119,58 @@ async def create_processschema(
|
||||
)
|
||||
|
||||
|
||||
@api_router.put("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
@api_router.put("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def update_process_schema(
|
||||
processschema_id: int,
|
||||
processschema_update: ProcessSchemaUpdate,
|
||||
process_schema_id: int,
|
||||
process_schema_update: ProcessSchemaUpdate,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
processschema_validation = await get_process_schema_by_id(connection, processschema_id)
|
||||
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
|
||||
|
||||
if processschema_validation is None:
|
||||
if process_schema_validation is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||
|
||||
authorize_user = await db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
|
||||
connection, current_user, processschema_validation.creator_id
|
||||
connection, current_user, process_schema_validation.creator_id
|
||||
)
|
||||
|
||||
updated_values = processschema_update.model_dump(by_alias=True, exclude_none=True)
|
||||
updated_values = process_schema_update.model_dump(by_alias=True, exclude_none=True)
|
||||
|
||||
if not updated_values:
|
||||
return processschema_validation
|
||||
return process_schema_validation
|
||||
|
||||
await update_process_schema_by_id(connection, updated_values, processschema_validation)
|
||||
await update_process_schema_by_id(connection, updated_values, process_schema_validation)
|
||||
|
||||
processschema = await get_process_schema_by_id(connection, processschema_id)
|
||||
process_schema = await get_process_schema_by_id(connection, process_schema_id)
|
||||
|
||||
return processschema
|
||||
return process_schema
|
||||
|
||||
|
||||
@api_router.delete("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
@api_router.delete("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||
async def delete_process_schema(
|
||||
processschema_id: int,
|
||||
process_schema_id: int,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
processschema_validation = await get_process_schema_by_id(connection, processschema_id)
|
||||
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
|
||||
|
||||
if processschema_validation is None:
|
||||
if process_schema_validation is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||
|
||||
authorize_user = await db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
|
||||
connection, current_user, processschema_validation.creator_id
|
||||
connection, current_user, process_schema_validation.creator_id
|
||||
)
|
||||
|
||||
processschema_update = ProcessSchemaUpdate(status=ProcessStatus.DELETED.value)
|
||||
process_schema_update = ProcessSchemaUpdate(status=ProcessStatus.DELETED.value)
|
||||
|
||||
updated_values = processschema_update.model_dump(by_alias=True, exclude_none=True)
|
||||
updated_values = process_schema_update.model_dump(by_alias=True, exclude_none=True)
|
||||
|
||||
if not updated_values:
|
||||
return processschema_validation
|
||||
return process_schema_validation
|
||||
|
||||
await update_process_schema_by_id(connection, updated_values, processschema_validation)
|
||||
await update_process_schema_by_id(connection, updated_values, process_schema_validation)
|
||||
|
||||
processschema = await get_process_schema_by_id(connection, processschema_id)
|
||||
process_schema = await get_process_schema_by_id(connection, process_schema_id)
|
||||
|
||||
return processschema
|
||||
return process_schema
|
@@ -38,12 +38,7 @@ all_list_event_adapter = TypeAdapter(List[AllListEvent])
|
||||
|
||||
|
||||
class ListEventFilterDTO(Base):
|
||||
pagination: Dict[str, int] = Field(
|
||||
default={"page": 1, "limit": 10},
|
||||
description="Пагинация (номер страницы и количество элементов)",
|
||||
)
|
||||
search: Optional[str] = Field(default=None, description="Поиск по текстовым полям (name, title)")
|
||||
order: Optional[Dict[str, str]] = Field(
|
||||
default={"field": "id", "direction": "asc"}, description="Сортировка (поле и направление)"
|
||||
)
|
||||
filters: Optional[Dict[str, List[str]]] = Field(default=None, description="Фильтрация по точным значениям")
|
||||
pagination: Dict[str, int]
|
||||
search: Optional[str] = None
|
||||
order: Optional[Dict[str, str]] = None
|
||||
filters: Optional[Dict[str, List[str]]] = None
|
||||
|
Reference in New Issue
Block a user