From f550b86c681e65e740c29dd1fdbce1cca13719ee Mon Sep 17 00:00:00 2001 From: TheNoxium Date: Mon, 30 Jun 2025 15:37:07 +0500 Subject: [PATCH 1/6] feat: CRUD ListEvent --- api/api/db/logic/listevents.py | 173 ++++++++++++++++++++ api/api/db/tables/account.py | 2 - api/api/endpoints/__init__.py | 3 +- api/api/endpoints/listevents.py | 174 +++++++++++++++++++++ api/api/schemas/endpoints/list_events.py | 37 +++++ api/api/schemas/events/list_events.py | 17 +- api/api/services/update_data_validation.py | 35 +++++ api/api/services/user_role_validation.py | 14 ++ 8 files changed, 438 insertions(+), 17 deletions(-) create mode 100644 api/api/db/logic/listevents.py create mode 100644 api/api/endpoints/listevents.py create mode 100644 api/api/schemas/endpoints/list_events.py diff --git a/api/api/db/logic/listevents.py b/api/api/db/logic/listevents.py new file mode 100644 index 0000000..7f1d0e1 --- /dev/null +++ b/api/api/db/logic/listevents.py @@ -0,0 +1,173 @@ +from typing import Optional +import math + +from datetime import datetime, timezone + +from sqlalchemy import insert, select, func +from sqlalchemy.ext.asyncio import AsyncConnection +from enum import Enum + +from api.db.tables.events import list_events_table + + +from api.schemas.events.list_events import ListEvent + + +from api.schemas.endpoints.list_events import all_list_event_adapter,AllListEventResponse + + +async def get_listevents_page_by_creator_id(connection: AsyncConnection, creator_id: int, page: int, limit: int) -> Optional[AllListEventResponse]: + """ + Получает список событий заданного создателя по значениям page и limit и creator_id. + """ + + first_event = page * limit - limit + print(creator_id) + query = ( + select( + list_events_table.c.id, + list_events_table.c.name, + list_events_table.c.title, + list_events_table.c.creator_id, + list_events_table.c.created_at, + list_events_table.c.schema, + list_events_table.c.state, + list_events_table.c.status, + ) + .where(list_events_table.c.creator_id == creator_id) # Фильтрация по creator_id + .order_by(list_events_table.c.id) + .offset(first_event) + .limit(limit) + ) + + count_query = ( + select(func.count()) + .select_from(list_events_table) + .where(list_events_table.c.creator_id == creator_id) # Фильтрация по creator_id + ) + + result = await connection.execute(query) + count_result = await connection.execute(count_query) + + events_data = result.mappings().all() + total_count = count_result.scalar() + total_pages = math.ceil(total_count / limit) + + # Здесь предполагается, что all_list_event_adapter.validate_python корректно обрабатывает данные + validated_list_event = all_list_event_adapter.validate_python(events_data) + + return AllListEventResponse(list_event=validated_list_event, amount_count=total_count, amount_pages=total_pages) + + +async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optional[ListEvent]: + """ + Получает список ползовелей заданных значениями page, limit. + """ + + first_event = page * limit - (limit) + + query = ( + select( + list_events_table.c.id, + list_events_table.c.name, + list_events_table.c.title, + list_events_table.c.creator_id, + list_events_table.c.created_at, + list_events_table.c.schema, + list_events_table.c.state, + list_events_table.c.status, + ) + .order_by(list_events_table.c.id) + .offset(first_event) + .limit(limit) + ) + + count_query = select(func.count()).select_from(list_events_table) + + result = await connection.execute(query) + count_result = await connection.execute(count_query) + + events_data = result.mappings().all() + total_count = count_result.scalar() + total_pages = math.ceil(total_count / limit) + + # Здесь предполагается, что all_list_event_adapter.validate_python корректно обрабатывает данные + validated_list_event = all_list_event_adapter.validate_python(events_data) + + return AllListEventResponse(list_event=validated_list_event, amount_count=total_count, amount_pages=total_pages) + +async def get_listevents_by_name(connection: AsyncConnection, name: str) -> Optional[ListEvent]: + """ + Получает юзера по login. + """ + query = select(list_events_table).where(list_events_table.c.name == name) + + listevents_db_cursor = await connection.execute(query) + listevents_db = listevents_db_cursor.one_or_none() + + if not listevents_db: + return None + + listevents_data = { + column.name: ( + getattr(listevents_db, column.name).name + if isinstance(getattr(listevents_db, column.name), Enum) + else getattr(listevents_db, column.name) + ) + for column in list_events_table.columns + } + + return ListEvent.model_validate(listevents_data) + +async def get_listevents_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) + listevents_db = listevents_db_cursor.one_or_none() + + if not listevents_db: + return None + + listevents_data = { + column.name: ( + getattr(listevents_db, column.name).name + if isinstance(getattr(listevents_db, column.name), Enum) + else getattr(listevents_db, column.name) + ) + for column in list_events_table.columns + } + + return ListEvent.model_validate(listevents_data) + +async def update_listevents_by_id(connection: AsyncConnection, update_values, listevents) -> Optional[ListEvent]: + """ + Вносит изменеия в нужное поле таблицы account_table. + """ + await connection.execute(list_events_table.update().where(list_events_table.c.id == listevents.id).values(**update_values)) + + await connection.commit() + + + +async def create_listevents(connection: AsyncConnection, listevents: ListEvent, creator_id: int) -> Optional[ListEvent]: + """ + Создает нове поле в таблице list_events_table. + """ + query = insert(list_events_table).values( + name=listevents.name, + title=listevents.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 + ) + + await connection.execute(query) + + await connection.commit() + + return listevents diff --git a/api/api/db/tables/account.py b/api/api/db/tables/account.py index 84c689e..1650378 100644 --- a/api/api/db/tables/account.py +++ b/api/api/db/tables/account.py @@ -3,8 +3,6 @@ import enum from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index from sqlalchemy.sql import func -from enum import Enum - from api.db.sql_types import UnsignedInt from api.db import metadata diff --git a/api/api/endpoints/__init__.py b/api/api/endpoints/__init__.py index 6e98978..0a51e78 100644 --- a/api/api/endpoints/__init__.py +++ b/api/api/endpoints/__init__.py @@ -2,8 +2,9 @@ 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 -list_of_routes = [auth_router, profile_router, account_router, keyring_router] +list_of_routes = [auth_router, profile_router, account_router, keyring_router,listevents_router] __all__ = [ "list_of_routes", diff --git a/api/api/endpoints/listevents.py b/api/api/endpoints/listevents.py new file mode 100644 index 0000000..a9d6fce --- /dev/null +++ b/api/api/endpoints/listevents.py @@ -0,0 +1,174 @@ +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.listevents import ( + get_listevents_by_name, + get_listevents_by_id, + create_listevents, + update_listevents_by_id, + get_listevents_page, + get_listevents_page_by_creator_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 + +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 +from api.services.update_data_validation import update_listevents_data_changes + + +api_router = APIRouter( + prefix="/listevents", + tags=["list events"], +) + +@api_router.get("", + dependencies=[Depends(bearer_schema)], + response_model=AllListEventResponse) +async def get_all_list_events( + 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(connection, current_user) + + if page_flag: + + list_eventslist = await get_listevents_page(connection, page, limit) + print(list_eventslist) + if list_eventslist is None: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found") + + return list_eventslist + else: + list_events_list = await get_listevents_page_by_creator_id(connection,authorize_user.id, page, limit) + + if list_events_list is None: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found") + + return list_events_list + + + + + + +@api_router.get("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent) +async def get_list_events( + listevents_id: int, + connection: AsyncConnection = Depends(get_connection_dep), + current_user=Depends(get_current_user) +): + listevents_validation = await get_listevents_by_id(connection, listevents_id) + + 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(connection, current_user,listevents_validation.creator_id) + + + if listevents_id is None: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found") + + return listevents_validation + + +@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ListEvent) +async def create_list_events( + listevents: 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) + + if listevents_validation is None: + await create_listevents(connection, listevents, user_validation.id) + user_new = await get_listevents_by_name(connection, listevents.name) + return user_new + + else: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, detail="An List events with this information already exists." + ) + +@api_router.put("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent) +async def update_listevents( + listevents_id: int, + listevents_update: ListEventUpdate, + connection: AsyncConnection = Depends(get_connection_dep), + current_user=Depends(get_current_user), +): + + listevents_validation = await get_listevents_by_id(connection, listevents_id) + + 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(connection, current_user,listevents_validation.creator_id) + + update_values = update_listevents_data_changes(listevents_update, listevents_validation) + + if update_values is None: + return listevents_validation + + listevents_update_data = ListEvent.model_validate({**listevents_validation.model_dump(), **update_values}) + + await update_listevents_by_id(connection, update_values, listevents_validation) + + listevents = await get_listevents_by_id(connection, listevents_id) + + return listevents + + +@api_router.delete("/{listevents_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent) +async def delete_list_events( + listevents_id: int, + connection: AsyncConnection = Depends(get_connection_dep), + current_user=Depends(get_current_user), +): + + listevents_validation = await get_listevents_by_id(connection, listevents_id) + + 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(connection, current_user,listevents_validation.creator_id) + + listevents_update = ListEventUpdate(status=EventStatus.DELETED.value) + + + update_values = update_listevents_data_changes(listevents_update, listevents_validation) + + if update_values is None: + return listevents_validation + + await update_listevents_by_id(connection, update_values, listevents_validation) + + listevents = await get_listevents_by_id(connection, listevents_id) + + return listevents diff --git a/api/api/schemas/endpoints/list_events.py b/api/api/schemas/endpoints/list_events.py new file mode 100644 index 0000000..762c00a --- /dev/null +++ b/api/api/schemas/endpoints/list_events.py @@ -0,0 +1,37 @@ +from pydantic import Field, TypeAdapter +from typing import Optional,Dict, Any, List +from datetime import datetime + + +from api.schemas.base import Base +from api.db.tables.events import EventState,EventStatus + + +class ListEventUpdate(Base): + id: Optional[int] = None + name: Optional[str] = Field(None, max_length=40) + title: Optional[str] = Field(None, max_length=64) + creator_id: Optional[int] = None + created_at: Optional[datetime]= None + schema: Optional[Dict[str, Any]]= None + state: Optional[EventState]= None + status: Optional[EventStatus]= None + +class AllListEvent(Base): + id: int + name: str + title: str + creator_id: int + created_at: datetime + schema: Dict[str, Any] = Field(default={}) + state: EventState + status: EventStatus + + +class AllListEventResponse(Base): + list_event: List[AllListEvent] + amount_count: int + amount_pages: int + + +all_list_event_adapter = TypeAdapter(List[AllListEvent]) diff --git a/api/api/schemas/events/list_events.py b/api/api/schemas/events/list_events.py index 2df94c7..d4d70d2 100644 --- a/api/api/schemas/events/list_events.py +++ b/api/api/schemas/events/list_events.py @@ -1,20 +1,9 @@ from pydantic import Field from typing import Dict, Any from datetime import datetime -from enum import Enum from api.schemas.base import Base - - -class State(Enum): - AUTO = "Auto" - DESCRIPTED = "Descripted" - - -class Status(Enum): - ACTIVE = "Active" - DISABLED = "Disabled" - DELETED = "Deleted" +from api.db.tables.events import EventState,EventStatus class ListEvent(Base): @@ -24,5 +13,5 @@ class ListEvent(Base): creator_id: int created_at: datetime schema: Dict[str, Any] - state: State - status: Status + state: EventState + status: EventStatus diff --git a/api/api/services/update_data_validation.py b/api/api/services/update_data_validation.py index 349a0a9..5c0438e 100644 --- a/api/api/services/update_data_validation.py +++ b/api/api/services/update_data_validation.py @@ -4,6 +4,8 @@ from api.schemas.endpoints.account import UserUpdate from api.db.tables.account import KeyType, KeyStatus from api.schemas.endpoints.account_keyring import AccountKeyringUpdate from api.db.tables.account import AccountRole, AccountStatus +from api.schemas.endpoints.list_events import ListEventUpdate +from api.db.tables.events import EventState, EventStatus def update_user_data_changes(update_data: UserUpdate, user) -> Optional[dict]: @@ -72,3 +74,36 @@ def update_key_data_changes(update_data: AccountKeyringUpdate, key) -> Optional[ changes[field] = new_value return changes if changes else None + +def update_listevents_data_changes(update_data: ListEventUpdate, listevents) -> Optional[dict]: + """ + Сравнивает данные для обновления с текущими значениями listevents. + Возвращает: + - None, если нет изменений + - Словарь {поле: новое_значение} для измененных полей + """ + update_values = {} + changes = {} + + for field, value in update_data.model_dump(exclude_unset=True).items(): + if value is None: + continue + + if isinstance(value, (EventState, EventStatus)): + update_values[field] = value.value + else: + update_values[field] = value + + for field, new_value in update_values.items(): + if not hasattr(listevents, field): + continue + + current_value = getattr(listevents, field) + + if isinstance(current_value, Enum): + current_value = current_value.value + + if current_value != new_value: + changes[field] = new_value + + return changes if changes else None diff --git a/api/api/services/user_role_validation.py b/api/api/services/user_role_validation.py index 93670ef..dce18f5 100644 --- a/api/api/services/user_role_validation.py +++ b/api/api/services/user_role_validation.py @@ -11,3 +11,17 @@ async def db_user_role_validation(connection, current_user): if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions") return authorize_user + +async def db_user_role_validation_for_listevents_by_listevent_id(connection, current_user,current_lisevents_creator_id): + authorize_user = await get_user_by_login(connection, current_user) + if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}: + if authorize_user.id != current_lisevents_creator_id: + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions") + return authorize_user + +async def db_user_role_validation_for_listevents(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 + else: + return authorize_user,True -- 2.39.5 From 0bff556b10005dddbec629fac22877893556959e Mon Sep 17 00:00:00 2001 From: TheNoxium Date: Tue, 1 Jul 2025 22:31:16 +0500 Subject: [PATCH 2/6] fix: page schems, name --- api/api/db/logic/listevents.py | 10 ++++++---- api/api/endpoints/listevents.py | 4 ++-- api/api/schemas/endpoints/list_events.py | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/api/api/db/logic/listevents.py b/api/api/db/logic/listevents.py index 7f1d0e1..b801a56 100644 --- a/api/api/db/logic/listevents.py +++ b/api/api/db/logic/listevents.py @@ -56,10 +56,11 @@ async def get_listevents_page_by_creator_id(connection: AsyncConnection, creator # Здесь предполагается, что all_list_event_adapter.validate_python корректно обрабатывает данные validated_list_event = all_list_event_adapter.validate_python(events_data) - return AllListEventResponse(list_event=validated_list_event, amount_count=total_count, amount_pages=total_pages) + return AllListEventResponse(list_event=validated_list_event, amount_count=total_count, amount_pages=total_pages, current_page=page, + limit = limit) -async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optional[ListEvent]: +async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optional[AllListEventResponse]: """ Получает список ползовелей заданных значениями page, limit. """ @@ -94,7 +95,8 @@ async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optio # Здесь предполагается, что all_list_event_adapter.validate_python корректно обрабатывает данные validated_list_event = all_list_event_adapter.validate_python(events_data) - return AllListEventResponse(list_event=validated_list_event, amount_count=total_count, amount_pages=total_pages) + return AllListEventResponse(list_event=validated_list_event, amount_count=total_count, amount_pages=total_pages,current_page=page, + limit = limit) async def get_listevents_by_name(connection: AsyncConnection, name: str) -> Optional[ListEvent]: """ @@ -142,7 +144,7 @@ async def get_listevents_by_id(connection: AsyncConnection, id: int) -> Optional return ListEvent.model_validate(listevents_data) -async def update_listevents_by_id(connection: AsyncConnection, update_values, listevents) -> Optional[ListEvent]: +async def update_listevents_by_id(connection: AsyncConnection, update_values, listevents): """ Вносит изменеия в нужное поле таблицы account_table. """ diff --git a/api/api/endpoints/listevents.py b/api/api/endpoints/listevents.py index a9d6fce..c54b6c8 100644 --- a/api/api/endpoints/listevents.py +++ b/api/api/endpoints/listevents.py @@ -108,8 +108,8 @@ async def create_list_events( if listevents_validation is None: await create_listevents(connection, listevents, user_validation.id) - user_new = await get_listevents_by_name(connection, listevents.name) - return user_new + listevents_new = await get_listevents_by_name(connection, listevents.name) + return listevents_new else: raise HTTPException( diff --git a/api/api/schemas/endpoints/list_events.py b/api/api/schemas/endpoints/list_events.py index 762c00a..141026e 100644 --- a/api/api/schemas/endpoints/list_events.py +++ b/api/api/schemas/endpoints/list_events.py @@ -32,6 +32,7 @@ class AllListEventResponse(Base): list_event: List[AllListEvent] amount_count: int amount_pages: int - + current_page: int + limit: int all_list_event_adapter = TypeAdapter(List[AllListEvent]) -- 2.39.5 From 3d5d717962ce3f4fd2d3813cc7cb742eeb555c7e Mon Sep 17 00:00:00 2001 From: TheNoxium Date: Wed, 2 Jul 2025 11:37:10 +0500 Subject: [PATCH 3/6] fix: removed id for update data --- api/api/schemas/endpoints/account.py | 2 +- api/api/schemas/endpoints/list_events.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api/schemas/endpoints/account.py b/api/api/schemas/endpoints/account.py index 37ceeea..829db8b 100644 --- a/api/api/schemas/endpoints/account.py +++ b/api/api/schemas/endpoints/account.py @@ -8,7 +8,7 @@ from api.schemas.base import Base class UserUpdate(Base): - id: Optional[int] = None + # id: Optional[int] = None name: Optional[str] = Field(None, max_length=100) login: Optional[str] = Field(None, max_length=100) email: Optional[EmailStr] = None diff --git a/api/api/schemas/endpoints/list_events.py b/api/api/schemas/endpoints/list_events.py index 141026e..2e1c30f 100644 --- a/api/api/schemas/endpoints/list_events.py +++ b/api/api/schemas/endpoints/list_events.py @@ -8,7 +8,7 @@ from api.db.tables.events import EventState,EventStatus class ListEventUpdate(Base): - id: Optional[int] = None + # id: Optional[int] = None name: Optional[str] = Field(None, max_length=40) title: Optional[str] = Field(None, max_length=64) creator_id: Optional[int] = None -- 2.39.5 From a90a802659486acb5d88664d53c5807f2cc97ff3 Mon Sep 17 00:00:00 2001 From: TheNoxium Date: Wed, 2 Jul 2025 11:43:24 +0500 Subject: [PATCH 4/6] fix: update data --- api/api/schemas/endpoints/account.py | 4 ++-- api/api/schemas/endpoints/account_keyring.py | 6 +++--- api/api/schemas/endpoints/list_events.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/api/schemas/endpoints/account.py b/api/api/schemas/endpoints/account.py index 829db8b..f1b9b10 100644 --- a/api/api/schemas/endpoints/account.py +++ b/api/api/schemas/endpoints/account.py @@ -15,8 +15,8 @@ class UserUpdate(Base): bind_tenant_id: Optional[str] = Field(None, max_length=40) role: Optional[AccountRole] = None meta: Optional[dict] = None - creator_id: Optional[int] = None - created_at: Optional[datetime] = None + # creator_id: Optional[int] = None + # created_at: Optional[datetime] = None status: Optional[AccountStatus] = None diff --git a/api/api/schemas/endpoints/account_keyring.py b/api/api/schemas/endpoints/account_keyring.py index b5f5193..1d3ed81 100644 --- a/api/api/schemas/endpoints/account_keyring.py +++ b/api/api/schemas/endpoints/account_keyring.py @@ -10,8 +10,8 @@ from api.schemas.base import Base class AccountKeyringUpdate(Base): owner_id: Optional[int] = None key_type: Optional[KeyType] = None - key_id: Optional[str] = Field(None, max_length=40) + # key_id: Optional[str] = Field(None, max_length=40) key_value: Optional[str] = Field(None, max_length=255) - created_at: Optional[datetime] = None - expiry: Optional[datetime] = None + # created_at: Optional[datetime] = None + # expiry: Optional[datetime] = None status: Optional[KeyStatus] = None diff --git a/api/api/schemas/endpoints/list_events.py b/api/api/schemas/endpoints/list_events.py index 2e1c30f..0b85199 100644 --- a/api/api/schemas/endpoints/list_events.py +++ b/api/api/schemas/endpoints/list_events.py @@ -11,8 +11,8 @@ class ListEventUpdate(Base): # id: Optional[int] = None name: Optional[str] = Field(None, max_length=40) title: Optional[str] = Field(None, max_length=64) - creator_id: Optional[int] = None - created_at: Optional[datetime]= None + # creator_id: Optional[int] = None + # created_at: Optional[datetime]= None schema: Optional[Dict[str, Any]]= None state: Optional[EventState]= None status: Optional[EventStatus]= None -- 2.39.5 From f65f4caf5c77240b7da6c2a3b14119247980b2ca Mon Sep 17 00:00:00 2001 From: TheNoxium Date: Wed, 2 Jul 2025 11:48:23 +0500 Subject: [PATCH 5/6] fix: description --- api/api/db/logic/listevents.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/api/db/logic/listevents.py b/api/api/db/logic/listevents.py index b801a56..bdd03b2 100644 --- a/api/api/db/logic/listevents.py +++ b/api/api/db/logic/listevents.py @@ -22,7 +22,6 @@ async def get_listevents_page_by_creator_id(connection: AsyncConnection, creator """ first_event = page * limit - limit - print(creator_id) query = ( select( list_events_table.c.id, @@ -62,7 +61,7 @@ async def get_listevents_page_by_creator_id(connection: AsyncConnection, creator async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optional[AllListEventResponse]: """ - Получает список ползовелей заданных значениями page, limit. + Получает список событий заданного создателя по значениям page и limit. """ first_event = page * limit - (limit) @@ -100,7 +99,7 @@ async def get_listevents_page(connection: AsyncConnection, page, limit) -> Optio async def get_listevents_by_name(connection: AsyncConnection, name: str) -> Optional[ListEvent]: """ - Получает юзера по login. + Получает list events по name. """ query = select(list_events_table).where(list_events_table.c.name == name) @@ -146,7 +145,7 @@ async def get_listevents_by_id(connection: AsyncConnection, id: int) -> Optional async def update_listevents_by_id(connection: AsyncConnection, update_values, listevents): """ - Вносит изменеия в нужное поле таблицы account_table. + Вносит изменеия в нужное поле таблицы list_events_table. """ await connection.execute(list_events_table.update().where(list_events_table.c.id == listevents.id).values(**update_values)) -- 2.39.5 From 2493cd0d9fcf02b6a066043d5ac2a44bd6a60135 Mon Sep 17 00:00:00 2001 From: Vladislav Syrochkin Date: Wed, 2 Jul 2025 14:14:03 +0500 Subject: [PATCH 6/6] fix(api): fix shadows an attribute in parent in ListEvents for field schema --- api/api/db/logic/listevents.py | 4 ++-- api/api/schemas/endpoints/list_events.py | 4 ++-- api/api/schemas/events/list_events.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/api/db/logic/listevents.py b/api/api/db/logic/listevents.py index bdd03b2..3d9c245 100644 --- a/api/api/db/logic/listevents.py +++ b/api/api/db/logic/listevents.py @@ -29,7 +29,7 @@ async def get_listevents_page_by_creator_id(connection: AsyncConnection, creator list_events_table.c.title, list_events_table.c.creator_id, list_events_table.c.created_at, - list_events_table.c.schema, + list_events_table.c.schema_, list_events_table.c.state, list_events_table.c.status, ) @@ -162,7 +162,7 @@ async def create_listevents(connection: AsyncConnection, listevents: ListEvent, title=listevents.title, # добавлено поле title creator_id=creator_id, created_at=datetime.now(timezone.utc), - schema=listevents.schema, # добавлено поле schema + schema=listevents.schema_, # добавлено поле schema state=listevents.state.value, # добавлено поле state status=listevents.status.value # добавлено поле status ) diff --git a/api/api/schemas/endpoints/list_events.py b/api/api/schemas/endpoints/list_events.py index 0b85199..e0fd96a 100644 --- a/api/api/schemas/endpoints/list_events.py +++ b/api/api/schemas/endpoints/list_events.py @@ -13,7 +13,7 @@ class ListEventUpdate(Base): title: Optional[str] = Field(None, max_length=64) # creator_id: Optional[int] = None # created_at: Optional[datetime]= None - schema: Optional[Dict[str, Any]]= None + schema_: Optional[Dict[str, Any]]= Field(None, alias="schema") state: Optional[EventState]= None status: Optional[EventStatus]= None @@ -23,7 +23,7 @@ class AllListEvent(Base): title: str creator_id: int created_at: datetime - schema: Dict[str, Any] = Field(default={}) + schema_: Dict[str, Any] = Field(default={}, alias="schema") state: EventState status: EventStatus diff --git a/api/api/schemas/events/list_events.py b/api/api/schemas/events/list_events.py index d4d70d2..d5d79e4 100644 --- a/api/api/schemas/events/list_events.py +++ b/api/api/schemas/events/list_events.py @@ -12,6 +12,6 @@ class ListEvent(Base): title: str = Field(..., max_length=64) creator_id: int created_at: datetime - schema: Dict[str, Any] + schema_: Dict[str, Any] = Field(..., alias="schema") state: EventState status: EventStatus -- 2.39.5