|
|
|
@@ -3,8 +3,10 @@ from fastapi import (
|
|
|
|
|
Depends,
|
|
|
|
|
HTTPException,
|
|
|
|
|
status,
|
|
|
|
|
Query
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
from typing import Optional, Dict, Any, List
|
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
|
|
|
|
|
|
|
|
|
from api.db.connection.session import get_connection_dep
|
|
|
|
@@ -16,7 +18,6 @@ from api.db.logic.processschema import (
|
|
|
|
|
create_process_schema,
|
|
|
|
|
get_process_schema_by_id,
|
|
|
|
|
update_process_schema_by_id,
|
|
|
|
|
get_process_schema_page_by_creator_id,
|
|
|
|
|
get_process_schema_page,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -26,7 +27,7 @@ from api.db.tables.process import ProcessStatus
|
|
|
|
|
|
|
|
|
|
from api.schemas.base import bearer_schema
|
|
|
|
|
|
|
|
|
|
from api.schemas.endpoints.process_schema import ProcessSchemaUpdate, AllProcessSchemaResponse
|
|
|
|
|
from api.schemas.endpoints.process_schema import ProcessSchemaUpdate, AllProcessSchemaResponse, ProcessSchemaFilterDTO
|
|
|
|
|
|
|
|
|
|
from api.services.auth import get_current_user
|
|
|
|
|
|
|
|
|
@@ -34,7 +35,6 @@ from api.services.user_role_validation import (
|
|
|
|
|
db_user_role_validation_for_listevents_and_processschema_by_listevent_id,
|
|
|
|
|
db_user_role_validation_for_listevents_and_processschema,
|
|
|
|
|
)
|
|
|
|
|
from api.services.update_data_validation import update_processschema_data_changes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api_router = APIRouter(
|
|
|
|
@@ -45,27 +45,47 @@ api_router = APIRouter(
|
|
|
|
|
|
|
|
|
|
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllProcessSchemaResponse)
|
|
|
|
|
async def get_all_process_schema(
|
|
|
|
|
page: int = 1,
|
|
|
|
|
limit: int = 10,
|
|
|
|
|
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"),
|
|
|
|
|
order_field: Optional[str] = Query("id", description="Field to sort by"),
|
|
|
|
|
order_direction: Optional[str] = Query("asc", description="Sort direction (asc/desc)"),
|
|
|
|
|
status_filter: Optional[List[str]] = Query(None, description="Filter by status"),
|
|
|
|
|
owner_id: Optional[List[str]] = Query(None, description="Filter by owner ID"),
|
|
|
|
|
connection: AsyncConnection = Depends(get_connection_dep),
|
|
|
|
|
creator_id: Optional[int] = Query(None, description="Filter by creator ID"),
|
|
|
|
|
current_user=Depends(get_current_user),
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
filters = {
|
|
|
|
|
**({"status": status_filter} if status_filter else {}),
|
|
|
|
|
**({"owner_id": owner_id} if owner_id else {}),
|
|
|
|
|
**({"creator_id": [str(creator_id)]} if creator_id else {}),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filter_dto = ProcessSchemaFilterDTO(
|
|
|
|
|
pagination={"page": page, "limit": limit},
|
|
|
|
|
search=search,
|
|
|
|
|
order={"field": order_field, "direction": order_direction},
|
|
|
|
|
filters=filters if filters else None
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
authorize_user, page_flag = await db_user_role_validation_for_listevents_and_processschema(connection, current_user)
|
|
|
|
|
|
|
|
|
|
if page_flag:
|
|
|
|
|
process_schema_page = await get_process_schema_page(connection, page, limit)
|
|
|
|
|
if not page_flag:
|
|
|
|
|
if filter_dto.filters is None:
|
|
|
|
|
filter_dto.filters = {}
|
|
|
|
|
filter_dto.filters["creator_id"] = [str(authorize_user.id)]
|
|
|
|
|
|
|
|
|
|
if process_schema_page is None:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
|
|
|
|
process_schema_page = await get_process_schema_page(connection, filter_dto)
|
|
|
|
|
|
|
|
|
|
return process_schema_page
|
|
|
|
|
else:
|
|
|
|
|
process_schema_page = await get_process_schema_page_by_creator_id(connection, authorize_user.id, page, limit)
|
|
|
|
|
if process_schema_page is None:
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
|
detail="Process schema not found"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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 process_schema_page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@api_router.get("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
|
|
|
|