feat: CRUD ProcessSchema

This commit is contained in:
TheNoxium
2025-07-27 22:17:36 +05:00
parent 5e3c3b4672
commit e0887c240f
15 changed files with 449 additions and 62 deletions

View File

@@ -3,8 +3,9 @@ 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
list_of_routes = [auth_router, profile_router, account_router, keyring_router, listevents_router]
list_of_routes = [auth_router, profile_router, account_router, keyring_router, listevents_router,processschema_router]
__all__ = [
"list_of_routes",

View File

@@ -32,8 +32,8 @@ from api.schemas.endpoints.list_events import ListEventUpdate, AllListEventRespo
from api.services.auth import get_current_user
from api.services.user_role_validation import (
db_user_role_validation_for_listevents_by_listevent_id,
db_user_role_validation_for_listevents,
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_listevents_data_changes
@@ -51,22 +51,22 @@ async def get_all_list_events(
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
authorize_user, page_flag = await db_user_role_validation_for_listevents(connection, current_user)
authorize_user, page_flag = await db_user_role_validation_for_listevents_and_processschema(connection, current_user)
if page_flag:
list_eventslist = await get_listevents_page(connection, page, limit)
print(list_eventslist)
if list_eventslist is None:
list_eventspage = await get_listevents_page(connection, page, limit)
if list_eventspage is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
return list_eventslist
return list_eventspage
else:
list_events_list = await get_listevents_page_by_creator_id(connection, authorize_user.id, page, limit)
list_events_page = await get_listevents_page_by_creator_id(connection, authorize_user.id, page, limit)
if list_events_list is None:
if list_events_page is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
return list_events_list
return list_events_page
@api_router.get("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
@@ -80,7 +80,7 @@ async def get_list_events(
if listevents_validation is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
authorize_user = await db_user_role_validation_for_listevents_by_listevent_id(
authorize_user = await db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
connection, current_user, listevents_validation.creator_id
)
@@ -111,7 +111,7 @@ async def create_list_events(
@api_router.put("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
async def update_listevents(
async def update_list_events(
listevents_id: int,
listevents_update: ListEventUpdate,
connection: AsyncConnection = Depends(get_connection_dep),
@@ -122,7 +122,7 @@ async def update_listevents(
if listevents_validation is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
authorize_user = await db_user_role_validation_for_listevents_by_listevent_id(
authorize_user = await db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
connection, current_user, listevents_validation.creator_id
)
@@ -151,7 +151,7 @@ async def delete_list_events(
if listevents_validation is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
authorize_user = await db_user_role_validation_for_listevents_by_listevent_id(
authorize_user = await db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
connection, current_user, listevents_validation.creator_id
)

View File

@@ -0,0 +1,167 @@
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.db.logic.processschema import (
get_processschema_by_title,
create_processschema,
get_processschema_by_id,
update_processschema_by_id,
get_processschema_page_by_creator_id,
get_processschema_page
)
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
from api.services.auth import get_current_user
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(
prefix="/processschema",
tags=["process schema"],
)
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllProcessSchemaResponse)
async def get_all_process_schema(
page: int = 1,
limit: int = 10,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
authorize_user, page_flag = await db_user_role_validation_for_listevents_and_processschema(connection, current_user)
if page_flag:
process_schemapage = await get_processschema_page(connection, page, limit)
if process_schemapage is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
return process_schemapage
else:
process_schema_page = await get_processschema_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")
return process_schema_page
@api_router.get("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def get_process_schema(
processschema_id: int,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
processschema_validation = await get_processschema_by_id(connection, processschema_id)
if processschema_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
)
if processschema_id is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
return processschema_validation
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def create_process_schema(
processschema: 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_processschema_by_title(connection, processschema.title)
if processschema_validation is None:
await create_processschema(connection, processschema, user_validation.id)
processschema_new = await get_processschema_by_title(connection, processschema.title)
return processschema_new
else:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, detail="An process schema with this information already exists."
)
@api_router.put("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def update_process_schema(
processschema_id: int,
processschema_update: ProcessSchemaUpdate,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
processschema_validation = await get_processschema_by_id(connection, processschema_id)
if processschema_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
)
update_values = update_processschema_data_changes(processschema_update, processschema_validation)
if update_values is None:
return processschema_validation
processschema_update_data = ProcessSchema.model_validate({**processschema_validation.model_dump(), **update_values})
await update_processschema_by_id(connection, update_values, processschema_validation)
processschema = await get_processschema_by_id(connection, processschema_id)
return processschema
@api_router.delete("/{processschema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def delete_process_schema(
processschema_id: int,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
processschema_validation = await get_processschema_by_id(connection, processschema_id)
if processschema_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
)
processschema_update = ProcessSchemaUpdate(status=ProcessStatus.DELETED.value)
update_values = update_processschema_data_changes(processschema_update, processschema_validation)
if update_values is None:
return processschema_validation
await update_processschema_by_id(connection, update_values, processschema_validation)
processschema = await get_processschema_by_id(connection, processschema_id)
return processschema

View File

@@ -1,11 +1,7 @@
from fastapi import (
APIRouter,
Body,
Depends,
Form,
HTTPException,
Request,
Response,
status,
)