fix: rename list events
This commit is contained in:
		@@ -14,7 +14,7 @@ from api.schemas.events.list_events import ListEvent
 | 
			
		||||
from api.schemas.endpoints.list_events import all_list_event_adapter, AllListEventResponse, ListEventFilterDTO
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_listevents_page_DTO(
 | 
			
		||||
async def get_list_events_page_DTO(
 | 
			
		||||
    connection: AsyncConnection, filter_dto: ListEventFilterDTO
 | 
			
		||||
) -> Optional[AllListEventResponse]:
 | 
			
		||||
    """
 | 
			
		||||
@@ -121,7 +121,7 @@ async def get_listevents_page_DTO(
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_listevents_page_by_creator_id(
 | 
			
		||||
async def get_list_events_page_by_creator_id(
 | 
			
		||||
    connection: AsyncConnection, creator_id: int, page: int, limit: int
 | 
			
		||||
) -> Optional[AllListEventResponse]:
 | 
			
		||||
    """
 | 
			
		||||
@@ -171,7 +171,7 @@ async def get_listevents_page_by_creator_id(
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optional[AllListEventResponse]:
 | 
			
		||||
async def get_list_events_page(connection: AsyncConnection, page, limit) -> Optional[AllListEventResponse]:
 | 
			
		||||
    """
 | 
			
		||||
    Получает список событий заданного создателя по значениям page и limit.
 | 
			
		||||
    """
 | 
			
		||||
@@ -215,63 +215,65 @@ async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optio
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_listevents_by_name(connection: AsyncConnection, name: str) -> Optional[ListEvent]:
 | 
			
		||||
async def get_list_events_by_name(connection: AsyncConnection, name: str) -> Optional[ListEvent]:
 | 
			
		||||
    """
 | 
			
		||||
    Получает list events  по name.
 | 
			
		||||
    """
 | 
			
		||||
    query = select(list_events_table).where(list_events_table.c.name == name)
 | 
			
		||||
 | 
			
		||||
    listevents_db_cursor = await connection.execute(query)
 | 
			
		||||
    list_events_db_cursor = await connection.execute(query)
 | 
			
		||||
 | 
			
		||||
    listevents_data = listevents_db_cursor.mappings().one_or_none()
 | 
			
		||||
    if not listevents_data:
 | 
			
		||||
    list_events_data = list_events_db_cursor.mappings().one_or_none()
 | 
			
		||||
    if not list_events_data:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    return ListEvent.model_validate(listevents_data)
 | 
			
		||||
    return ListEvent.model_validate(list_events_data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_listevents_by_id(connection: AsyncConnection, id: int) -> Optional[ListEvent]:
 | 
			
		||||
async def get_list_events_by_id(connection: AsyncConnection, id: int) -> Optional[ListEvent]:
 | 
			
		||||
    """
 | 
			
		||||
    Получает listevent по id.
 | 
			
		||||
    """
 | 
			
		||||
    query = select(list_events_table).where(list_events_table.c.id == id)
 | 
			
		||||
 | 
			
		||||
    listevents_db_cursor = await connection.execute(query)
 | 
			
		||||
    list_events_db_cursor = await connection.execute(query)
 | 
			
		||||
 | 
			
		||||
    listevents_data = listevents_db_cursor.mappings().one_or_none()
 | 
			
		||||
    if not listevents_data:
 | 
			
		||||
    list_events_data = list_events_db_cursor.mappings().one_or_none()
 | 
			
		||||
    if not list_events_data:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    return ListEvent.model_validate(listevents_data)
 | 
			
		||||
    return ListEvent.model_validate(list_events_data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def update_listevents_by_id(connection: AsyncConnection, update_values, listevents):
 | 
			
		||||
async def update_list_events_by_id(connection: AsyncConnection, update_values, list_events):
 | 
			
		||||
    """
 | 
			
		||||
    Вносит изменеия в нужное поле таблицы list_events_table.
 | 
			
		||||
    """
 | 
			
		||||
    await connection.execute(
 | 
			
		||||
        list_events_table.update().where(list_events_table.c.id == listevents.id).values(**update_values)
 | 
			
		||||
        list_events_table.update().where(list_events_table.c.id == list_events.id).values(**update_values)
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    await connection.commit()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def create_listevents(connection: AsyncConnection, listevents: ListEvent, creator_id: int) -> Optional[ListEvent]:
 | 
			
		||||
async def create_list_events(
 | 
			
		||||
    connection: AsyncConnection, list_events: ListEvent, creator_id: int
 | 
			
		||||
) -> Optional[ListEvent]:
 | 
			
		||||
    """
 | 
			
		||||
    Создает нове поле в таблице list_events_table.
 | 
			
		||||
    """
 | 
			
		||||
    query = insert(list_events_table).values(
 | 
			
		||||
        name=listevents.name,
 | 
			
		||||
        title=listevents.title,  # добавлено поле title
 | 
			
		||||
        name=list_events.name,
 | 
			
		||||
        title=list_events.title,  # добавлено поле title
 | 
			
		||||
        creator_id=creator_id,
 | 
			
		||||
        created_at=datetime.now(timezone.utc),
 | 
			
		||||
        schema=listevents.schema_,  # добавлено поле schema
 | 
			
		||||
        state=listevents.state.value,  # добавлено поле state
 | 
			
		||||
        status=listevents.status.value,  # добавлено поле status
 | 
			
		||||
        schema=list_events.schema_,  # добавлено поле schema
 | 
			
		||||
        state=list_events.state.value,  # добавлено поле state
 | 
			
		||||
        status=list_events.status.value,  # добавлено поле status
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    await connection.execute(query)
 | 
			
		||||
 | 
			
		||||
    await connection.commit()
 | 
			
		||||
 | 
			
		||||
    return listevents
 | 
			
		||||
    return list_events
 | 
			
		||||
@@ -2,7 +2,7 @@ from api.endpoints.auth import api_router as auth_router
 | 
			
		||||
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.list_events import api_router as listevents_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]
 | 
			
		||||
 
 | 
			
		||||
@@ -8,12 +8,12 @@ from api.db.connection.session import get_connection_dep
 | 
			
		||||
 | 
			
		||||
from api.db.logic.account import get_user_by_login
 | 
			
		||||
 | 
			
		||||
from api.db.logic.listevents import (
 | 
			
		||||
    get_listevents_by_name,
 | 
			
		||||
    get_listevents_by_id,
 | 
			
		||||
    create_listevents,
 | 
			
		||||
    update_listevents_by_id,
 | 
			
		||||
    get_listevents_page_DTO,
 | 
			
		||||
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_page_DTO,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -27,13 +27,13 @@ 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_and_processschema_by_listevent_id,
 | 
			
		||||
    db_user_role_validation_for_listevents_and_processschema,
 | 
			
		||||
    db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
 | 
			
		||||
    db_user_role_validation_for_list_events_and_process_schema,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
api_router = APIRouter(
 | 
			
		||||
    prefix="/listevents",
 | 
			
		||||
    prefix="/list_events",
 | 
			
		||||
    tags=["list events"],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -53,8 +53,8 @@ async def get_all_list_events(
 | 
			
		||||
):
 | 
			
		||||
    filters = {
 | 
			
		||||
        **({"status": status_filter} if status_filter else {}),
 | 
			
		||||
        **({"creator_id": [str(creator_id)]} if creator_id else {}),
 | 
			
		||||
        **({"state": state_filter} if state_filter else {}),
 | 
			
		||||
        **({"creator_id": [str(creator_id)]} if creator_id else {}),
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    filter_dto = ListEventFilterDTO(
 | 
			
		||||
@@ -64,14 +64,16 @@ async def get_all_list_events(
 | 
			
		||||
        filters=filters if filters else None,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    authorize_user, page_flag = await db_user_role_validation_for_listevents_and_processschema(connection, current_user)
 | 
			
		||||
    authorize_user, page_flag = await db_user_role_validation_for_list_events_and_process_schema(
 | 
			
		||||
        connection, current_user
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    if not page_flag:
 | 
			
		||||
        if filter_dto.filters is None:
 | 
			
		||||
            filter_dto.filters = {}
 | 
			
		||||
        filter_dto.filters["creator_id"] = [str(authorize_user.id)]
 | 
			
		||||
 | 
			
		||||
    list_events_page = await get_listevents_page_DTO(connection, filter_dto)
 | 
			
		||||
    list_events_page = await get_list_events_page_DTO(connection, filter_dto)
 | 
			
		||||
 | 
			
		||||
    if list_events_page is None:
 | 
			
		||||
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
 | 
			
		||||
@@ -79,40 +81,40 @@ async def get_all_list_events(
 | 
			
		||||
    return list_events_page
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@api_router.get("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
@api_router.get("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
async def get_list_events(
 | 
			
		||||
    listevents_id: int,
 | 
			
		||||
    list_events_id: int,
 | 
			
		||||
    connection: AsyncConnection = Depends(get_connection_dep),
 | 
			
		||||
    current_user=Depends(get_current_user),
 | 
			
		||||
):
 | 
			
		||||
    listevents_validation = await get_listevents_by_id(connection, listevents_id)
 | 
			
		||||
    list_events_validation = await get_list_events_by_id(connection, list_events_id)
 | 
			
		||||
 | 
			
		||||
    if listevents_validation is None:
 | 
			
		||||
    if list_events_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_and_processschema_by_listevent_id(
 | 
			
		||||
        connection, current_user, listevents_validation.creator_id
 | 
			
		||||
    authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
        connection, current_user, list_events_validation.creator_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    if listevents_id is None:
 | 
			
		||||
    if list_events_id is None:
 | 
			
		||||
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
 | 
			
		||||
 | 
			
		||||
    return listevents_validation
 | 
			
		||||
    return list_events_validation
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
async def create_list_events(
 | 
			
		||||
    listevents: ListEventUpdate,
 | 
			
		||||
    list_events: ListEventUpdate,
 | 
			
		||||
    connection: AsyncConnection = Depends(get_connection_dep),
 | 
			
		||||
    current_user=Depends(get_current_user),
 | 
			
		||||
):
 | 
			
		||||
    user_validation = await get_user_by_login(connection, current_user)
 | 
			
		||||
    listevents_validation = await get_listevents_by_name(connection, listevents.name)
 | 
			
		||||
    list_events_validation = await get_list_events_by_name(connection, list_events.name)
 | 
			
		||||
 | 
			
		||||
    if listevents_validation is None:
 | 
			
		||||
        await create_listevents(connection, listevents, user_validation.id)
 | 
			
		||||
        listevents_new = await get_listevents_by_name(connection, listevents.name)
 | 
			
		||||
        return listevents_new
 | 
			
		||||
    if list_events_validation is None:
 | 
			
		||||
        await create_list_events(connection, list_events, user_validation.id)
 | 
			
		||||
        list_events_new = await get_list_events_by_name(connection, list_events.name)
 | 
			
		||||
        return list_events_new
 | 
			
		||||
 | 
			
		||||
    else:
 | 
			
		||||
        raise HTTPException(
 | 
			
		||||
@@ -120,58 +122,58 @@ async def create_list_events(
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@api_router.put("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
@api_router.put("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
async def update_list_events(
 | 
			
		||||
    listevents_id: int,
 | 
			
		||||
    listevents_update: ListEventUpdate,
 | 
			
		||||
    list_events_id: int,
 | 
			
		||||
    list_events_update: ListEventUpdate,
 | 
			
		||||
    connection: AsyncConnection = Depends(get_connection_dep),
 | 
			
		||||
    current_user=Depends(get_current_user),
 | 
			
		||||
):
 | 
			
		||||
    listevents_validation = await get_listevents_by_id(connection, listevents_id)
 | 
			
		||||
    list_events_validation = await get_list_events_by_id(connection, list_events_id)
 | 
			
		||||
 | 
			
		||||
    if listevents_validation is None:
 | 
			
		||||
    if list_events_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_and_processschema_by_listevent_id(
 | 
			
		||||
        connection, current_user, listevents_validation.creator_id
 | 
			
		||||
    authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
        connection, current_user, list_events_validation.creator_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    updated_values = listevents_update.model_dump(by_alias=True, exclude_none=True)
 | 
			
		||||
    updated_values = list_events_update.model_dump(by_alias=True, exclude_none=True)
 | 
			
		||||
 | 
			
		||||
    if not updated_values:
 | 
			
		||||
        return listevents_validation
 | 
			
		||||
        return list_events_validation
 | 
			
		||||
 | 
			
		||||
    await update_listevents_by_id(connection, updated_values, listevents_validation)
 | 
			
		||||
    await update_list_events_by_id(connection, updated_values, list_events_validation)
 | 
			
		||||
 | 
			
		||||
    listevents = await get_listevents_by_id(connection, listevents_id)
 | 
			
		||||
    list_events = await get_list_events_by_id(connection, list_events_id)
 | 
			
		||||
 | 
			
		||||
    return listevents
 | 
			
		||||
    return list_events
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@api_router.delete("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
@api_router.delete("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
 | 
			
		||||
async def delete_list_events(
 | 
			
		||||
    listevents_id: int,
 | 
			
		||||
    list_events_id: int,
 | 
			
		||||
    connection: AsyncConnection = Depends(get_connection_dep),
 | 
			
		||||
    current_user=Depends(get_current_user),
 | 
			
		||||
):
 | 
			
		||||
    listevents_validation = await get_listevents_by_id(connection, listevents_id)
 | 
			
		||||
    list_events_validation = await get_list_events_by_id(connection, list_events_id)
 | 
			
		||||
 | 
			
		||||
    if listevents_validation is None:
 | 
			
		||||
    if list_events_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_and_processschema_by_listevent_id(
 | 
			
		||||
        connection, current_user, listevents_validation.creator_id
 | 
			
		||||
    authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
        connection, current_user, list_events_validation.creator_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    listevents_update = ListEventUpdate(status=EventStatus.DELETED.value)
 | 
			
		||||
    list_events_update = ListEventUpdate(status=EventStatus.DELETED.value)
 | 
			
		||||
 | 
			
		||||
    updated_values = listevents_update.model_dump(by_alias=True, exclude_none=True)
 | 
			
		||||
    updated_values = list_events_update.model_dump(by_alias=True, exclude_none=True)
 | 
			
		||||
 | 
			
		||||
    if not updated_values:
 | 
			
		||||
        return listevents_validation
 | 
			
		||||
        return list_events_validation
 | 
			
		||||
 | 
			
		||||
    await update_listevents_by_id(connection, updated_values, listevents_validation)
 | 
			
		||||
    await update_list_events_by_id(connection, updated_values, list_events_validation)
 | 
			
		||||
 | 
			
		||||
    listevents = await get_listevents_by_id(connection, listevents_id)
 | 
			
		||||
    list_events = await get_list_events_by_id(connection, list_events_id)
 | 
			
		||||
 | 
			
		||||
    return listevents
 | 
			
		||||
    return list_events
 | 
			
		||||
@@ -26,8 +26,8 @@ from api.schemas.endpoints.process_schema import ProcessSchemaUpdate, AllProcess
 | 
			
		||||
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,
 | 
			
		||||
    db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
 | 
			
		||||
    db_user_role_validation_for_list_events_and_process_schema,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -63,7 +63,9 @@ async def get_all_process_schema(
 | 
			
		||||
        filters=filters if filters else None,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    authorize_user, page_flag = await db_user_role_validation_for_listevents_and_processschema(connection, current_user)
 | 
			
		||||
    authorize_user, page_flag = await db_user_role_validation_for_list_events_and_process_schema(
 | 
			
		||||
        connection, current_user
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    if not page_flag:
 | 
			
		||||
        if filter_dto.filters is None:
 | 
			
		||||
@@ -89,7 +91,7 @@ async def get_process_schema(
 | 
			
		||||
    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(
 | 
			
		||||
    authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
        connection, current_user, process_schema_validation.creator_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
@@ -131,7 +133,7 @@ async def update_process_schema(
 | 
			
		||||
    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(
 | 
			
		||||
    authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
        connection, current_user, process_schema_validation.creator_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
@@ -158,7 +160,7 @@ async def delete_process_schema(
 | 
			
		||||
    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(
 | 
			
		||||
    authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
        connection, current_user, process_schema_validation.creator_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ async def db_user_role_validation(connection, current_user):
 | 
			
		||||
    return authorize_user
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def db_user_role_validation_for_listevents_and_processschema_by_listevent_id(
 | 
			
		||||
async def db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
 | 
			
		||||
    connection, current_user, current_listevents_creator_id
 | 
			
		||||
):
 | 
			
		||||
    authorize_user = await get_user_by_login(connection, current_user)
 | 
			
		||||
@@ -23,7 +23,7 @@ async def db_user_role_validation_for_listevents_and_processschema_by_listevent_
 | 
			
		||||
    return authorize_user
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def db_user_role_validation_for_listevents_and_processschema(connection, current_user):
 | 
			
		||||
async def db_user_role_validation_for_list_events_and_process_schema(connection, current_user):
 | 
			
		||||
    authorize_user = await get_user_by_login(connection, current_user)
 | 
			
		||||
    if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
 | 
			
		||||
        return authorize_user, False
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user