2 Commits

Author SHA1 Message Date
15bc323ee4 test: add client services 2025-06-10 17:06:19 +05:00
958f00069f test 2025-06-10 17:05:35 +05:00
83 changed files with 16504 additions and 4201 deletions

View File

@@ -12,35 +12,36 @@ services:
start-api: start-api:
cd api && \ cd api && \
poetry run python -m ${API_APPLICATION_NAME} source .venv/bin/activate && \
python -m ${API_APPLICATION_NAME}
start-client: start-client:
cd client && \ cd client && \
npm run dev npm start
migrate: migrate:
cd api && \ cd api && \
source .venv/bin/activate && \
cd $(API_APPLICATION_NAME)/db && \ cd $(API_APPLICATION_NAME)/db && \
PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True poetry run alembic upgrade $(args) PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True alembic upgrade $(args)
downgrade: downgrade:
cd api && \ cd api && \
source .venv/bin/activate && \
cd $(API_APPLICATION_NAME)/db && \ cd $(API_APPLICATION_NAME)/db && \
PYTHONPATH='../..' poetry run alembic downgrade -1 PYTHONPATH='../..' alembic downgrade -1
revision: revision:
cd api && \ cd api && \
source .venv/bin/activate && \
cd $(API_APPLICATION_NAME)/db && \ cd $(API_APPLICATION_NAME)/db && \
PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True poetry run alembic revision --autogenerate PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True alembic revision --autogenerate
venv-api: venv-api:
cd api && \ cd api && \
poetry env activate \
poetry install poetry install
venv-client:
cd client && \
npm install
install: install:
make migrate head && \ make migrate head && \
cd api && \ cd api && \
@@ -57,8 +58,3 @@ format-api:
check-api: check-api:
cd api && \ cd api && \
poetry run ruff format . --check poetry run ruff format . --check
regenerate-openapi-local:
cd client \
rm src/types/openapi-types.ts \
npx openapi-typescript http://localhost:8000/openapi -o src/types/openapi-types.ts

View File

@@ -1,49 +1 @@
# Vorkout/connect Vorkout/connect
### Makefile cheat sheet
```Makefile
Dev:
venv-api create python virtual environment
venv-client install node modules
install Migrate database and initialize project
Application Api:
start-api Run api server
Application Client:
start-client Run client server
Prod:
...
Code:
check-api Check api code with ruff
format-api Reformat api code with ruff
Help:
...
Testing:
...
```
### Запуск в режиме разработки
Для запуска в режиме разработки нужно
1. Устрановить среду для clint и api
2. Запустить в докере или локально необходимые сервисы (базуб брокер и redis) `make services`
3. Для миграции и создания первого пользователя необходимо запустить `make install`
3. Запустить api `make start-api`
4. Запустить client `make start-client`
### Миграции алембик
1. Стоит внимательно учитывать, адрес какой базы стоит в настройках alembic - локальной или продакшн. Посмотреть это можно в файле [env.py](connect/api/api/db/alembic/env.py). Конфиг для локальной базы
```python
config.set_main_option(
"sqlalchemy.url",
f"mysql+pymysql://root:hackme@localhost:3306/connect_test",
)
```

View File

@@ -1,15 +1,15 @@
import logging
import sys import sys
import logging
import loguru import loguru
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from uvicorn import run from uvicorn import run
from api.config import DefaultSettings, get_settings from api.config import get_settings, DefaultSettings
from api.endpoints import list_of_routes from api.endpoints import list_of_routes
from api.services.middleware import MiddlewareAccessTokenValidadtion
from api.utils.common import get_hostname from api.utils.common import get_hostname
from api.services.middleware import MiddlewareAccessTokenValidadtion
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@@ -52,6 +52,7 @@ prod_origins = [""]
origins = dev_origins if get_settings().ENV == "local" else prod_origins origins = dev_origins if get_settings().ENV == "local" else prod_origins
if __name__ == "__main__": if __name__ == "__main__":
settings_for_application = get_settings() settings_for_application = get_settings()
if settings_for_application.ENV == "prod": if settings_for_application.ENV == "prod":

View File

@@ -18,7 +18,8 @@ class DbCredentialsSchema(BaseModel):
class DefaultSettings(BaseSettings): class DefaultSettings(BaseSettings):
ENV: str = environ.get("ENV", "local") ENV: str = environ.get("ENV", "local")
PATH_PREFIX: str = environ.get("PATH_PREFIX", "/api/v1") PATH_PREFIX: str = environ.get("PATH_PREFIX", "/api/v1")
APP_HOST: str = environ.get("APP_HOST", "http://127.0.0.1") # APP_HOST: str = environ.get("APP_HOST", "http://127.0.0.1")
APP_HOST: str = environ.get("APP_HOST", "http://localhost")
APP_PORT: int = int(environ.get("APP_PORT", 8000)) APP_PORT: int = int(environ.get("APP_PORT", 8000))
APP_ID: uuid.UUID = environ.get("APP_ID", uuid.uuid4()) APP_ID: uuid.UUID = environ.get("APP_ID", uuid.uuid4())
LOGS_STORAGE_PATH: str = environ.get("LOGS_STORAGE_PATH", "storage/logs") LOGS_STORAGE_PATH: str = environ.get("LOGS_STORAGE_PATH", "storage/logs")

View File

@@ -0,0 +1,7 @@
from sqlalchemy import MetaData
metadata = MetaData()
__all__ = [
"metadata",
]

View File

@@ -7,7 +7,7 @@ from sqlalchemy import pool
from alembic import context from alembic import context
from orm import metadata, tables from api.db import metadata, tables
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides
# access to the values within the .ini file in use. # access to the values within the .ini file in use.

View File

@@ -1,38 +0,0 @@
"""empty message
Revision ID: 93106fbe7d83
Revises: f1b06efacec0
Create Date: 2025-06-26 16:36:02.270706
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision: str = '93106fbe7d83'
down_revision: Union[str, None] = 'f1b06efacec0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('account_keyring', 'key_value',
existing_type=mysql.VARCHAR(length=255),
type_=sa.String(length=512),
existing_nullable=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('account_keyring', 'key_value',
existing_type=sa.String(length=512),
type_=mysql.VARCHAR(length=255),
existing_nullable=False)
# ### end Alembic commands ###

View File

@@ -1,136 +1,77 @@
import math
from datetime import datetime, timezone
from enum import Enum
from typing import Optional from typing import Optional
import math
from sqlalchemy import insert, select, func, or_, and_, asc, desc from datetime import datetime, timezone
from sqlalchemy import insert, select, func
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from enum import Enum
from api.db.tables.account import account_table
from orm.tables.account import account_table
from api.schemas.account.account import User from api.schemas.account.account import User
from api.schemas.endpoints.account import all_user_adapter, AllUser, AllUserResponse, UserCreate, UserFilterDTO from api.schemas.endpoints.account import AllUserResponse, all_user_adapter
async def get_user_account_page_DTO( async def get_user_accaunt_page(connection: AsyncConnection, page, limit) -> Optional[User]:
connection: AsyncConnection, filter_dto: UserFilterDTO
) -> Optional[AllUserResponse]:
""" """
Получает список пользователей с пагинацией, фильтрацией и сортировкой через DTO объект. Получает список ползовелей заданных значениями page, limit.
Поддерживает:
- пагинацию
- поиск
- фильтрацию по полям
- сортировку
""" """
page = filter_dto.pagination.get("page", 1) first_user = page * limit - (limit)
limit = filter_dto.pagination.get("limit", 10)
offset = (page - 1) * limit
query = select( query = (
select(
account_table.c.id, account_table.c.id,
account_table.c.name, account_table.c.name,
account_table.c.login, account_table.c.login,
account_table.c.email, account_table.c.email,
account_table.c.bind_tenant_id, account_table.c.bind_tenant_id,
account_table.c.role, account_table.c.role,
account_table.c.meta,
account_table.c.creator_id,
account_table.c.created_at, account_table.c.created_at,
account_table.c.status, account_table.c.status,
) )
.order_by(account_table.c.id)
# Поиск .offset(first_user)
if filter_dto.search: .limit(limit)
search_term = f"%{filter_dto.search}%"
query = query.where(
or_(
account_table.c.name.ilike(search_term),
account_table.c.login.ilike(search_term),
account_table.c.email.ilike(search_term),
) )
)
# Фильтрацию
filter_conditions = []
if filter_dto.filters:
for field, values in filter_dto.filters.items():
column = getattr(account_table.c, field, None)
if column is not None and values:
if len(values) == 1:
filter_conditions.append(column == values[0])
else:
filter_conditions.append(column.in_(values))
if filter_conditions:
query = query.where(and_(*filter_conditions))
# Сортировка
if filter_dto.order:
order_field = filter_dto.order.get("field", "id")
order_direction = filter_dto.order.get("direction", "asc")
column = getattr(account_table.c, order_field, None)
if column is not None:
if order_direction.lower() == "desc":
query = query.order_by(desc(column))
else:
query = query.order_by(asc(column))
else:
query = query.order_by(account_table.c.id)
query = query.offset(offset).limit(limit)
count_query = select(func.count()).select_from(account_table) count_query = select(func.count()).select_from(account_table)
if filter_dto.search:
search_term = f"%{filter_dto.search}%"
count_query = count_query.where(
or_(
account_table.c.name.ilike(search_term),
account_table.c.login.ilike(search_term),
account_table.c.email.ilike(search_term),
)
)
if filter_conditions:
count_query = count_query.where(and_(*filter_conditions))
result = await connection.execute(query) result = await connection.execute(query)
count_result = await connection.execute(count_query) count_result = await connection.execute(count_query)
users_data = result.mappings().all() users_data = result.mappings().all()
total_count = count_result.scalar() total_count = count_result.scalar()
if not total_count:
return None
total_pages = math.ceil(total_count / limit) total_pages = math.ceil(total_count / limit)
validated_users = all_user_adapter.validate_python(users_data) validated_users = all_user_adapter.validate_python(users_data)
return AllUserResponse( return AllUserResponse(users=validated_users, amount_count=total_count, amount_pages=total_pages)
users=validated_users,
amount_count=total_count,
amount_pages=total_pages,
current_page=page,
limit=limit,
)
async def get_user_by_id(connection: AsyncConnection, user_id: int) -> Optional[AllUser]: async def get_user_by_id(connection: AsyncConnection, id: int) -> Optional[User]:
""" """
Получает юзера по id. Получает юзера по id.
""" """
query = select(account_table).where(account_table.c.id == user_id) query = select(account_table).where(account_table.c.id == id)
user_db_cursor = await connection.execute(query) user_db_cursor = await connection.execute(query)
user = user_db_cursor.mappings().one_or_none() user_db = user_db_cursor.one_or_none()
if not user: if not user_db:
return None return None
return User.model_validate(user) user_data = {
column.name: (
getattr(user_db, column.name).name
if isinstance(getattr(user_db, column.name), Enum)
else getattr(user_db, column.name)
)
for column in account_table.columns
}
return User.model_validate(user_data)
async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional[User]: async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional[User]:
@@ -140,10 +81,20 @@ async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional
query = select(account_table).where(account_table.c.login == login) query = select(account_table).where(account_table.c.login == login)
user_db_cursor = await connection.execute(query) user_db_cursor = await connection.execute(query)
user_data = user_db_cursor.mappings().one_or_none() user_db = user_db_cursor.one_or_none()
if not user_data:
if not user_db:
return None return None
user_data = {
column.name: (
getattr(user_db, column.name).name
if isinstance(getattr(user_db, column.name), Enum)
else getattr(user_db, column.name)
)
for column in account_table.columns
}
return User.model_validate(user_data) return User.model_validate(user_data)
@@ -156,7 +107,7 @@ async def update_user_by_id(connection: AsyncConnection, update_values, user) ->
await connection.commit() await connection.commit()
async def create_user(connection: AsyncConnection, user: UserCreate, creator_id: int) -> Optional[AllUser]: async def create_user(connection: AsyncConnection, user: User, creator_id: int) -> Optional[User]:
""" """
Создает нове поле в таблице account_table. Создает нове поле в таблице account_table.
""" """
@@ -166,15 +117,14 @@ async def create_user(connection: AsyncConnection, user: UserCreate, creator_id:
email=user.email, email=user.email,
bind_tenant_id=user.bind_tenant_id, bind_tenant_id=user.bind_tenant_id,
role=user.role.value, role=user.role.value,
meta=user.meta or {}, meta=user.meta,
creator_id=creator_id, creator_id=creator_id,
created_at=datetime.now(timezone.utc), created_at=datetime.now(timezone.utc),
status=user.status.value, status=user.status.value,
) )
res = await connection.execute(query) await connection.execute(query)
await connection.commit() await connection.commit()
new_user = await get_user_by_id(connection, res.lastrowid)
return new_user return user

View File

@@ -4,18 +4,17 @@ from sqlalchemy import select, update
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from enum import Enum from enum import Enum
from orm.tables.account import account_table, account_keyring_table, KeyType, KeyStatus from api.db.tables.account import account_table, account_keyring_table, KeyType, KeyStatus
from api.schemas.account.account import User from api.schemas.account.account import User
from api.schemas.account.account_keyring import AccountKeyring from api.schemas.account.account_keyring import AccountKeyring
from api.schemas.endpoints.account import AllUser
from api.utils.key_id_gen import KeyIdGenerator from api.utils.key_id_gen import KeyIdGenerator
from datetime import datetime, timezone from datetime import datetime, timezone
async def get_user(connection: AsyncConnection, login: str) -> tuple[Optional[AllUser], Optional[AccountKeyring]]: async def get_user(connection: AsyncConnection, login: str) -> Optional[User]:
query = ( query = (
select(account_table, account_keyring_table) select(account_table, account_keyring_table)
.join(account_keyring_table, account_table.c.id == account_keyring_table.c.owner_id) .join(account_keyring_table, account_table.c.id == account_keyring_table.c.owner_id)
@@ -46,7 +45,7 @@ async def get_user(connection: AsyncConnection, login: str) -> tuple[Optional[Al
for column in account_keyring_table.columns for column in account_keyring_table.columns
} }
user = AllUser.model_validate(user_data) user = User.model_validate(user_data)
password = AccountKeyring.model_validate(password_data) password = AccountKeyring.model_validate(password_data)
return user, password return user, password

View File

@@ -1,14 +1,13 @@
from datetime import datetime, timedelta, timezone
from enum import Enum
from typing import Optional from typing import Optional
from datetime import datetime, timezone
from enum import Enum
from sqlalchemy import insert, select, update from sqlalchemy import insert, select
from sqlalchemy.dialects.mysql import insert as mysql_insert
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from orm.tables.account import account_keyring_table, KeyStatus, KeyType from api.db.tables.account import account_keyring_table
from api.schemas.account.account_keyring import AccountKeyring from api.schemas.account.account_keyring import AccountKeyring
from api.utils.hasher import hasher
async def get_key_by_id(connection: AsyncConnection, key_id: str) -> Optional[AccountKeyring]: async def get_key_by_id(connection: AsyncConnection, key_id: str) -> Optional[AccountKeyring]:
@@ -18,11 +17,20 @@ async def get_key_by_id(connection: AsyncConnection, key_id: str) -> Optional[Ac
query = select(account_keyring_table).where(account_keyring_table.c.key_id == key_id) query = select(account_keyring_table).where(account_keyring_table.c.key_id == key_id)
user_db_cursor = await connection.execute(query) user_db_cursor = await connection.execute(query)
user_db = user_db_cursor.one_or_none()
user_data = user_db_cursor.mappings().one_or_none() if not user_db:
if not user_data:
return None return None
user_data = {
column.name: (
getattr(user_db, column.name).name
if isinstance(getattr(user_db, column.name), Enum)
else getattr(user_db, column.name)
)
for column in account_keyring_table.columns
}
return AccountKeyring.model_validate(user_data) return AccountKeyring.model_validate(user_data)
@@ -59,37 +67,3 @@ async def create_key(connection: AsyncConnection, key: AccountKeyring, key_id: i
await connection.commit() await connection.commit()
return key return key
async def create_password_key(connection: AsyncConnection, password: str | None, owner_id: int):
if password is None:
password = hasher.generate_password()
hashed_password = hasher.hash_data(password)
stmt = mysql_insert(account_keyring_table).values(
owner_id=owner_id,
key_type=KeyType.PASSWORD.value,
key_id="PASSWORD",
key_value=hashed_password,
created_at=datetime.now(timezone.utc),
expiry=datetime.now(timezone.utc) + timedelta(days=365),
status=KeyStatus.ACTIVE,
)
stmt.on_duplicate_key_update(key_value=hashed_password)
await connection.execute(stmt)
await connection.commit()
async def update_password_key(connection: AsyncConnection, owner_id: int, password: str):
stmt = select(account_keyring_table).where(account_keyring_table.c.owner_id == owner_id)
result = await connection.execute(stmt)
keyring = result.one_or_none()
if not keyring:
await create_password_key(connection, password, owner_id)
else:
stmt = (
update(account_keyring_table)
.values(key_value=hasher.hash_data(password), expiry=datetime.now(timezone.utc) + timedelta(days=365))
.where(account_keyring_table.c.owner_id == owner_id)
)
await connection.execute(stmt)
await connection.commit()

View File

@@ -1,279 +0,0 @@
from typing import Optional
import math
from datetime import datetime, timezone
from sqlalchemy import insert, select, func, or_, and_, asc, desc
from sqlalchemy.ext.asyncio import AsyncConnection
from orm.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, ListEventFilterDTO
async def get_list_events_page_DTO(
connection: AsyncConnection, filter_dto: ListEventFilterDTO
) -> Optional[AllListEventResponse]:
"""
Получает список событий с фильтрацией через DTO объект.
Поддерживает:
- пагинацию
- полнотекстовый поиск (пропускает name при русских буквах)
- фильтрацию по полям
- сортировку
"""
page = filter_dto.pagination.get("page", 1)
limit = filter_dto.pagination.get("limit", 10)
offset = (page - 1) * 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.label("schema_"),
list_events_table.c.state,
list_events_table.c.status,
)
if filter_dto.search:
search_term = f"%{filter_dto.search}%"
has_russian = any("\u0400" <= char <= "\u04ff" for char in filter_dto.search)
if has_russian:
query = query.where(list_events_table.c.title.ilike(search_term))
else:
query = query.where(
or_(list_events_table.c.title.ilike(search_term), list_events_table.c.name.ilike(search_term))
)
filter_conditions = []
if filter_dto.filters:
for field, values in filter_dto.filters.items():
column = getattr(list_events_table.c, field, None)
if column is not None and values:
if len(values) == 1:
filter_conditions.append(column == values[0])
else:
filter_conditions.append(column.in_(values))
if filter_conditions:
query = query.where(and_(*filter_conditions))
if filter_dto.order:
order_field = filter_dto.order.get("field", "id")
order_direction = filter_dto.order.get("direction", "asc")
if order_field.startswith("schema."):
json_field = order_field[7:]
column = list_events_table.c.schema[json_field].astext
else:
column = getattr(list_events_table.c, order_field, None)
if column is not None:
if order_direction.lower() == "desc":
query = query.order_by(desc(column))
else:
query = query.order_by(asc(column))
else:
query = query.order_by(list_events_table.c.id)
query = query.offset(offset).limit(limit)
count_query = select(func.count()).select_from(list_events_table)
if filter_dto.search:
search_term = f"%{filter_dto.search}%"
has_russian = any("\u0400" <= char <= "\u04ff" for char in filter_dto.search)
if has_russian:
count_query = count_query.where(list_events_table.c.title.ilike(search_term))
else:
count_query = count_query.where(
or_(list_events_table.c.title.ilike(search_term), list_events_table.c.name.ilike(search_term))
)
if filter_conditions:
count_query = count_query.where(and_(*filter_conditions))
result = await connection.execute(query)
count_result = await connection.execute(count_query)
events_data = result.mappings().all()
total_count = count_result.scalar()
if not total_count:
return None
total_pages = math.ceil(total_count / limit)
validated_events = all_list_event_adapter.validate_python(events_data)
return AllListEventResponse(
list_event=validated_events,
amount_count=total_count,
amount_pages=total_pages,
current_page=page,
limit=limit,
)
async def get_list_events_page_by_creator_id(
connection: AsyncConnection, creator_id: int, page: int, limit: int
) -> Optional[AllListEventResponse]:
"""
Получает список событий заданного создателя по значениям page и limit и creator_id.
"""
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,
)
.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,
current_page=page,
limit=limit,
)
async def get_list_events_page(connection: AsyncConnection, page, limit) -> Optional[AllListEventResponse]:
"""
Получает список событий заданного создателя по значениям 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,
current_page=page,
limit=limit,
)
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)
list_events_db_cursor = await connection.execute(query)
list_events_data = list_events_db_cursor.mappings().one_or_none()
if not list_events_data:
return None
return ListEvent.model_validate(list_events_data)
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)
list_events_db_cursor = await connection.execute(query)
list_events_data = list_events_db_cursor.mappings().one_or_none()
if not list_events_data:
return None
return ListEvent.model_validate(list_events_data)
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 == list_events.id).values(**update_values)
)
await connection.commit()
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=list_events.name,
title=list_events.title, # добавлено поле title
creator_id=creator_id,
created_at=datetime.now(timezone.utc),
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 list_events

View File

@@ -1,175 +0,0 @@
from typing import Optional
import math
from datetime import datetime, timezone
from sqlalchemy import insert, select, func, or_, and_, asc, desc
from sqlalchemy.ext.asyncio import AsyncConnection
from orm.tables.process import process_schema_table
from api.schemas.process.process_schema import ProcessSchema
from api.schemas.endpoints.process_schema import (
all_process_schema_adapter,
AllProcessSchemaResponse,
ProcessSchemaFilterDTO,
)
async def get_process_schema_page_DTO(
connection: AsyncConnection, filter_dto: ProcessSchemaFilterDTO
) -> Optional[AllProcessSchemaResponse]:
"""
Получает список схем процессов с комплексной фильтрацией через DTO объект.
Поддерживает:
- пагинацию
- поиск
- фильтрацию по полям
- сортировку
"""
page = filter_dto.pagination.get("page", 1)
limit = filter_dto.pagination.get("limit", 10)
offset = (page - 1) * limit
query = select(
process_schema_table.c.id,
process_schema_table.c.title,
process_schema_table.c.description,
process_schema_table.c.owner_id,
process_schema_table.c.creator_id,
process_schema_table.c.created_at,
process_schema_table.c.settings,
process_schema_table.c.status,
)
if filter_dto.search:
search_term = f"%{filter_dto.search}%"
query = query.where(
or_(process_schema_table.c.title.ilike(search_term), process_schema_table.c.description.ilike(search_term))
)
if filter_dto.filters:
filter_conditions = []
for field, values in filter_dto.filters.items():
column = getattr(process_schema_table.c, field, None)
if column is not None and values:
if len(values) == 1:
filter_conditions.append(column == values[0])
else:
filter_conditions.append(column.in_(values))
if filter_conditions:
query = query.where(and_(*filter_conditions))
if filter_dto.order:
order_field = filter_dto.order.get("field", "id")
order_direction = filter_dto.order.get("direction", "asc")
column = getattr(process_schema_table.c, order_field, None)
if column is not None:
if order_direction.lower() == "desc":
query = query.order_by(desc(column))
else:
query = query.order_by(asc(column))
else:
query = query.order_by(process_schema_table.c.id)
query = query.offset(offset).limit(limit)
count_query = select(func.count()).select_from(process_schema_table)
if filter_dto.search:
search_term = f"%{filter_dto.search}%"
count_query = count_query.where(
or_(process_schema_table.c.title.ilike(search_term), process_schema_table.c.description.ilike(search_term))
)
if filter_dto.filters and filter_conditions:
count_query = count_query.where(and_(*filter_conditions))
result = await connection.execute(query)
count_result = await connection.execute(count_query)
events_data = result.mappings().all()
total_count = count_result.scalar()
if not total_count:
return None
total_pages = math.ceil(total_count / limit)
validated_process_schema = all_process_schema_adapter.validate_python(events_data)
return AllProcessSchemaResponse(
process_schema=validated_process_schema,
amount_count=total_count,
amount_pages=total_pages,
current_page=page,
limit=limit,
)
async def get_process_schema_by_title(connection: AsyncConnection, title: str) -> Optional[ProcessSchema]:
"""
Получает process schema по title.
"""
query = select(process_schema_table).where(process_schema_table.c.title == title)
process_schema_db_cursor = await connection.execute(query)
process_schema_data = process_schema_db_cursor.mappings().one_or_none()
if not process_schema_data:
return None
return ProcessSchema.model_validate(process_schema_data)
async def get_process_schema_by_id(connection: AsyncConnection, id: int) -> Optional[ProcessSchema]:
"""
Получает process_schema по id.
"""
query = select(process_schema_table).where(process_schema_table.c.id == id)
process_schema_db_cursor = await connection.execute(query)
process_schema_data = process_schema_db_cursor.mappings().one_or_none()
if not process_schema_data:
return None
return ProcessSchema.model_validate(process_schema_data)
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 == process_schema.id).values(**update_values)
)
await connection.commit()
async def create_process_schema(
connection: AsyncConnection, process_schema: ProcessSchema, creator_id: int
) -> Optional[ProcessSchema]:
"""
Создает нове поле в таблице process_schema_table.
"""
query = insert(process_schema_table).values(
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=process_schema.settings,
status=process_schema.status.value,
)
await connection.execute(query)
await connection.commit()
return process_schema

18
api/api/db/sql_types.py Normal file
View File

@@ -0,0 +1,18 @@
__all__ = ["BigIntegerPK", "SAEnum", "UnsignedInt"]
from typing import Any
from sqlalchemy import BigInteger, Enum, Integer
from sqlalchemy.dialects import mysql
# class SAEnum(Enum):
# def __init__(self, *enums: object, **kw: Any):
# validate_strings = kw.pop("validate_strings", True)
# super().__init__(*enums, **kw, validate_strings=validate_strings)
# # https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#allowing-autoincrement-behavior-sqlalchemy-types-other-than-integer-integer
# BigIntegerPK = BigInteger().with_variant(Integer, "sqlite")
UnsignedInt = Integer().with_variant(mysql.INTEGER(unsigned=True), "mysql")

View File

@@ -0,0 +1 @@
from . import account, events, process

View File

@@ -0,0 +1,67 @@
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
class AccountRole(enum.StrEnum):
OWNER = "OWNER"
ADMIN = "ADMIN"
EDITOR = "EDITOR"
VIEWER = "VIEWER"
class AccountStatus(enum.StrEnum):
ACTIVE = "ACTIVE"
DISABLED = "DISABLED"
BLOCKED = "BLOCKED"
DELETED = "DELETED"
account_table = Table(
"account",
metadata,
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
Column("name", String(100), nullable=False),
Column("login", String(100), nullable=False),
Column("email", String(100), nullable=True),
Column("bind_tenant_id", String(40), nullable=True),
Column("role", SQLAEnum(AccountRole), nullable=False),
Column("meta", JSON, default={}),
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=True),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("status", SQLAEnum(AccountStatus), nullable=False),
Index("idx_login", "login"),
Index("idx_name", "name"),
)
class KeyType(enum.StrEnum):
PASSWORD = "PASSWORD"
ACCESS_TOKEN = "ACCESS_TOKEN"
REFRESH_TOKEN = "REFRESH_TOKEN"
API_KEY = "API_KEY"
class KeyStatus(enum.StrEnum):
ACTIVE = "ACTIVE"
EXPIRED = "EXPIRED"
DELETED = "DELETED"
account_keyring_table = Table(
"account_keyring",
metadata,
Column("owner_id", UnsignedInt, ForeignKey("account.id"), primary_key=True, nullable=False),
Column("key_type", SQLAEnum(KeyType), primary_key=True, nullable=False),
Column("key_id", String(40), primary_key=True, default=None),
Column("key_value", String(255), nullable=False),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("expiry", DateTime(timezone=True), nullable=True),
Column("status", SQLAEnum(KeyStatus), nullable=False),
)

View File

@@ -0,0 +1,34 @@
import enum
from sqlalchemy import Table, Column, Integer, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
from sqlalchemy.sql import func
from enum import Enum, auto
from api.db.sql_types import UnsignedInt
from api.db import metadata
class EventState(enum.StrEnum):
AUTO = "AUTO"
DESCRIPTED = "DESCRIPTED"
class EventStatus(enum.StrEnum):
ACTIVE = "ACTIVE"
DISABLED = "DISABLED"
DELETED = "DELETED"
list_events_table = Table(
"list_events",
metadata,
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
Column("name", String(40, collation="latin1_bin"), nullable=False, unique=True),
Column("title", String(64), nullable=False),
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("schema", JSON, default={}),
Column("state", SQLAEnum(EventState), nullable=False),
Column("status", SQLAEnum(EventStatus), nullable=False),
)

View File

@@ -0,0 +1,108 @@
import enum
from sqlalchemy import (
Table,
Column,
Integer,
String,
Text,
Enum as SQLAEnum,
JSON,
ForeignKey,
DateTime,
Index,
PrimaryKeyConstraint,
)
from sqlalchemy.sql import func
from enum import Enum, auto
from api.db.sql_types import UnsignedInt
from api.db import metadata
class ProcessStatus(enum.StrEnum):
ACTIVE = "ACTIVE"
STOPPING = "STOPPING"
STOPPED = "STOPPED"
DELETED = "DELETED"
process_schema_table = Table(
"process_schema",
metadata,
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
Column("title", String(100), nullable=False),
Column("description", Text, nullable=False),
Column("owner_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("settings", JSON, default={}),
Column("status", SQLAEnum(ProcessStatus), nullable=False),
Index(
"idx_owner_id",
"owner_id",
),
)
process_version_archive_table = Table(
"process_version_archive",
metadata,
Column("id", UnsignedInt, autoincrement=True, nullable=False),
Column("ps_id", UnsignedInt, ForeignKey("process_schema.id"), nullable=False),
Column("version", UnsignedInt, default=1, nullable=False),
Column("snapshot", JSON, default={}),
Column("owner_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("is_last", UnsignedInt, default=0),
PrimaryKeyConstraint("id", "version"),
)
class NodeStatus(enum.StrEnum):
ACTIVE = "ACTIVE"
DISABLED = "DISABLED"
DELETED = "DELETED"
class NodeType(Enum):
TYPE1 = "Type1"
TYPE2 = "Type2"
TYPE3 = "Type3"
ps_node_table = Table(
"ps_node",
metadata,
Column("id", UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
Column("ps_id", UnsignedInt, ForeignKey("process_schema.id"), nullable=False),
Column("node_type", SQLAEnum(NodeType), nullable=False),
Column("settings", JSON, default={}),
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("status", SQLAEnum(NodeStatus), nullable=False),
Index("idx_ps_id", "ps_id"),
)
class NodeLinkStatus(enum.StrEnum):
ACTIVE = "ACTIVE"
STOPPING = "STOPPING"
STOPPED = "STOPPED"
DELETED = "DELETED"
node_link_table = Table(
"node_link",
metadata,
Column("id", UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
Column("link_name", String(20), nullable=False),
Column("node_id", UnsignedInt, ForeignKey("ps_node.id"), nullable=False),
Column("next_node_id", UnsignedInt, ForeignKey("ps_node.id"), nullable=False),
Column("settings", JSON, default={}),
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
Column("created_at", DateTime(timezone=True), server_default=func.now()),
Column("status", SQLAEnum(NodeLinkStatus), nullable=False),
Index("idx_node_id", "node_id"),
Index("idx_next_node_id", "next_node_id"),
)

View File

@@ -2,10 +2,8 @@ from api.endpoints.auth import api_router as auth_router
from api.endpoints.profile import api_router as profile_router from api.endpoints.profile import api_router as profile_router
from api.endpoints.account import api_router as account_router from api.endpoints.account import api_router as account_router
from api.endpoints.keyring import api_router as keyring_router from api.endpoints.keyring import api_router as keyring_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] list_of_routes = [auth_router, profile_router, account_router, keyring_router]
__all__ = [ __all__ = [
"list_of_routes", "list_of_routes",

View File

@@ -1,23 +1,32 @@
from typing import List, Optional from fastapi import (
APIRouter,
Depends,
HTTPException,
status,
)
from fastapi import APIRouter, Depends, HTTPException, Query, status
from orm.tables.account import AccountStatus
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from api.db.connection.session import get_connection_dep from api.db.connection.session import get_connection_dep
from api.db.logic.account import ( from api.db.logic.account import (
create_user,
get_user_account_page_DTO,
get_user_by_id, get_user_by_id,
get_user_by_login,
update_user_by_id, update_user_by_id,
create_user,
get_user_by_login,
get_user_accaunt_page,
) )
from api.db.logic.keyring import create_password_key, update_password_key
from api.schemas.account.account import User from api.schemas.account.account import User
from api.db.tables.account import AccountStatus
from api.schemas.base import bearer_schema from api.schemas.base import bearer_schema
from api.schemas.endpoints.account import AllUserResponse, UserCreate, UserFilterDTO, UserUpdate from api.schemas.endpoints.account import UserUpdate, AllUserResponse
from api.services.auth import get_current_user from api.services.auth import get_current_user
from api.services.user_role_validation import db_user_role_validation from api.services.user_role_validation import db_user_role_validation
from api.services.update_data_validation import update_user_data_changes
api_router = APIRouter( api_router = APIRouter(
prefix="/account", prefix="/account",
@@ -27,33 +36,14 @@ api_router = APIRouter(
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllUserResponse) @api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllUserResponse)
async def get_all_account( async def get_all_account(
page: int = Query(1, description="Page number", gt=0), page: int = 1,
limit: int = Query(10, description="КNumber of items per page", gt=0), limit: int = 10,
search: Optional[str] = Query(None, description="Search term to filter by name or login or email"),
status_filter: Optional[List[str]] = Query(None, description="Filter by status"),
role_filter: Optional[List[str]] = Query(None, description="Filter by role"),
creator_id: Optional[int] = Query(None, description="Filter by creator id"),
order_field: Optional[str] = Query("id", description="Field to sort by"),
order_direction: Optional[str] = Query("asc", description="Sort direction (asc/desc)"),
connection: AsyncConnection = Depends(get_connection_dep), connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user), current_user=Depends(get_current_user),
): ):
authorize_user = await db_user_role_validation(connection, current_user) authorize_user = await db_user_role_validation(connection, current_user)
filters = { user_list = await get_user_accaunt_page(connection, page, limit)
**({"status": status_filter} if status_filter else {}),
**({"role": role_filter} if role_filter else {}),
**({"creator_id": [str(creator_id)]} if creator_id else {}),
}
filter_dto = UserFilterDTO(
pagination={"page": page, "limit": limit},
search=search,
order={"field": order_field, "direction": order_direction},
filters=filters if filters else None,
)
user_list = await get_user_account_page_DTO(connection, filter_dto)
if user_list is None: if user_list is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Accounts not found") raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Accounts not found")
@@ -63,9 +53,7 @@ async def get_all_account(
@api_router.get("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User) @api_router.get("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
async def get_account( async def get_account(
user_id: int, user_id: int, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
): ):
authorize_user = await db_user_role_validation(connection, current_user) authorize_user = await db_user_role_validation(connection, current_user)
@@ -79,25 +67,24 @@ async def get_account(
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=User) @api_router.post("", dependencies=[Depends(bearer_schema)], response_model=User)
async def create_account( async def create_account(
user: UserCreate, user: UserUpdate, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
): ):
authorize_user = await db_user_role_validation(connection, current_user) authorize_user = await db_user_role_validation(connection, current_user)
user_validation = await get_user_by_login(connection, user.login) user_validation = await get_user_by_login(connection, user.login)
if user_validation is None: if user_validation is None:
new_user = await create_user(connection, user, authorize_user.id) await create_user(connection, user, authorize_user.id)
await create_password_key(connection, user.password, new_user.id) user_new = await get_user_by_login(connection, user.login)
return new_user return user_new
else: else:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, detail="An account with this information already exists." status_code=status.HTTP_400_BAD_REQUEST, detail="An account with this information already exists."
) )
@api_router.put("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=UserUpdate) @api_router.put("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
async def update_account( async def update_account(
user_id: int, user_id: int,
user_update: UserUpdate, user_update: UserUpdate,
@@ -110,15 +97,14 @@ async def update_account(
if user is None: if user is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found") raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
if user_update.password is not None: update_values = update_user_data_changes(user_update, user)
await update_password_key(connection, user.id, user_update.password)
updated_values = user_update.model_dump(by_alias=True, exclude_none=True) if update_values is None:
if not updated_values:
return user return user
await update_user_by_id(connection, updated_values, user) user_update_data = User.model_validate({**user.model_dump(), **update_values})
await update_user_by_id(connection, update_values, user)
user = await get_user_by_id(connection, user_id) user = await get_user_by_id(connection, user_id)
@@ -127,9 +113,7 @@ async def update_account(
@api_router.delete("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User) @api_router.delete("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
async def delete_account( async def delete_account(
user_id: int, user_id: int, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
): ):
authorize_user = await db_user_role_validation(connection, current_user) authorize_user = await db_user_role_validation(connection, current_user)
@@ -139,12 +123,12 @@ async def delete_account(
user_update = UserUpdate(status=AccountStatus.DELETED.value) user_update = UserUpdate(status=AccountStatus.DELETED.value)
updated_values = user_update.model_dump(by_alias=True, exclude_none=True) update_values = update_user_data_changes(user_update, user)
if not updated_values: if update_values is None:
return user return user
await update_user_by_id(connection, updated_values, user) await update_user_by_id(connection, update_values, user)
user = await get_user_by_id(connection, user_id) user = await get_user_by_id(connection, user_id)

View File

@@ -1,14 +1,14 @@
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import jwt
from fastapi import ( from fastapi import (
APIRouter, APIRouter,
Depends, Depends,
HTTPException, HTTPException,
Request,
Response, Response,
status, status,
Request,
) )
from loguru import logger from loguru import logger
from fastapi_jwt_auth import AuthJWT from fastapi_jwt_auth import AuthJWT
@@ -22,7 +22,7 @@ from api.services.auth import authenticate_user
from api.db.logic.auth import add_new_refresh_token, upgrade_old_refresh_token from api.db.logic.auth import add_new_refresh_token, upgrade_old_refresh_token
from api.schemas.endpoints.auth import Auth, Tokens from api.schemas.endpoints.auth import Auth, Access
api_router = APIRouter( api_router = APIRouter(
prefix="/auth", prefix="/auth",
@@ -30,11 +30,21 @@ api_router = APIRouter(
) )
def get_login_from_jwt(token: str):
payload = jwt.decode(
token,
get_settings().SECRET_KEY,
algorithms=[get_settings().ALGORITHM],
)
return payload.get("sub")
class Settings(BaseModel): class Settings(BaseModel):
authjwt_secret_key: str = get_settings().SECRET_KEY authjwt_secret_key: str = get_settings().SECRET_KEY
# Configure application to store and get JWT from cookies # Configure application to store and get JWT from cookies
authjwt_token_location: set = {"headers"} authjwt_token_location: set = {"headers", "cookies"}
authjwt_cookie_domain: str = get_settings().DOMAIN authjwt_cookie_domain: str = get_settings().DOMAIN
authjwt_refresh_cookie_name: str = "refresh_token_cookie"
# Only allow JWT cookies to be sent over https # Only allow JWT cookies to be sent over https
authjwt_cookie_secure: bool = get_settings().ENV == "prod" authjwt_cookie_secure: bool = get_settings().ENV == "prod"
@@ -48,7 +58,7 @@ def get_config():
return Settings() return Settings()
@api_router.post("", response_model=Tokens) @api_router.post("", response_model=Access)
async def login_for_access_token( async def login_for_access_token(
user: Auth, user: Auth,
response: Response, response: Response,
@@ -68,7 +78,9 @@ async def login_for_access_token(
# headers={"WWW-Authenticate": "Bearer"}, # headers={"WWW-Authenticate": "Bearer"},
) )
access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES) # access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES)
access_token_expires = timedelta(seconds=5)
refresh_token_expires = timedelta(days=get_settings().REFRESH_TOKEN_EXPIRE_DAYS) refresh_token_expires = timedelta(days=get_settings().REFRESH_TOKEN_EXPIRE_DAYS)
logger.debug(f"refresh_token_expires {refresh_token_expires}") logger.debug(f"refresh_token_expires {refresh_token_expires}")
@@ -80,27 +92,26 @@ async def login_for_access_token(
await add_new_refresh_token(connection, refresh_token, refresh_token_expires_time, user) await add_new_refresh_token(connection, refresh_token, refresh_token_expires_time, user)
return Tokens(access_token=access_token, refresh_token=refresh_token) Authorize.set_refresh_cookies(refresh_token)
return Access(access_token=access_token)
@api_router.post("/refresh", response_model=Tokens) @api_router.post("/refresh", response_model=Access)
async def refresh( async def refresh(
request: Request, request: Request,
connection: AsyncConnection = Depends(get_connection_dep), connection: AsyncConnection = Depends(get_connection_dep),
Authorize: AuthJWT = Depends(), Authorize: AuthJWT = Depends(),
) -> Tokens: ):
try: refresh_token = request.cookies.get("refresh_token_cookie")
Authorize.jwt_refresh_token_required()
current_user = Authorize.get_jwt_subject()
except Exception:
refresh_token = request.headers.get("Authorization").split(" ")[1]
await upgrade_old_refresh_token(connection, refresh_token)
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid refresh token",
)
access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES) if not refresh_token:
raise HTTPException(status_code=401, detail="Refresh token is missing")
Authorize.jwt_refresh_token_required(refresh_token)
current_user = Authorize.get_jwt_subject()
# try:
# access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES)
access_token_expires = timedelta(seconds=5)
new_access_token = Authorize.create_access_token(subject=current_user, expires_time=access_token_expires) new_access_token = Authorize.create_access_token(subject=current_user, expires_time=access_token_expires)
return Tokens(access_token=new_access_token) return Access(access_token=new_access_token)

View File

@@ -1,19 +1,31 @@
from fastapi import ( from fastapi import (
APIRouter, APIRouter,
Body,
Depends, Depends,
Form,
HTTPException, HTTPException,
Response,
status, status,
) )
from orm.tables.account import KeyStatus
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from api.db.connection.session import get_connection_dep from api.db.connection.session import get_connection_dep
from api.db.logic.keyring import create_key, get_key_by_id, update_key_by_id
from api.schemas.account.account_keyring import AccountKeyring from api.db.logic.keyring import get_key_by_id, create_key, update_key_by_id
from api.db.tables.account import KeyStatus
from api.schemas.base import bearer_schema from api.schemas.base import bearer_schema
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate from api.schemas.endpoints.account_keyring import AccountKeyringUpdate
from api.schemas.account.account_keyring import AccountKeyring
from api.services.auth import get_current_user from api.services.auth import get_current_user
from api.services.user_role_validation import db_user_role_validation from api.services.user_role_validation import db_user_role_validation
from api.services.update_data_validation import update_key_data_changes
api_router = APIRouter( api_router = APIRouter(
prefix="/keyring", prefix="/keyring",
@@ -75,12 +87,14 @@ async def update_keyring(
if keyring is None: if keyring is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="keyring not found") raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="keyring not found")
updated_values = keyring_update.model_dump(by_alias=True, exclude_none=True) update_values = update_key_data_changes(keyring_update, keyring)
if not updated_values: if update_values is None:
return keyring return keyring
await update_key_by_id(connection, updated_values, keyring) keyring_update_data = AccountKeyring.model_validate({**keyring.model_dump(), **update_values})
await update_key_by_id(connection, update_values, keyring)
keyring = await get_key_by_id(connection, key_id) keyring = await get_key_by_id(connection, key_id)
@@ -102,12 +116,12 @@ async def delete_keyring(
keyring_update = AccountKeyringUpdate(status=KeyStatus.DELETED.value) keyring_update = AccountKeyringUpdate(status=KeyStatus.DELETED.value)
updated_values = keyring_update.model_dump(by_alias=True, exclude_none=True) update_values = update_key_data_changes(keyring_update, keyring)
if not updated_values: if update_values is None:
return keyring return keyring
await update_key_by_id(connection, updated_values, keyring) await update_key_by_id(connection, update_values, keyring)
keyring = await get_key_by_id(connection, key_id) keyring = await get_key_by_id(connection, key_id)

View File

@@ -1,169 +0,0 @@
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, Query, status
from orm.tables.events import EventStatus
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.list_events import (
create_list_events,
get_list_events_by_id,
get_list_events_by_name,
get_list_events_page_DTO,
update_list_events_by_id,
)
from api.schemas.base import bearer_schema
from api.schemas.endpoints.list_events import AllListEventResponse, ListEventFilterDTO, ListEventUpdate
from api.schemas.events.list_events import ListEvent
from api.services.auth import get_current_user
from api.services.user_role_validation import (
db_user_role_validation_for_list_events_and_process_schema,
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
)
api_router = APIRouter(
prefix="/list_events",
tags=["list events"],
)
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllListEventResponse)
async def get_all_list_events(
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 name"),
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"),
state_filter: Optional[List[str]] = Query(None, description="Filter by state"),
creator_id: Optional[int] = Query(None, description="Filter by creator id"),
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
filters = {
**({"status": status_filter} if status_filter else {}),
**({"state": state_filter} if state_filter else {}),
**({"creator_id": [str(creator_id)]} if creator_id else {}),
}
filter_dto = ListEventFilterDTO(
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_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_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")
return list_events_page
@api_router.get("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
async def get_list_events(
list_events_id: int,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
list_events_validation = await get_list_events_by_id(connection, list_events_id)
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_list_events_and_process_schema_by_list_event_id(
connection, current_user, list_events_validation.creator_id
)
if list_events_id is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
return list_events_validation
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
async def create_list_events(
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)
list_events_validation = await get_list_events_by_name(connection, list_events.name)
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(
status_code=status.HTTP_400_BAD_REQUEST, detail="An List events with this information already exists."
)
@api_router.put("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
async def update_list_events(
list_events_id: int,
list_events_update: ListEventUpdate,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
list_events_validation = await get_list_events_by_id(connection, list_events_id)
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_list_events_and_process_schema_by_list_event_id(
connection, current_user, list_events_validation.creator_id
)
updated_values = list_events_update.model_dump(by_alias=True, exclude_none=True)
if not updated_values:
return list_events_validation
await update_list_events_by_id(connection, updated_values, list_events_validation)
list_events = await get_list_events_by_id(connection, list_events_id)
return list_events
@api_router.delete("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
async def delete_list_events(
list_events_id: int,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
list_events_validation = await get_list_events_by_id(connection, list_events_id)
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_list_events_and_process_schema_by_list_event_id(
connection, current_user, list_events_validation.creator_id
)
list_events_update = ListEventUpdate(status=EventStatus.DELETED.value)
updated_values = list_events_update.model_dump(by_alias=True, exclude_none=True)
if not updated_values:
return list_events_validation
await update_list_events_by_id(connection, updated_values, list_events_validation)
list_events = await get_list_events_by_id(connection, list_events_id)
return list_events

View File

@@ -1,169 +0,0 @@
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, Query, status
from orm.tables.process import ProcessStatus
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.process_schema import (
create_process_schema,
get_process_schema_by_id,
get_process_schema_by_title,
get_process_schema_page_DTO,
update_process_schema_by_id,
)
from api.schemas.base import bearer_schema
from api.schemas.endpoints.process_schema import AllProcessSchemaResponse, ProcessSchemaFilterDTO, ProcessSchemaUpdate
from api.schemas.process.process_schema import ProcessSchema
from api.services.auth import get_current_user
from api.services.user_role_validation import (
db_user_role_validation_for_list_events_and_process_schema,
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
)
api_router = APIRouter(
prefix="/process_schema",
tags=["process schema"],
)
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllProcessSchemaResponse)
async def get_all_process_schema(
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_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)]
process_schema_page = await get_process_schema_page_DTO(connection, filter_dto)
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("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def get_process_schema(
process_schema_id: int,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
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_list_events_and_process_schema_by_list_event_id(
connection, current_user, process_schema_validation.creator_id
)
if process_schema_id is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
return process_schema_validation
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def create_processschema(
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)
process_schema_validation = await get_process_schema_by_title(connection, process_schema.title)
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(
status_code=status.HTTP_400_BAD_REQUEST, detail="An process schema with this information already exists."
)
@api_router.put("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def update_process_schema(
process_schema_id: int,
process_schema_update: ProcessSchemaUpdate,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
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_list_events_and_process_schema_by_list_event_id(
connection, current_user, process_schema_validation.creator_id
)
updated_values = process_schema_update.model_dump(by_alias=True, exclude_none=True)
if not updated_values:
return process_schema_validation
await update_process_schema_by_id(connection, updated_values, process_schema_validation)
process_schema = await get_process_schema_by_id(connection, process_schema_id)
return process_schema
@api_router.delete("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
async def delete_process_schema(
process_schema_id: int,
connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user),
):
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
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_list_events_and_process_schema_by_list_event_id(
connection, current_user, process_schema_validation.creator_id
)
process_schema_update = ProcessSchemaUpdate(status=ProcessStatus.DELETED.value)
updated_values = process_schema_update.model_dump(by_alias=True, exclude_none=True)
if not updated_values:
return process_schema_validation
await update_process_schema_by_id(connection, updated_values, process_schema_validation)
process_schema = await get_process_schema_by_id(connection, process_schema_id)
return process_schema

View File

@@ -1,17 +1,26 @@
from fastapi import ( from fastapi import (
APIRouter, APIRouter,
Body,
Depends, Depends,
Form,
HTTPException, HTTPException,
Request,
Response,
status, status,
) )
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from api.db.connection.session import get_connection_dep from api.db.connection.session import get_connection_dep
from api.db.logic.account import get_user_by_id, get_user_by_login, update_user_by_id from api.db.logic.account import get_user_by_id, update_user_by_id, get_user_by_login
from api.schemas.account.account import User
from api.schemas.base import bearer_schema from api.schemas.base import bearer_schema
from api.schemas.endpoints.account import UserUpdate
from api.services.auth import get_current_user from api.services.auth import get_current_user
from api.services.update_data_validation import update_user_data_changes
from api.schemas.endpoints.account import UserUpdate
from api.schemas.account.account import User
api_router = APIRouter( api_router = APIRouter(
prefix="/profile", prefix="/profile",
@@ -33,7 +42,7 @@ async def get_profile(
@api_router.put("", dependencies=[Depends(bearer_schema)], response_model=User) @api_router.put("", dependencies=[Depends(bearer_schema)], response_model=User)
async def update_profile( async def update_profile(
user_update: UserUpdate, user_updata: UserUpdate,
connection: AsyncConnection = Depends(get_connection_dep), connection: AsyncConnection = Depends(get_connection_dep),
current_user=Depends(get_current_user), current_user=Depends(get_current_user),
): ):
@@ -41,13 +50,13 @@ async def update_profile(
if user is None: if user is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found") raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
if user_update.role is None and user_update.login is None: if user_updata.role == None and user_updata.login == None:
updated_values = user_update.model_dump(by_alias=True, exclude_none=True) update_values = update_user_data_changes(user_updata, user)
if updated_values is None: if update_values is None:
return user return user
await update_user_by_id(connection, updated_values, user) await update_user_by_id(connection, update_values, user)
user = await get_user_by_id(connection, user.id) user = await get_user_by_id(connection, user.id)

View File

@@ -1,8 +1,8 @@
import datetime
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
from orm.tables.account import AccountRole, AccountStatus
from pydantic import EmailStr, Field from pydantic import EmailStr, Field
from api.db.tables.account import AccountRole, AccountStatus
from api.schemas.base import Base from api.schemas.base import Base

View File

@@ -1,8 +1,8 @@
from datetime import datetime import datetime
from typing import Optional from typing import Optional
from orm.tables.account import KeyStatus, KeyType
from pydantic import Field from pydantic import Field
from datetime import datetime
from api.db.tables.account import KeyType, KeyStatus
from api.schemas.base import Base from api.schemas.base import Base

View File

@@ -1,34 +1,25 @@
from typing import Optional, List
from datetime import datetime from datetime import datetime
from typing import Dict, List, Optional
from orm.tables.account import AccountRole, AccountStatus
from pydantic import EmailStr, Field, TypeAdapter from pydantic import EmailStr, Field, TypeAdapter
from api.db.tables.account import AccountRole, AccountStatus
from api.schemas.base import Base from api.schemas.base import Base
class UserUpdate(Base): class UserUpdate(Base):
id: Optional[int] = None
name: Optional[str] = Field(None, max_length=100) name: Optional[str] = Field(None, max_length=100)
login: Optional[str] = Field(None, max_length=100) login: Optional[str] = Field(None, max_length=100)
email: Optional[EmailStr] = None email: Optional[EmailStr] = None
password: Optional[str] = None
bind_tenant_id: Optional[str] = Field(None, max_length=40) bind_tenant_id: Optional[str] = Field(None, max_length=40)
role: Optional[AccountRole] = None role: Optional[AccountRole] = None
meta: Optional[dict] = None meta: Optional[dict] = None
creator_id: Optional[int] = None
created_at: Optional[datetime] = None
status: Optional[AccountStatus] = None status: Optional[AccountStatus] = None
class UserCreate(Base):
name: str = Field(max_length=100)
login: str = Field(max_length=100)
email: Optional[EmailStr] = None
password: Optional[str] = None
bind_tenant_id: Optional[str] = Field(None, max_length=40)
role: AccountRole
meta: Optional[dict] = None
status: AccountStatus
class AllUser(Base): class AllUser(Base):
id: int id: int
name: str name: str
@@ -36,8 +27,6 @@ class AllUser(Base):
email: Optional[EmailStr] = None email: Optional[EmailStr] = None
bind_tenant_id: Optional[str] = None bind_tenant_id: Optional[str] = None
role: AccountRole role: AccountRole
meta: Optional[dict] = None
creator_id: Optional[int] = None
created_at: datetime created_at: datetime
status: AccountStatus status: AccountStatus
@@ -46,15 +35,6 @@ class AllUserResponse(Base):
users: List[AllUser] users: List[AllUser]
amount_count: int amount_count: int
amount_pages: int amount_pages: int
current_page: int
limit: int
all_user_adapter = TypeAdapter(List[AllUser]) all_user_adapter = TypeAdapter(List[AllUser])
class UserFilterDTO(Base):
pagination: Dict[str, int]
search: Optional[str] = None
order: Optional[Dict[str, str]] = None
filters: Optional[Dict[str, List[str]]] = None

View File

@@ -1,7 +1,8 @@
import datetime
from typing import Optional from typing import Optional
from orm.tables.account import KeyStatus, KeyType
from pydantic import Field from pydantic import Field
from datetime import datetime
from api.db.tables.account import KeyType, KeyStatus
from api.schemas.base import Base from api.schemas.base import Base
@@ -9,5 +10,8 @@ from api.schemas.base import Base
class AccountKeyringUpdate(Base): class AccountKeyringUpdate(Base):
owner_id: Optional[int] = None owner_id: Optional[int] = None
key_type: Optional[KeyType] = None key_type: Optional[KeyType] = None
key_id: Optional[str] = Field(None, max_length=40)
key_value: Optional[str] = Field(None, max_length=255) key_value: Optional[str] = Field(None, max_length=255)
created_at: Optional[datetime] = None
expiry: Optional[datetime] = None
status: Optional[KeyStatus] = None status: Optional[KeyStatus] = None

View File

@@ -1,6 +1,5 @@
from api.schemas.base import Base from api.schemas.base import Base
# Таблица для получения информации из запроса # Таблица для получения информации из запроса
@@ -9,6 +8,9 @@ class Auth(Base):
password: str password: str
class Tokens(Base): class Refresh(Base):
refresh_token: str
class Access(Base):
access_token: str access_token: str
refresh_token: str | None = None

View File

@@ -1,44 +0,0 @@
from datetime import datetime
from typing import Any, Dict, List, Optional
from orm.tables.events import EventState, EventStatus
from pydantic import Field, TypeAdapter
from api.schemas.base import Base
class ListEventUpdate(Base):
name: Optional[str] = Field(None, max_length=40)
title: Optional[str] = Field(None, max_length=64)
schema_: Optional[Dict[str, Any]] = Field(None, alias="schema")
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={}, alias="schema")
state: EventState
status: EventStatus
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])
class ListEventFilterDTO(Base):
pagination: Dict[str, int]
search: Optional[str] = None
order: Optional[Dict[str, str]] = None
filters: Optional[Dict[str, List[str]]] = None

View File

@@ -1,44 +0,0 @@
from datetime import datetime
from typing import Any, Dict, List, Optional
from orm.tables.process import ProcessStatus
from pydantic import Field, TypeAdapter
from api.schemas.base import Base
class ProcessSchemaUpdate(Base):
title: Optional[str] = Field(None, max_length=100)
description: Optional[str] = None
owner_id: Optional[int] = None
settings: Optional[Dict[str, Any]] = None
status: Optional[ProcessStatus] = None
class AllProcessSchema(Base):
id: int
title: str = Field(..., max_length=100)
description: str
owner_id: int
creator_id: int
created_at: datetime
settings: Dict[str, Any]
status: ProcessStatus
class AllProcessSchemaResponse(Base):
process_schema: List[AllProcessSchema]
amount_count: int
amount_pages: int
current_page: int
limit: int
all_process_schema_adapter = TypeAdapter(List[AllProcessSchema])
class ProcessSchemaFilterDTO(Base):
pagination: Dict[str, int]
search: Optional[str] = None
order: Optional[Dict[str, str]] = None
filters: Optional[Dict[str, List[str]]] = None

View File

@@ -1,18 +1,28 @@
from datetime import datetime
from typing import Any, Dict
from orm.tables.events import EventState, EventStatus
from pydantic import Field from pydantic import Field
from typing import Dict, Any
from datetime import datetime
from enum import Enum
from api.schemas.base import Base from api.schemas.base import Base
class State(Enum):
AUTO = "Auto"
DESCRIPTED = "Descripted"
class Status(Enum):
ACTIVE = "Active"
DISABLED = "Disabled"
DELETED = "Deleted"
class ListEvent(Base): class ListEvent(Base):
id: int id: int
name: str = Field(..., max_length=40) name: str = Field(..., max_length=40)
title: str = Field(..., max_length=64) title: str = Field(..., max_length=64)
creator_id: int creator_id: int
created_at: datetime created_at: datetime
schema_: Dict[str, Any] = Field(..., alias="schema") schema: Dict[str, Any]
state: EventState state: State
status: EventStatus status: Status

View File

@@ -1,12 +1,18 @@
from datetime import datetime
from typing import Any, Dict
from orm.tables.process import NodeStatus
from pydantic import Field from pydantic import Field
from typing import Dict, Any
from datetime import datetime
from enum import Enum
from api.schemas.base import Base from api.schemas.base import Base
class Status(Enum):
ACTIVE = "Active"
STOPPING = "Stopping"
STOPPED = "Stopped"
DELETED = "Deleted"
class MyModel(Base): class MyModel(Base):
id: int id: int
link_name: str = Field(..., max_length=20) link_name: str = Field(..., max_length=20)
@@ -15,4 +21,4 @@ class MyModel(Base):
settings: Dict[str, Any] settings: Dict[str, Any]
creator_id: int creator_id: int
created_at: datetime created_at: datetime
status: NodeStatus status: Status

View File

@@ -1,12 +1,18 @@
from datetime import datetime
from typing import Any, Dict
from orm.tables.process import ProcessStatus
from pydantic import Field from pydantic import Field
from typing import Dict, Any
from datetime import datetime
from enum import Enum
from api.schemas.base import Base from api.schemas.base import Base
class Status(Enum):
ACTIVE = "Active"
STOPPING = "Stopping"
STOPPED = "Stopped"
DELETED = "Deleted"
class ProcessSchema(Base): class ProcessSchema(Base):
id: int id: int
title: str = Field(..., max_length=100) title: str = Field(..., max_length=100)
@@ -15,4 +21,4 @@ class ProcessSchema(Base):
creator_id: int creator_id: int
created_at: datetime created_at: datetime
settings: Dict[str, Any] settings: Dict[str, Any]
status: ProcessStatus status: Status

View File

@@ -1,5 +1,5 @@
from typing import Dict, Any
from datetime import datetime from datetime import datetime
from typing import Any, Dict
from api.schemas.base import Base from api.schemas.base import Base

View File

@@ -1,11 +1,20 @@
from datetime import datetime from datetime import datetime
from typing import Any, Dict from typing import Dict, Any
from enum import Enum
from orm.tables.process import NodeStatus, NodeType
from api.schemas.base import Base from api.schemas.base import Base
class NodeType(Enum):
pass
class Status(Enum):
ACTIVE = "Active"
DISABLED = "Disabled"
DELETED = "Deleted"
class Ps_Node(Base): class Ps_Node(Base):
id: int id: int
ps_id: int ps_id: int
@@ -13,4 +22,4 @@ class Ps_Node(Base):
settings: dict settings: dict
creator_id: Dict[str, Any] creator_id: Dict[str, Any]
created_at: datetime created_at: datetime
status: NodeStatus status: Status

View File

@@ -1,25 +1,27 @@
from fastapi import Request, HTTPException
from typing import Optional from typing import Optional
from fastapi import HTTPException, Request
from orm.tables.account import AccountStatus
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from api.db.logic.auth import get_user from api.db.logic.auth import get_user
from api.schemas.endpoints.account import AllUser
from api.utils.hasher import hasher # # from backend.schemas.users.token import TokenData
from api.schemas.account.account import User
from api.db.tables.account import AccountStatus
from api.utils.hasher import Hasher
async def get_current_user(request: Request) -> str | HTTPException: async def get_current_user(request: Request) -> Optional[User]:
if not hasattr(request.state, "current_user"): if not hasattr(request.state, "current_user"):
return HTTPException(status_code=401, detail="Unauthorized") return HTTPException(status_code=401, detail="Unauthorized")
return request.state.current_user return request.state.current_user
async def authenticate_user(connection: AsyncConnection, username: str, password: str) -> Optional[AllUser]: async def authenticate_user(connection: AsyncConnection, username: str, password: str) -> Optional[User]:
sql_user, sql_password = await get_user(connection, username) sql_user, sql_password = await get_user(connection, username)
if not sql_user or sql_user.status != AccountStatus.ACTIVE: if not sql_user or sql_user.status != AccountStatus.ACTIVE:
return None return None
hasher = Hasher()
if not hasher.verify_data(password, sql_password.key_value): if not hasher.verify_data(password, sql_password.key_value):
return None return None
return sql_user return sql_user

View File

@@ -1,16 +1,18 @@
import re from starlette.middleware.base import BaseHTTPMiddleware
from re import escape
from fastapi import ( from fastapi import (
Request, Request,
status, status,
) )
from fastapi.responses import JSONResponse
from fastapi_jwt_auth import AuthJWT
from starlette.middleware.base import BaseHTTPMiddleware
from fastapi.responses import JSONResponse
from api.config import get_settings from api.config import get_settings
import re
from re import escape
from fastapi_jwt_auth import AuthJWT
class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware): class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware):
def __init__(self, app): def __init__(self, app):
@@ -30,8 +32,10 @@ class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware):
status_code=status.HTTP_405_METHOD_NOT_ALLOWED, status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
content={"detail": "Method not allowed"}, content={"detail": "Method not allowed"},
) )
if any(pattern.match(request.url.path) for pattern in self.excluded_routes): if any(pattern.match(request.url.path) for pattern in self.excluded_routes):
return await call_next(request) return await call_next(request)
auth_header = request.headers.get("Authorization") auth_header = request.headers.get("Authorization")
if not auth_header: if not auth_header:
return JSONResponse( return JSONResponse(
@@ -39,6 +43,7 @@ class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware):
content={"detail": "Missing authorization header."}, content={"detail": "Missing authorization header."},
headers={"WWW-Authenticate": "Bearer"}, headers={"WWW-Authenticate": "Bearer"},
) )
try: try:
token = auth_header.split(" ")[1] token = auth_header.split(" ")[1]
Authorize = AuthJWT(request) Authorize = AuthJWT(request)
@@ -50,4 +55,5 @@ class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware):
content={"detail": "The access token is invalid or expired."}, content={"detail": "The access token is invalid or expired."},
headers={"WWW-Authenticate": "Bearer"}, headers={"WWW-Authenticate": "Bearer"},
) )
return await call_next(request) return await call_next(request)

View File

@@ -0,0 +1,74 @@
from enum import Enum
from typing import Optional
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
def update_user_data_changes(update_data: UserUpdate, user) -> Optional[dict]:
"""
Сравнивает данные для обновления с текущими значениями пользователя.
Возвращает:
- None, если нет изменений
- Словарь {поле: новое_значение} для измененных полей
"""
update_values = {}
changes = {}
for field, value in update_data.model_dump(exclude_unset=True).items():
if value is None:
continue
if isinstance(value, (AccountRole, AccountStatus)):
update_values[field] = value.value
else:
update_values[field] = value
for field, new_value in update_values.items():
if not hasattr(user, field):
continue
current_value = getattr(user, 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
def update_key_data_changes(update_data: AccountKeyringUpdate, key) -> Optional[dict]:
"""
Сравнивает данные для обновления с текущими значениями пользователя.
Возвращает:
- None, если нет изменений
- Словарь {поле: новое_значение} для измененных полей
"""
update_values = {}
changes = {}
for field, value in update_data.model_dump(exclude_unset=True).items():
if value is None:
continue
if isinstance(value, (KeyType, KeyStatus)):
update_values[field] = value.value
else:
update_values[field] = value
for field, new_value in update_values.items():
if not hasattr(key, field):
continue
current_value = getattr(key, 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

View File

@@ -2,9 +2,8 @@ from fastapi import (
HTTPException, HTTPException,
status, status,
) )
from orm.tables.account import AccountRole
from api.db.logic.account import get_user_by_login from api.db.logic.account import get_user_by_login
from api.db.tables.account import AccountRole
async def db_user_role_validation(connection, current_user): async def db_user_role_validation(connection, current_user):
@@ -12,21 +11,3 @@ async def db_user_role_validation(connection, current_user):
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}: 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") raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions")
return authorize_user return authorize_user
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)
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
if authorize_user.id != current_listevents_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_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
else:
return authorize_user, True

View File

@@ -1,6 +1,4 @@
import hashlib import hashlib
import secrets
# Хешер для работы с паролем. # Хешер для работы с паролем.
@@ -16,10 +14,3 @@ class Hasher:
def verify_data(self, password: str, hashed: str) -> bool: def verify_data(self, password: str, hashed: str) -> bool:
# Проверяет пароль путем сравнения его хеша с сохраненным хешем. # Проверяет пароль путем сравнения его хеша с сохраненным хешем.
return self.hash_data(password) == hashed return self.hash_data(password) == hashed
@staticmethod
def generate_password() -> str:
return secrets.token_urlsafe(20)
hasher = Hasher()

View File

@@ -1,24 +1,32 @@
import asyncio
import os import os
import asyncio
from orm.tables.account import account_keyring_table, account_table, AccountRole, KeyStatus, KeyType import hashlib
import secrets
from api.db.connection.session import get_connection from api.db.connection.session import get_connection
from api.utils.hasher import hasher from api.db.tables.account import account_table, account_keyring_table, AccountRole, KeyType, KeyStatus
from api.utils.key_id_gen import KeyIdGenerator from api.utils.key_id_gen import KeyIdGenerator
INIT_LOCK_FILE = "../init.lock" INIT_LOCK_FILE = "../init.lock"
DEFAULT_LOGIN = "vorkout" DEFAULT_LOGIN = "vorkout"
def hash_password(password: str) -> str:
return hashlib.sha256(password.encode()).hexdigest()
def generate_password() -> str:
return secrets.token_urlsafe(20)
async def init(): async def init():
if os.path.exists(INIT_LOCK_FILE): if os.path.exists(INIT_LOCK_FILE):
print("Sorry, service is already initialized") print("Sorry, service is already initialized")
return return
async with get_connection() as conn: async with get_connection() as conn:
password = hasher.generate_password() password = generate_password()
hashed_password = hasher.hash_data(password) hashed_password = hash_password(password)
create_user_query = account_table.insert().values( create_user_query = account_table.insert().values(
name=DEFAULT_LOGIN, name=DEFAULT_LOGIN,

153
api/poetry.lock generated
View File

@@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 2.1.4 and should not be changed by hand. # This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand.
[[package]] [[package]]
name = "aio-pika" name = "aio-pika"
@@ -227,25 +227,6 @@ files = [
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
] ]
[[package]]
name = "core-library"
version = "0.1.0"
description = "Abstract classes library for the Vorkout project"
optional = false
python-versions = ">=3.9"
groups = ["main"]
files = []
develop = false
[package.dependencies]
sqlalchemy = ">=2.0.43,<3.0.0"
[package.source]
type = "git"
url = "https://gitea.heado.ru/Vorkout/core.git"
reference = "0.1.0"
resolved_reference = "96ddb52582660600dbacead4919e67f948e96898"
[[package]] [[package]]
name = "cryptography" name = "cryptography"
version = "44.0.2" version = "44.0.2"
@@ -1435,83 +1416,83 @@ files = [
[[package]] [[package]]
name = "sqlalchemy" name = "sqlalchemy"
version = "2.0.43" version = "2.0.39"
description = "Database Abstraction Library" description = "Database Abstraction Library"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
groups = ["main"] groups = ["main"]
files = [ files = [
{file = "SQLAlchemy-2.0.43-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:21ba7a08a4253c5825d1db389d4299f64a100ef9800e4624c8bf70d8f136e6ed"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:66a40003bc244e4ad86b72abb9965d304726d05a939e8c09ce844d27af9e6d37"},
{file = "SQLAlchemy-2.0.43-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:11b9503fa6f8721bef9b8567730f664c5a5153d25e247aadc69247c4bc605227"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:67de057fbcb04a066171bd9ee6bcb58738d89378ee3cabff0bffbf343ae1c787"},
{file = "SQLAlchemy-2.0.43-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:07097c0a1886c150ef2adba2ff7437e84d40c0f7dcb44a2c2b9c905ccfc6361c"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:533e0f66c32093a987a30df3ad6ed21170db9d581d0b38e71396c49718fbb1ca"},
{file = "SQLAlchemy-2.0.43-cp37-cp37m-musllinux_1_2_aarch64.whl", hash = "sha256:cdeff998cb294896a34e5b2f00e383e7c5c4ef3b4bfa375d9104723f15186443"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-musllinux_1_2_aarch64.whl", hash = "sha256:7399d45b62d755e9ebba94eb89437f80512c08edde8c63716552a3aade61eb42"},
{file = "SQLAlchemy-2.0.43-cp37-cp37m-musllinux_1_2_x86_64.whl", hash = "sha256:bcf0724a62a5670e5718957e05c56ec2d6850267ea859f8ad2481838f889b42c"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-musllinux_1_2_x86_64.whl", hash = "sha256:788b6ff6728072b313802be13e88113c33696a9a1f2f6d634a97c20f7ef5ccce"},
{file = "SQLAlchemy-2.0.43-cp37-cp37m-win32.whl", hash = "sha256:c697575d0e2b0a5f0433f679bda22f63873821d991e95a90e9e52aae517b2e32"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-win32.whl", hash = "sha256:01da15490c9df352fbc29859d3c7ba9cd1377791faeeb47c100832004c99472c"},
{file = "SQLAlchemy-2.0.43-cp37-cp37m-win_amd64.whl", hash = "sha256:d34c0f6dbefd2e816e8f341d0df7d4763d382e3f452423e752ffd1e213da2512"}, {file = "SQLAlchemy-2.0.39-cp37-cp37m-win_amd64.whl", hash = "sha256:f2bcb085faffcacf9319b1b1445a7e1cfdc6fb46c03f2dce7bc2d9a4b3c1cdc5"},
{file = "sqlalchemy-2.0.43-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:70322986c0c699dca241418fcf18e637a4369e0ec50540a2b907b184c8bca069"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b761a6847f96fdc2d002e29e9e9ac2439c13b919adfd64e8ef49e75f6355c548"},
{file = "sqlalchemy-2.0.43-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:87accdbba88f33efa7b592dc2e8b2a9c2cdbca73db2f9d5c510790428c09c154"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:0d7e3866eb52d914aea50c9be74184a0feb86f9af8aaaa4daefe52b69378db0b"},
{file = "sqlalchemy-2.0.43-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c00e7845d2f692ebfc7d5e4ec1a3fd87698e4337d09e58d6749a16aedfdf8612"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:995c2bacdddcb640c2ca558e6760383dcdd68830160af92b5c6e6928ffd259b4"},
{file = "sqlalchemy-2.0.43-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:022e436a1cb39b13756cf93b48ecce7aa95382b9cfacceb80a7d263129dfd019"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:344cd1ec2b3c6bdd5dfde7ba7e3b879e0f8dd44181f16b895940be9b842fd2b6"},
{file = "sqlalchemy-2.0.43-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:c5e73ba0d76eefc82ec0219d2301cb33bfe5205ed7a2602523111e2e56ccbd20"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:5dfbc543578058c340360f851ddcecd7a1e26b0d9b5b69259b526da9edfa8875"},
{file = "sqlalchemy-2.0.43-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:9c2e02f06c68092b875d5cbe4824238ab93a7fa35d9c38052c033f7ca45daa18"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:3395e7ed89c6d264d38bea3bfb22ffe868f906a7985d03546ec7dc30221ea980"},
{file = "sqlalchemy-2.0.43-cp310-cp310-win32.whl", hash = "sha256:e7a903b5b45b0d9fa03ac6a331e1c1d6b7e0ab41c63b6217b3d10357b83c8b00"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-win32.whl", hash = "sha256:bf555f3e25ac3a70c67807b2949bfe15f377a40df84b71ab2c58d8593a1e036e"},
{file = "sqlalchemy-2.0.43-cp310-cp310-win_amd64.whl", hash = "sha256:4bf0edb24c128b7be0c61cd17eef432e4bef507013292415f3fb7023f02b7d4b"}, {file = "SQLAlchemy-2.0.39-cp38-cp38-win_amd64.whl", hash = "sha256:463ecfb907b256e94bfe7bcb31a6d8c7bc96eca7cbe39803e448a58bb9fcad02"},
{file = "sqlalchemy-2.0.43-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:52d9b73b8fb3e9da34c2b31e6d99d60f5f99fd8c1225c9dad24aeb74a91e1d29"}, {file = "sqlalchemy-2.0.39-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6827f8c1b2f13f1420545bd6d5b3f9e0b85fe750388425be53d23c760dcf176b"},
{file = "sqlalchemy-2.0.43-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f42f23e152e4545157fa367b2435a1ace7571cab016ca26038867eb7df2c3631"}, {file = "sqlalchemy-2.0.39-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d9f119e7736967c0ea03aff91ac7d04555ee038caf89bb855d93bbd04ae85b41"},
{file = "sqlalchemy-2.0.43-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4fb1a8c5438e0c5ea51afe9c6564f951525795cf432bed0c028c1cb081276685"}, {file = "sqlalchemy-2.0.39-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4600c7a659d381146e1160235918826c50c80994e07c5b26946a3e7ec6c99249"},
{file = "sqlalchemy-2.0.43-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db691fa174e8f7036afefe3061bc40ac2b770718be2862bfb03aabae09051aca"}, {file = "sqlalchemy-2.0.39-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4a06e6c8e31c98ddc770734c63903e39f1947c9e3e5e4bef515c5491b7737dde"},
{file = "sqlalchemy-2.0.43-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:fe2b3b4927d0bc03d02ad883f402d5de201dbc8894ac87d2e981e7d87430e60d"}, {file = "sqlalchemy-2.0.39-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:c4c433f78c2908ae352848f56589c02b982d0e741b7905228fad628999799de4"},
{file = "sqlalchemy-2.0.43-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:4d3d9b904ad4a6b175a2de0738248822f5ac410f52c2fd389ada0b5262d6a1e3"}, {file = "sqlalchemy-2.0.39-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:7bd5c5ee1448b6408734eaa29c0d820d061ae18cb17232ce37848376dcfa3e92"},
{file = "sqlalchemy-2.0.43-cp311-cp311-win32.whl", hash = "sha256:5cda6b51faff2639296e276591808c1726c4a77929cfaa0f514f30a5f6156921"}, {file = "sqlalchemy-2.0.39-cp310-cp310-win32.whl", hash = "sha256:87a1ce1f5e5dc4b6f4e0aac34e7bb535cb23bd4f5d9c799ed1633b65c2bcad8c"},
{file = "sqlalchemy-2.0.43-cp311-cp311-win_amd64.whl", hash = "sha256:c5d1730b25d9a07727d20ad74bc1039bbbb0a6ca24e6769861c1aa5bf2c4c4a8"}, {file = "sqlalchemy-2.0.39-cp310-cp310-win_amd64.whl", hash = "sha256:871f55e478b5a648c08dd24af44345406d0e636ffe021d64c9b57a4a11518304"},
{file = "sqlalchemy-2.0.43-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:20d81fc2736509d7a2bd33292e489b056cbae543661bb7de7ce9f1c0cd6e7f24"}, {file = "sqlalchemy-2.0.39-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a28f9c238f1e143ff42ab3ba27990dfb964e5d413c0eb001b88794c5c4a528a9"},
{file = "sqlalchemy-2.0.43-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:25b9fc27650ff5a2c9d490c13c14906b918b0de1f8fcbb4c992712d8caf40e83"}, {file = "sqlalchemy-2.0.39-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:08cf721bbd4391a0e765fe0fe8816e81d9f43cece54fdb5ac465c56efafecb3d"},
{file = "sqlalchemy-2.0.43-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6772e3ca8a43a65a37c88e2f3e2adfd511b0b1da37ef11ed78dea16aeae85bd9"}, {file = "sqlalchemy-2.0.39-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7a8517b6d4005facdbd7eb4e8cf54797dbca100a7df459fdaff4c5123265c1cd"},
{file = "sqlalchemy-2.0.43-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1a113da919c25f7f641ffbd07fbc9077abd4b3b75097c888ab818f962707eb48"}, {file = "sqlalchemy-2.0.39-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4b2de1523d46e7016afc7e42db239bd41f2163316935de7c84d0e19af7e69538"},
{file = "sqlalchemy-2.0.43-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:4286a1139f14b7d70141c67a8ae1582fc2b69105f1b09d9573494eb4bb4b2687"}, {file = "sqlalchemy-2.0.39-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:412c6c126369ddae171c13987b38df5122cb92015cba6f9ee1193b867f3f1530"},
{file = "sqlalchemy-2.0.43-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:529064085be2f4d8a6e5fab12d36ad44f1909a18848fcfbdb59cc6d4bbe48efe"}, {file = "sqlalchemy-2.0.39-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:6b35e07f1d57b79b86a7de8ecdcefb78485dab9851b9638c2c793c50203b2ae8"},
{file = "sqlalchemy-2.0.43-cp312-cp312-win32.whl", hash = "sha256:b535d35dea8bbb8195e7e2b40059e2253acb2b7579b73c1b432a35363694641d"}, {file = "sqlalchemy-2.0.39-cp311-cp311-win32.whl", hash = "sha256:3eb14ba1a9d07c88669b7faf8f589be67871d6409305e73e036321d89f1d904e"},
{file = "sqlalchemy-2.0.43-cp312-cp312-win_amd64.whl", hash = "sha256:1c6d85327ca688dbae7e2b06d7d84cfe4f3fffa5b5f9e21bb6ce9d0e1a0e0e0a"}, {file = "sqlalchemy-2.0.39-cp311-cp311-win_amd64.whl", hash = "sha256:78f1b79132a69fe8bd6b5d91ef433c8eb40688ba782b26f8c9f3d2d9ca23626f"},
{file = "sqlalchemy-2.0.43-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e7c08f57f75a2bb62d7ee80a89686a5e5669f199235c6d1dac75cd59374091c3"}, {file = "sqlalchemy-2.0.39-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c457a38351fb6234781d054260c60e531047e4d07beca1889b558ff73dc2014b"},
{file = "sqlalchemy-2.0.43-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:14111d22c29efad445cd5021a70a8b42f7d9152d8ba7f73304c4d82460946aaa"}, {file = "sqlalchemy-2.0.39-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:018ee97c558b499b58935c5a152aeabf6d36b3d55d91656abeb6d93d663c0c4c"},
{file = "sqlalchemy-2.0.43-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:21b27b56eb2f82653168cefe6cb8e970cdaf4f3a6cb2c5e3c3c1cf3158968ff9"}, {file = "sqlalchemy-2.0.39-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5493a8120d6fc185f60e7254fc056a6742f1db68c0f849cfc9ab46163c21df47"},
{file = "sqlalchemy-2.0.43-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9c5a9da957c56e43d72126a3f5845603da00e0293720b03bde0aacffcf2dc04f"}, {file = "sqlalchemy-2.0.39-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b2cf5b5ddb69142511d5559c427ff00ec8c0919a1e6c09486e9c32636ea2b9dd"},
{file = "sqlalchemy-2.0.43-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:5d79f9fdc9584ec83d1b3c75e9f4595c49017f5594fee1a2217117647225d738"}, {file = "sqlalchemy-2.0.39-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:9f03143f8f851dd8de6b0c10784363712058f38209e926723c80654c1b40327a"},
{file = "sqlalchemy-2.0.43-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9df7126fd9db49e3a5a3999442cc67e9ee8971f3cb9644250107d7296cb2a164"}, {file = "sqlalchemy-2.0.39-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:06205eb98cb3dd52133ca6818bf5542397f1dd1b69f7ea28aa84413897380b06"},
{file = "sqlalchemy-2.0.43-cp313-cp313-win32.whl", hash = "sha256:7f1ac7828857fcedb0361b48b9ac4821469f7694089d15550bbcf9ab22564a1d"}, {file = "sqlalchemy-2.0.39-cp312-cp312-win32.whl", hash = "sha256:7f5243357e6da9a90c56282f64b50d29cba2ee1f745381174caacc50d501b109"},
{file = "sqlalchemy-2.0.43-cp313-cp313-win_amd64.whl", hash = "sha256:971ba928fcde01869361f504fcff3b7143b47d30de188b11c6357c0505824197"}, {file = "sqlalchemy-2.0.39-cp312-cp312-win_amd64.whl", hash = "sha256:2ed107331d188a286611cea9022de0afc437dd2d3c168e368169f27aa0f61338"},
{file = "sqlalchemy-2.0.43-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:4e6aeb2e0932f32950cf56a8b4813cb15ff792fc0c9b3752eaf067cfe298496a"}, {file = "sqlalchemy-2.0.39-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:fe193d3ae297c423e0e567e240b4324d6b6c280a048e64c77a3ea6886cc2aa87"},
{file = "sqlalchemy-2.0.43-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:61f964a05356f4bca4112e6334ed7c208174511bd56e6b8fc86dad4d024d4185"}, {file = "sqlalchemy-2.0.39-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:79f4f502125a41b1b3b34449e747a6abfd52a709d539ea7769101696bdca6716"},
{file = "sqlalchemy-2.0.43-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:46293c39252f93ea0910aababa8752ad628bcce3a10d3f260648dd472256983f"}, {file = "sqlalchemy-2.0.39-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8a10ca7f8a1ea0fd5630f02feb055b0f5cdfcd07bb3715fc1b6f8cb72bf114e4"},
{file = "sqlalchemy-2.0.43-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:136063a68644eca9339d02e6693932116f6a8591ac013b0014479a1de664e40a"}, {file = "sqlalchemy-2.0.39-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e6b0a1c7ed54a5361aaebb910c1fa864bae34273662bb4ff788a527eafd6e14d"},
{file = "sqlalchemy-2.0.43-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:6e2bf13d9256398d037fef09fd8bf9b0bf77876e22647d10761d35593b9ac547"}, {file = "sqlalchemy-2.0.39-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:52607d0ebea43cf214e2ee84a6a76bc774176f97c5a774ce33277514875a718e"},
{file = "sqlalchemy-2.0.43-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:44337823462291f17f994d64282a71c51d738fc9ef561bf265f1d0fd9116a782"}, {file = "sqlalchemy-2.0.39-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:c08a972cbac2a14810463aec3a47ff218bb00c1a607e6689b531a7c589c50723"},
{file = "sqlalchemy-2.0.43-cp38-cp38-win32.whl", hash = "sha256:13194276e69bb2af56198fef7909d48fd34820de01d9c92711a5fa45497cc7ed"}, {file = "sqlalchemy-2.0.39-cp313-cp313-win32.whl", hash = "sha256:23c5aa33c01bd898f879db158537d7e7568b503b15aad60ea0c8da8109adf3e7"},
{file = "sqlalchemy-2.0.43-cp38-cp38-win_amd64.whl", hash = "sha256:334f41fa28de9f9be4b78445e68530da3c5fa054c907176460c81494f4ae1f5e"}, {file = "sqlalchemy-2.0.39-cp313-cp313-win_amd64.whl", hash = "sha256:4dabd775fd66cf17f31f8625fc0e4cfc5765f7982f94dc09b9e5868182cb71c0"},
{file = "sqlalchemy-2.0.43-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ceb5c832cc30663aeaf5e39657712f4c4241ad1f638d487ef7216258f6d41fe7"}, {file = "sqlalchemy-2.0.39-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:2600a50d590c22d99c424c394236899ba72f849a02b10e65b4c70149606408b5"},
{file = "sqlalchemy-2.0.43-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:11f43c39b4b2ec755573952bbcc58d976779d482f6f832d7f33a8d869ae891bf"}, {file = "sqlalchemy-2.0.39-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4eff9c270afd23e2746e921e80182872058a7a592017b2713f33f96cc5f82e32"},
{file = "sqlalchemy-2.0.43-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:413391b2239db55be14fa4223034d7e13325a1812c8396ecd4f2c08696d5ccad"}, {file = "sqlalchemy-2.0.39-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2d7332868ce891eda48896131991f7f2be572d65b41a4050957242f8e935d5d7"},
{file = "sqlalchemy-2.0.43-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c379e37b08c6c527181a397212346be39319fb64323741d23e46abd97a400d34"}, {file = "sqlalchemy-2.0.39-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:125a7763b263218a80759ad9ae2f3610aaf2c2fbbd78fff088d584edf81f3782"},
{file = "sqlalchemy-2.0.43-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:03d73ab2a37d9e40dec4984d1813d7878e01dbdc742448d44a7341b7a9f408c7"}, {file = "sqlalchemy-2.0.39-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:04545042969833cb92e13b0a3019549d284fd2423f318b6ba10e7aa687690a3c"},
{file = "sqlalchemy-2.0.43-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:8cee08f15d9e238ede42e9bbc1d6e7158d0ca4f176e4eab21f88ac819ae3bd7b"}, {file = "sqlalchemy-2.0.39-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:805cb481474e111ee3687c9047c5f3286e62496f09c0e82e8853338aaaa348f8"},
{file = "sqlalchemy-2.0.43-cp39-cp39-win32.whl", hash = "sha256:b3edaec7e8b6dc5cd94523c6df4f294014df67097c8217a89929c99975811414"}, {file = "sqlalchemy-2.0.39-cp39-cp39-win32.whl", hash = "sha256:34d5c49f18778a3665d707e6286545a30339ad545950773d43977e504815fa70"},
{file = "sqlalchemy-2.0.43-cp39-cp39-win_amd64.whl", hash = "sha256:227119ce0a89e762ecd882dc661e0aa677a690c914e358f0dd8932a2e8b2765b"}, {file = "sqlalchemy-2.0.39-cp39-cp39-win_amd64.whl", hash = "sha256:35e72518615aa5384ef4fae828e3af1b43102458b74a8c481f69af8abf7e802a"},
{file = "sqlalchemy-2.0.43-py3-none-any.whl", hash = "sha256:1681c21dd2ccee222c2fe0bef671d1aef7c504087c9c4e800371cfcc8ac966fc"}, {file = "sqlalchemy-2.0.39-py3-none-any.whl", hash = "sha256:a1c6b0a5e3e326a466d809b651c63f278b1256146a377a528b6938a279da334f"},
{file = "sqlalchemy-2.0.43.tar.gz", hash = "sha256:788bfcef6787a7764169cfe9859fe425bf44559619e1d9f56f5bddf2ebf6f417"}, {file = "sqlalchemy-2.0.39.tar.gz", hash = "sha256:5d2d1fe548def3267b4c70a8568f108d1fed7cbbeccb9cc166e05af2abc25c22"},
] ]
[package.dependencies] [package.dependencies]
aiomysql = {version = ">=0.2.0", optional = true, markers = "extra == \"aiomysql\""} aiomysql = {version = ">=0.2.0", optional = true, markers = "extra == \"aiomysql\""}
greenlet = {version = ">=1", optional = true, markers = "python_version < \"3.14\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\") or extra == \"aiomysql\""} greenlet = {version = "!=0.4.17", optional = true, markers = "python_version < \"3.14\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\") or extra == \"aiomysql\""}
pymysql = {version = "*", optional = true, markers = "extra == \"pymysql\""} pymysql = {version = "*", optional = true, markers = "extra == \"pymysql\""}
typing-extensions = ">=4.6.0" typing-extensions = ">=4.6.0"
[package.extras] [package.extras]
aiomysql = ["aiomysql (>=0.2.0)", "greenlet (>=1)"] aiomysql = ["aiomysql (>=0.2.0)", "greenlet (!=0.4.17)"]
aioodbc = ["aioodbc", "greenlet (>=1)"] aioodbc = ["aioodbc", "greenlet (!=0.4.17)"]
aiosqlite = ["aiosqlite", "greenlet (>=1)", "typing_extensions (!=3.10.0.1)"] aiosqlite = ["aiosqlite", "greenlet (!=0.4.17)", "typing_extensions (!=3.10.0.1)"]
asyncio = ["greenlet (>=1)"] asyncio = ["greenlet (!=0.4.17)"]
asyncmy = ["asyncmy (>=0.2.3,!=0.2.4,!=0.2.6)", "greenlet (>=1)"] asyncmy = ["asyncmy (>=0.2.3,!=0.2.4,!=0.2.6)", "greenlet (!=0.4.17)"]
mariadb-connector = ["mariadb (>=1.0.1,!=1.1.2,!=1.1.5,!=1.1.10)"] mariadb-connector = ["mariadb (>=1.0.1,!=1.1.2,!=1.1.5,!=1.1.10)"]
mssql = ["pyodbc"] mssql = ["pyodbc"]
mssql-pymssql = ["pymssql"] mssql-pymssql = ["pymssql"]
@@ -1522,7 +1503,7 @@ mysql-connector = ["mysql-connector-python"]
oracle = ["cx_oracle (>=8)"] oracle = ["cx_oracle (>=8)"]
oracle-oracledb = ["oracledb (>=1.0.1)"] oracle-oracledb = ["oracledb (>=1.0.1)"]
postgresql = ["psycopg2 (>=2.7)"] postgresql = ["psycopg2 (>=2.7)"]
postgresql-asyncpg = ["asyncpg", "greenlet (>=1)"] postgresql-asyncpg = ["asyncpg", "greenlet (!=0.4.17)"]
postgresql-pg8000 = ["pg8000 (>=1.29.1)"] postgresql-pg8000 = ["pg8000 (>=1.29.1)"]
postgresql-psycopg = ["psycopg (>=3.0.7)"] postgresql-psycopg = ["psycopg (>=3.0.7)"]
postgresql-psycopg2binary = ["psycopg2-binary"] postgresql-psycopg2binary = ["psycopg2-binary"]
@@ -1952,4 +1933,4 @@ propcache = ">=0.2.0"
[metadata] [metadata]
lock-version = "2.1" lock-version = "2.1"
python-versions = ">=3.11,<4.0" python-versions = ">=3.11,<4.0"
content-hash = "0ac41110571b3bba38672fceef1c107864b8582378c6afba6418e05f99a75da1" content-hash = "5ed129fde2c5d7b3518fbb2fe2ce79f0bad2aa1060304d45a7bc26d35f7ab46b"

View File

@@ -1,8 +1,10 @@
[project] [project]
name = "api" name = "api"
version = "0.0.5" version = "0.0.3"
description = "" description = ""
authors = [{ name = "Vladislav", email = "vlad.dev@heado.ru" }] authors = [
{name = "Vladislav",email = "vlad.dev@heado.ru"}
]
readme = "README.md" readme = "README.md"
requires-python = ">=3.11,<4.0" requires-python = ">=3.11,<4.0"
dependencies = [ dependencies = [
@@ -17,7 +19,6 @@ dependencies = [
"pydantic[email] (>=2.11.3,<3.0.0)", "pydantic[email] (>=2.11.3,<3.0.0)",
"python-multipart (>=0.0.20,<0.0.21)", "python-multipart (>=0.0.20,<0.0.21)",
"fastapi-jwt-auth @ git+https://github.com/vvpreo/fastapi-jwt-auth", "fastapi-jwt-auth @ git+https://github.com/vvpreo/fastapi-jwt-auth",
"core-library @ git+https://gitea.heado.ru/Vorkout/core.git@0.1.0",
] ]

View File

@@ -1,4 +1,5 @@
VITE_APP_WEBSOCKET_PROTOCOL=ws REACT_APP_WEBSOCKET_PROTOCOL=ws
VITE_APP_HTTP_PROTOCOL=http REACT_APP_HTTP_PROTOCOL=http
VITE_APP_API_URL=localhost:8000 REACT_APP_API_URL=localhost:8000
VITE_APP_URL=localhost:3000 REACT_APP_URL=localhost:3000
BROWSER=none

View File

@@ -1,17 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using Vite" />
<link rel="icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<title>VORKOUT</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

17424
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "client", "name": "client",
"version": "0.0.5", "version": "0.0.2",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@ant-design/icons": "^5.6.1", "@ant-design/icons": "^5.6.1",
@@ -9,6 +9,7 @@
"@testing-library/react": "^16.2.0", "@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2", "@types/jest": "^27.5.2",
"@types/node": "^16.18.126",
"@types/react": "^19.0.11", "@types/react": "^19.0.11",
"@types/react-dom": "^19.0.4", "@types/react-dom": "^19.0.4",
"antd": "^5.24.7", "antd": "^5.24.7",
@@ -20,13 +21,16 @@
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
"react-i18next": "^15.5.1", "react-i18next": "^15.5.1",
"react-router-dom": "^7.5.0", "react-router-dom": "^7.5.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4", "web-vitals": "^2.1.4",
"zustand": "^5.0.5" "zustand": "^5.0.5"
}, },
"scripts": { "scripts": {
"dev": "vite", "start": "react-scripts start",
"build": "vite build", "build": "react-scripts build",
"preview": "vite preview" "test": "react-scripts test",
"eject": "react-scripts eject"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
@@ -45,13 +49,5 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@types/node": "^20.19.1",
"@vitejs/plugin-react": "^4.5.2",
"typescript": "^5.8.3",
"vite": "^6.3.5",
"vite-plugin-node-polyfills": "^0.23.0"
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

43
client/public/index.html Normal file
View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>VORKOUT</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

View File

@@ -1,21 +1,10 @@
/* eslint-disable react-hooks/exhaustive-deps */ import React from 'react';
import React, { useEffect } from 'react';
import { Route, Routes } from 'react-router-dom'; import { Route, Routes } from 'react-router-dom';
import { useSetUserSelector } from './store/userStore';
import LoginPage from './pages/LoginPage';
import ProtectedRoute from './pages/ProtectedRoute';
import MainLayout from './pages/MainLayout'; import MainLayout from './pages/MainLayout';
import ProtectedRoute from './pages/ProtectedRoute';
import LoginPage from './pages/LoginPage';
function App() { function App() {
const setUser = useSetUserSelector();
useEffect(() => {
const storedUser = localStorage.getItem('user');
if (storedUser) {
setUser(JSON.parse(storedUser));
}
}, []);
return ( return (
<div className="App"> <div className="App">
<Routes> <Routes>

View File

@@ -1,13 +1,10 @@
import axios from 'axios'; import axios from 'axios';
import { Access, Auth } from '../types/auth';
import { User } from '../types/user';
import { AuthService } from '../services/auth';
import axiosRetry from 'axios-retry'; import axiosRetry from 'axios-retry';
import { Auth, Tokens } from '@/types/auth';
import { useAuthStore } from '@/store/authStore';
import { AuthService } from '@/services/authService';
import { User, UserCreate, UserUpdate } from '@/types/user';
const baseURL = `${import.meta.env.VITE_APP_HTTP_PROTOCOL}://${ const baseURL = `${process.env.REACT_APP_HTTP_PROTOCOL}://${process.env.REACT_APP_API_URL}/api/v1`;
import.meta.env.VITE_APP_API_URL
}/api/v1`;
const base = axios.create({ const base = axios.create({
baseURL, baseURL,
@@ -18,40 +15,35 @@ const base = axios.create({
}); });
base.interceptors.request.use((config) => { base.interceptors.request.use((config) => {
if (config.url === '/auth/refresh') { const token = localStorage.getItem('accessToken');
return config;
}
const token = useAuthStore.getState().accessToken;
if (token) { if (token) {
config.headers.Authorization = `Bearer ${token}`; config.headers.Authorization = `Bearer ${token}`;
} }
return config; return config;
}); });
axiosRetry(base, { // axiosRetry(base, {
retries: 3, // retries: 3,
retryDelay: (retryCount: number) => { // retryDelay: (retryCount: number) => {
console.log(`retry attempt: ${retryCount}`); // console.log(`retry attempt: ${retryCount}`);
return retryCount * 2000; // return retryCount * 2000;
}, // },
retryCondition: async (error: any) => { // retryCondition: async (error: any) => {
if (error.code === 'ERR_CANCELED') { // if (error.code === 'ERR_CANCELED') {
return true; // return true;
} // }
return false; // return false;
}, // },
}); // });
base.interceptors.response.use( base.interceptors.response.use(
(response) => { (response) => {
return response; return response;
}, },
async function (error) { async function (error) {
if (!error.response) {
return Promise.reject(error);
}
console.log('error', error); console.log('error', error);
const originalRequest = error.response.config; const originalRequest = error.response.config;
console.log('originalRequest._retry', originalRequest);
const urlTokens = error?.request?.responseURL.split('/'); const urlTokens = error?.request?.responseURL.split('/');
const url = urlTokens[urlTokens.length - 1]; const url = urlTokens[urlTokens.length - 1];
console.log('url', url); console.log('url', url);
@@ -63,13 +55,11 @@ base.interceptors.response.use(
url !== 'logout' url !== 'logout'
) { ) {
originalRequest._retry = true; originalRequest._retry = true;
try { const res = await AuthService.refresh().catch(async () => {
await AuthService.refresh();
return base(originalRequest);
} catch (error) {
await AuthService.logout(); await AuthService.logout();
return new Promise(() => {}); });
} console.log('res', res);
return await base(originalRequest);
} }
return await Promise.reject(error); return await Promise.reject(error);
} }
@@ -77,22 +67,14 @@ base.interceptors.response.use(
const api = { const api = {
// auth // auth
async login(auth: Auth): Promise<Tokens> { async login(auth: Auth): Promise<Access> {
const response = await base.post<Tokens>('/auth', auth); console.log(auth);
const response = await base.post<Access>('/auth', auth);
return response.data; return response.data;
}, },
async refreshToken(): Promise<Tokens> { async refreshToken(): Promise<Access> {
const token = localStorage.getItem('refreshToken'); const response = await base.post<Access>('/auth/refresh');
const response = await base.post<Tokens>(
'/auth/refresh',
{},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return response.data; return response.data;
}, },
@@ -101,30 +83,6 @@ const api = {
const response = await base.get<User>('/profile'); const response = await base.get<User>('/profile');
return response.data; return response.data;
}, },
async getUsers(page: number, limit: number): Promise<any> {
const response = await base.get<User[]>(
`/account?page=${page}&limit=${limit}`
);
return response.data;
},
async getUserById(userId: number): Promise<User> {
const response = await base.get<User>(`/account/${userId}`);
return response.data;
},
async createUser(user: UserCreate): Promise<User> {
const response = await base.post<User>('/account', user);
return response.data;
},
async updateUser(userId: number, user: UserUpdate): Promise<User> {
const response = await base.put<User>(`/account/${userId}`, user);
return response.data;
},
// keyrings
}; };
export default api; export default api;

View File

@@ -2,16 +2,12 @@ import { Drawer } from 'antd';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { Avatar, Typography } from 'antd'; import { Avatar, Typography } from 'antd';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useUserSelector } from '@/store/userStore';
interface ContentDrawerProps { interface ContentDrawerProps {
open: boolean; open: boolean;
closeDrawer: () => void; closeDrawer: () => void;
children: React.ReactNode; children: React.ReactNode;
type: 'create' | 'edit'; type: 'create' | 'edit';
login?: string;
name?: string;
email?: string | null;
} }
export default function ContentDrawer({ export default function ContentDrawer({
@@ -19,11 +15,7 @@ export default function ContentDrawer({
closeDrawer, closeDrawer,
children, children,
type, type,
login,
name,
email,
}: ContentDrawerProps) { }: ContentDrawerProps) {
const user = useUserSelector();
const { t } = useTranslation(); const { t } = useTranslation();
const [width, setWidth] = useState<number | string>('30%'); const [width, setWidth] = useState<number | string>('30%');
@@ -38,7 +30,6 @@ export default function ContentDrawer({
window.addEventListener('resize', calculateWidths); window.addEventListener('resize', calculateWidths);
return () => window.removeEventListener('resize', calculateWidths); return () => window.removeEventListener('resize', calculateWidths);
}, []); }, []);
console.log(login, user?.login, login === user?.login);
const editDrawerTitle = ( const editDrawerTitle = (
<div <div
@@ -68,21 +59,16 @@ export default function ContentDrawer({
<div style={{ display: 'flex', alignItems: 'center', gap: 12, flex: 1 }}> <div style={{ display: 'flex', alignItems: 'center', gap: 12, flex: 1 }}>
<Avatar <Avatar
src={ src="https://cdn-icons-png.flaticon.com/512/219/219986.png"
login ? `https://gamma.heado.ru/go/ava?name=${login}` : undefined
}
size={40} size={40}
style={{ flexShrink: 0 }} style={{ flexShrink: 0 }}
/> />
<div> <div>
<Typography.Text <Typography.Text strong style={{ display: 'block' }}>
strong Александр Александров
style={{ display: 'block', fontSize: '20px' }}
>
{name} {login === user?.login ? t('you') : ''}
</Typography.Text> </Typography.Text>
<Typography.Text type="secondary" style={{ fontSize: 14 }}> <Typography.Text type="secondary" style={{ fontSize: 14 }}>
{email} alexandralex@vorkout.ru
</Typography.Text> </Typography.Text>
</div> </div>
</div> </div>
@@ -166,7 +152,7 @@ export default function ContentDrawer({
placement="right" placement="right"
open={open} open={open}
width={width} width={width}
destroyOnHidden={true} destroyOnClose={true}
closable={false} closable={false}
> >
{children} {children}

View File

@@ -1,9 +1,5 @@
import { useUserSelector } from '@/store/userStore';
import { Avatar } from 'antd'; import { Avatar } from 'antd';
import Title from 'antd/es/typography/Title'; import Title from 'antd/es/typography/Title';
import { useState } from 'react';
import ContentDrawer from './ContentDrawer';
import UserEdit from './UserEdit';
interface HeaderProps { interface HeaderProps {
title: string; title: string;
@@ -11,13 +7,6 @@ interface HeaderProps {
} }
export default function Header({ title, additionalContent }: HeaderProps) { export default function Header({ title, additionalContent }: HeaderProps) {
const [openEdit, setOpenEdit] = useState(false);
const showEditDrawer = () => setOpenEdit(true);
const closeEditDrawer = () => {
setOpenEdit(false);
};
const user = useUserSelector();
return ( return (
<div <div
style={{ style={{
@@ -54,24 +43,13 @@ export default function Header({ title, additionalContent }: HeaderProps) {
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}} }}
onClick={showEditDrawer}
> >
<Avatar <Avatar
size={25.77} size={25.77}
src={`https://gamma.heado.ru/go/ava?name=${user?.login}`} src={`https://cdn-icons-png.flaticon.com/512/219/219986.png`}
/> />
</div> </div>
</div> </div>
<ContentDrawer
login={user?.login}
name={user?.name}
email={user?.email}
open={openEdit}
closeDrawer={closeEditDrawer}
type="edit"
>
{user?.id && <UserEdit closeDrawer={closeEditDrawer} userId={user?.id} />}
</ContentDrawer>
</div> </div>
); );
} }

View File

@@ -1,4 +1,3 @@
import { useUserSelector } from '@/store/userStore';
import { Divider, Menu, Tooltip } from 'antd'; import { Divider, Menu, Tooltip } from 'antd';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -14,7 +13,6 @@ export default function SiderMenu({
selectedKey, selectedKey,
hangleMenuClick, hangleMenuClick,
}: SiderMenuProps) { }: SiderMenuProps) {
const user = useUserSelector();
const { t } = useTranslation(); const { t } = useTranslation();
const collapseStyle = collapsed const collapseStyle = collapsed
? { fontSize: '12px' } ? { fontSize: '12px' }
@@ -76,8 +74,7 @@ export default function SiderMenu({
label: t('settings'), label: t('settings'),
className: 'no-expand-icon', className: 'no-expand-icon',
children: [ children: [
user && (user.role === 'OWNER' || user.role === 'ADMIN') {
? {
key: '/accounts', key: '/accounts',
label: !collapsed ? ( label: !collapsed ? (
<Tooltip title={t('accounts')}>{t('accounts')}</Tooltip> <Tooltip title={t('accounts')}>{t('accounts')}</Tooltip>
@@ -85,8 +82,7 @@ export default function SiderMenu({
t('accounts') t('accounts')
), ),
style: collapseStyle, style: collapseStyle,
} },
: undefined,
{ {
key: '/events-list', key: '/events-list',
label: !collapsed ? ( label: !collapsed ? (

View File

@@ -8,19 +8,13 @@ import {
UploadFile, UploadFile,
GetProp, GetProp,
UploadProps, UploadProps,
message, } from 'antd';
Spin, import { useState } from 'react';
} from "antd"; import { useTranslation } from 'react-i18next';
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useUserSelector } from "@/store/userStore";
import { UserCreate as NewUserCreate } from "@/types/user";
import { UserService } from "@/services/userService";
import { LoadingOutlined } from "@ant-design/icons";
const { Option } = Select; const { Option } = Select;
type FileType = Parameters<GetProp<UploadProps, "beforeUpload">>[0]; type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
const getBase64 = (file: FileType): Promise<string> => const getBase64 = (file: FileType): Promise<string> =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
@@ -30,17 +24,10 @@ const getBase64 = (file: FileType): Promise<string> =>
reader.onerror = (error) => reject(error); reader.onerror = (error) => reject(error);
}); });
interface UserCreateProps { export default function UserCreate() {
closeDrawer: () => void;
getUsers: () => Promise<void>;
}
export default function UserCreate({ closeDrawer, getUsers }: UserCreateProps) {
const user = useUserSelector();
const { t } = useTranslation(); const { t } = useTranslation();
const [previewOpen, setPreviewOpen] = useState(false); const [previewOpen, setPreviewOpen] = useState(false);
const [previewImage, setPreviewImage] = useState(""); const [previewImage, setPreviewImage] = useState('');
const [loading, setLoading] = useState(false);
const [fileList, setFileList] = useState<UploadFile[]>([]); const [fileList, setFileList] = useState<UploadFile[]>([]);
@@ -53,49 +40,40 @@ export default function UserCreate({ closeDrawer, getUsers }: UserCreateProps) {
setPreviewOpen(true); setPreviewOpen(true);
}; };
const handleChange: UploadProps["onChange"] = ({ fileList: newFileList }) => const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) =>
setFileList(newFileList); setFileList(newFileList);
const onFinish = async (values: NewUserCreate) => {
setLoading(true);
await UserService.createUser(values);
await getUsers();
closeDrawer();
setLoading(false);
message.info(t("createdAccountMessage"), 4);
};
const customUploadButton = ( const customUploadButton = (
<div> <div>
<div <div
style={{ style={{
height: "102px", height: '102px',
width: "102px", width: '102px',
backgroundColor: "#E2E2E2", backgroundColor: '#E2E2E2',
borderRadius: "50%", borderRadius: '50%',
display: "flex", display: 'flex',
alignItems: "center", alignItems: 'center',
justifyContent: "center", justifyContent: 'center',
marginBottom: 8, marginBottom: 8,
marginTop: 30, marginTop: 30,
cursor: "pointer", cursor: 'pointer',
}} }}
> >
<img <img
src="./icons/drawer/add_photo_alternate.svg" src="./icons/drawer/add_photo_alternate.svg"
alt="add_photo_alternate" alt="add_photo_alternate"
style={{ height: "18px", width: "18px" }} style={{ height: '18px', width: '18px' }}
/> />
</div> </div>
<span style={{ fontSize: "14px", color: "#8c8c8c" }}> <span style={{ fontSize: '14px', color: '#8c8c8c' }}>
{t("selectPhoto")} {t('selectPhoto')}
</span> </span>
</div> </div>
); );
const photoToUpload = ( const photoToUpload = (
<div style={{ height: "102px" }}> <div style={{ height: '102px' }}>
<Upload <Upload
listType="picture-circle" listType="picture-circle"
fileList={fileList} fileList={fileList}
@@ -107,11 +85,11 @@ export default function UserCreate({ closeDrawer, getUsers }: UserCreateProps) {
</Upload> </Upload>
{previewImage && ( {previewImage && (
<Image <Image
wrapperStyle={{ display: "none" }} wrapperStyle={{ display: 'none' }}
preview={{ preview={{
visible: previewOpen, visible: previewOpen,
onVisibleChange: (visible) => setPreviewOpen(visible), onVisibleChange: (visible) => setPreviewOpen(visible),
afterOpenChange: (visible) => !visible && setPreviewImage(""), afterOpenChange: (visible) => !visible && setPreviewImage(''),
}} }}
src={previewImage} src={previewImage}
/> />
@@ -122,24 +100,24 @@ export default function UserCreate({ closeDrawer, getUsers }: UserCreateProps) {
return ( return (
<div <div
style={{ style={{
display: "flex", display: 'flex',
flexDirection: "column", flexDirection: 'column',
height: "100%", height: '100%',
}} }}
> >
<div <div
style={{ style={{
display: "flex", display: 'flex',
alignItems: "center", alignItems: 'center',
justifyContent: "center", justifyContent: 'center',
marginBottom: "36px", marginBottom: '36px',
}} }}
> >
<div <div
style={{ style={{
display: "flex", display: 'flex',
flexDirection: "column", flexDirection: 'column',
alignItems: "center", alignItems: 'center',
}} }}
> >
{photoToUpload} {photoToUpload}
@@ -148,85 +126,83 @@ export default function UserCreate({ closeDrawer, getUsers }: UserCreateProps) {
<Form <Form
name="user-edit-form" name="user-edit-form"
layout="vertical" layout="vertical"
onFinish={onFinish} // onFinish={onFinish}
initialValues={{ initialValues={{
name: "", name: '',
login: "", login: '',
password: "", password: '',
email: "", email: '',
bindTenantId: "", tenant: '',
role: "", role: '',
status: "", status: '',
}} }}
style={{ flex: 1, display: "flex", flexDirection: "column" }} style={{ flex: 1, display: 'flex', flexDirection: 'column' }}
> >
<Form.Item <Form.Item
label={t("name")} label={t('name')}
name="name" name="name"
rules={[{ required: true, message: t("nameMessage") }]} rules={[{ required: true, message: t('nameMessage') }]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("login")} label={t('login')}
name="login" name="login"
rules={[{ required: true, message: t("loginMessage") }]} rules={[{ required: true, message: t('loginMessage') }]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("password")} label={t('password')}
name="password" name="password"
rules={[{ message: t("passwordMessage") }]} rules={[{ required: true, message: t('passwordMessage') }]}
> >
<Input.Password /> <Input.Password />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("email")} label={t('email')}
name="email" name="email"
rules={[ rules={[
{ message: t("emailMessage") }, { required: true, message: t('emailMessage') },
{ type: "email", message: t("emailErrorMessage") }, { type: 'email', message: t('emailErrorMessage') },
]} ]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("tenant")} label={t('tenant')}
name="bindTenantId" name="tenant"
rules={[{ message: t("tenantMessage") }]} rules={[{ required: true, message: t('tenantMessage') }]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("role")} label={t('role')}
name="role" name="role"
rules={[{ required: true, message: t("roleMessage") }]} rules={[{ required: true, message: t('roleMessage') }]}
> >
<Select placeholder={t("roleMessage")}> <Select placeholder={t('roleMessage')}>
{user && user.role === "OWNER" ? ( <Option value="Директор магазина">Директор магазина</Option>
<Option value="ADMIN">{t("ADMIN")}</Option> <Option value="Менеджер">Менеджер</Option>
) : undefined} <Option value="Кассир">Кассир</Option>
<Option value="EDITOR">{t("EDITOR")}</Option>
<Option value="VIEWER">{t("VIEWER")}</Option>
</Select> </Select>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("status")} label={t('status')}
name="status" name="status"
rules={[{ required: true, message: t("statusMessage") }]} rules={[{ required: true, message: t('statusMessage') }]}
> >
<Select placeholder={t("statusMessage")}> <Select placeholder={t('statusMessage')}>
<Option value="ACTIVE">{t("ACTIVE")}</Option> <Option value="ACTIVE">Активен</Option>
<Option value="DISABLED">{t("DISABLED")}</Option> <Option value="DISABLED">Неактивен</Option>
<Option value="BLOCKED">{t("BLOCKED")}</Option> <Option value="BLOCKED">Заблокирован</Option>
<Option value="DELETED">{t("DELETED")}</Option> <Option value="DELETED">Удален</Option>
</Select> </Select>
</Form.Item> </Form.Item>
@@ -237,23 +213,14 @@ export default function UserCreate({ closeDrawer, getUsers }: UserCreateProps) {
type="primary" type="primary"
htmlType="submit" htmlType="submit"
block block
style={{ color: "#000" }} style={{ color: '#000' }}
> >
{loading ? (
<>
<Spin indicator={<LoadingOutlined spin />} size="small"></Spin>{" "}
{t("saving")}
</>
) : (
<>
<img <img
src="/icons/drawer/reg.svg" src="/icons/drawer/reg.svg"
alt="save" alt="save"
style={{ height: "18px", width: "18px" }} style={{ height: '18px', width: '18px' }}
/>{" "} />{' '}
{t("addAccount")} {t('addAccount')}
</>
)}
</Button> </Button>
</Form.Item> </Form.Item>
</Form> </Form>

View File

@@ -1,101 +1,47 @@
import { UserService } from '@/services/userService'; import { Button, Form, Input, Select } from 'antd';
import { useUserSelector } from '@/store/userStore';
import { UserUpdate } from '@/types/user';
import { LoadingOutlined } from '@ant-design/icons';
import { Button, Form, Input, message, Select, Spin } from 'antd';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
const { Option } = Select; const { Option } = Select;
interface UserEditProps { export default function UserEdit() {
userId?: number;
closeDrawer: () => void;
}
export default function UserEdit({ userId, closeDrawer }: UserEditProps) {
const currentUser = useUserSelector();
const [form] = Form.useForm();
const { t } = useTranslation(); const { t } = useTranslation();
const [user, setUser] = useState<UserUpdate>({
id: 0,
name: '',
login: '',
email: '',
password: '',
bindTenantId: '',
role: 'VIEWER',
meta: {},
createdAt: '',
status: 'ACTIVE',
});
const [loading, setLoading] = useState(false);
useEffect(() => {
async function getUser() {
if (typeof userId === 'undefined') {
return;
}
const user = await UserService.getUserById(userId);
setUser(user);
form.setFieldsValue({ ...user });
}
getUser();
}, []);
const onFinish = async (values: UserUpdate) => {
setLoading(true);
let updatedUser: Partial<UserUpdate> = {};
(Object.keys(values) as Array<keyof UserUpdate>).forEach((key) => {
if (values[key] !== user[key]) {
updatedUser = { ...updatedUser, [key]: values[key] };
}
});
if (Object.keys(updatedUser).length > 0) {
console.log('updateUser', userId, updatedUser);
await UserService.updateUser(userId!, updatedUser);
}
setLoading(false);
message.info(t('editAccountMessage'), 4);
closeDrawer();
};
return ( return (
<div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}> <div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
<Form <Form
form={form}
name="user-edit-form" name="user-edit-form"
layout="vertical" layout="vertical"
onFinish={onFinish} // onFinish={onFinish}
initialValues={{ ...user }} initialValues={{
name: 'Александр Александров',
login: 'alexandralex@vorkout.ru',
password: 'jKUUl776GHd',
email: 'alexandralex@vorkout.ru',
tenant: 'text',
role: 'Директор магазина',
status: 'Активен',
}}
style={{ flex: 1, display: 'flex', flexDirection: 'column' }} style={{ flex: 1, display: 'flex', flexDirection: 'column' }}
> >
<Form.Item <Form.Item
label={t('name')} label={t('name')}
name="name" name="name"
rules={[{ message: t('nameMessage') }]} rules={[{ required: true, message: t('nameMessage') }]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
{user?.id === currentUser?.id ? undefined : (
<Form.Item <Form.Item
label={t('login')} label={t('login')}
name="login" name="login"
rules={[{ message: t('loginMessage') }]} rules={[{ required: true, message: t('loginMessage') }]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
)}
<Form.Item <Form.Item
label={t('password')} label={t('password')}
name="password" name="password"
rules={[{ message: t('passwordMessage') }]} rules={[{ required: true, message: t('passwordMessage') }]}
> >
<Input.Password /> <Input.Password />
</Form.Item> </Form.Item>
@@ -113,27 +59,23 @@ export default function UserEdit({ userId, closeDrawer }: UserEditProps) {
<Form.Item <Form.Item
label={t('tenant')} label={t('tenant')}
name="bindTenantId" name="tenant"
rules={[{ required: true, message: t('tenantMessage') }]} rules={[{ required: true, message: t('tenantMessage') }]}
> >
<Input /> <Input />
</Form.Item> </Form.Item>
{user?.id === currentUser?.id ? undefined : (
<Form.Item <Form.Item
label={t('role')} label={t('role')}
name="role" name="role"
rules={[{ required: true, message: t('roleMessage') }]} rules={[{ required: true, message: t('roleMessage') }]}
> >
<Select placeholder={t('roleMessage')}> <Select placeholder={t('roleMessage')}>
{currentUser && currentUser.role === 'OWNER' ? ( <Option value="Директор магазина">Директор магазина</Option>
<Option value="ADMIN">{t('ADMIN')}</Option> <Option value="Менеджер">Менеджер</Option>
) : undefined} <Option value="Кассир">Кассир</Option>
<Option value="EDITOR">{t('EDITOR')}</Option>
<Option value="VIEWER">{t('VIEWER')}</Option>
</Select> </Select>
</Form.Item> </Form.Item>
)}
<Form.Item <Form.Item
label={t('status')} label={t('status')}
@@ -141,10 +83,10 @@ export default function UserEdit({ userId, closeDrawer }: UserEditProps) {
rules={[{ required: true, message: t('statusMessage') }]} rules={[{ required: true, message: t('statusMessage') }]}
> >
<Select placeholder={t('statusMessage')}> <Select placeholder={t('statusMessage')}>
<Option value="ACTIVE">{t('ACTIVE')}</Option> <Option value="ACTIVE">Активен</Option>
<Option value="DISABLED">{t('DISABLED')}</Option> <Option value="DISABLED">Неактивен</Option>
<Option value="BLOCKED">{t('BLOCKED')}</Option> <Option value="BLOCKED">Заблокирован</Option>
<Option value="DELETED">{t('DELETED')}</Option> <Option value="DELETED">Удален</Option>
</Select> </Select>
</Form.Item> </Form.Item>
@@ -157,21 +99,12 @@ export default function UserEdit({ userId, closeDrawer }: UserEditProps) {
block block
style={{ color: '#000' }} style={{ color: '#000' }}
> >
{loading ? (
<>
<Spin indicator={<LoadingOutlined spin />} size="small"></Spin>{' '}
{t('saving')}
</>
) : (
<>
<img <img
src="/icons/drawer/save.svg" src="/icons/drawer/save.svg"
alt="save" alt="save"
style={{ height: '18px', width: '18px' }} style={{ height: '18px', width: '18px' }}
/>{' '} />{' '}
{t('save')} {t('save')}
</>
)}
</Button> </Button>
</Form.Item> </Form.Item>
</Form> </Form>

View File

@@ -1,9 +1,8 @@
import '@/config/i18n'; import './i18n';
import { ConfigProvider } from 'antd'; import { ConfigProvider } from 'antd';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { BrowserRouter } from 'react-router-dom';
import { theme } from '@/config/customTheme'; import { theme } from './customTheme';
import en from 'antd/locale/en_US'; import en from 'antd/locale/en_US';
import ru from 'antd/locale/ru_RU'; import ru from 'antd/locale/ru_RU';
@@ -19,7 +18,7 @@ export default function AppWrapper({ children }: any) {
return ( return (
<ConfigProvider locale={antdLocales[currentLang]} theme={theme}> <ConfigProvider locale={antdLocales[currentLang]} theme={theme}>
<BrowserRouter>{children}</BrowserRouter> {children}
</ConfigProvider> </ConfigProvider>
); );
} }

View File

@@ -37,20 +37,6 @@ i18n
addAccount: 'Add account', addAccount: 'Add account',
save: 'Save changes', save: 'Save changes',
newAccount: 'New account', newAccount: 'New account',
ACTIVE: 'Active',
DISABLED: 'Disabled',
BLOCKED: 'Blocked',
DELETED: 'Deleted',
OWNER: 'Owner',
ADMIN: 'Admin',
EDITOR: 'Editor',
VIEWER: 'Viewer',
nameLogin: 'Name, login',
createdAt: 'Created',
saving: 'Saving...',
createdAccountMessage: 'User successfully created!',
editAccountMessage: 'User successfully updated!',
you: '(You)',
}, },
}, },
ru: { ru: {
@@ -80,20 +66,6 @@ i18n
addAccount: 'Добавить аккаунт', addAccount: 'Добавить аккаунт',
save: 'Сохранить изменения', save: 'Сохранить изменения',
newAccount: 'Новая учетная запись', newAccount: 'Новая учетная запись',
ACTIVE: 'Активен',
DISABLED: 'Выключен',
BLOCKED: 'Заблокирован',
DELETED: 'Удален',
OWNER: 'Владелец',
ADMIN: 'Админ',
EDITOR: 'Редактор',
VIEWER: 'Наблюдатель',
nameLogin: 'Имя, Логин',
createdAt: 'Создано',
saving: 'Сохранение...',
createdAccountMessage: 'Пользователь успешно создан!',
editAccountMessage: 'Пользователь успешно обновлен!',
you: '(Вы)',
}, },
}, },
}, },

12
client/src/env.d.ts vendored
View File

@@ -1,12 +0,0 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_APP_WEBSOCKET_PROTOCOL: string;
readonly VITE_APP_HTTP_PROTOCOL: string;
readonly VITE_APP_API_URL: string;
readonly VITE_APP_URL: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}

View File

@@ -1,8 +1,9 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import '@/index.css'; import './index.css';
import App from '@/App'; import App from './App';
import AppWrapper from '@/config/AppWrapper'; import { BrowserRouter } from 'react-router-dom';
import AppWrapper from './config/AppWrapper';
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById('root') as HTMLElement
@@ -10,6 +11,8 @@ const root = ReactDOM.createRoot(
root.render( root.render(
<AppWrapper> <AppWrapper>
<BrowserRouter>
<App /> <App />
</BrowserRouter>
</AppWrapper> </AppWrapper>
); );

View File

@@ -1,219 +1,36 @@
import { useEffect, useState } from "react"; import Header from '../components/Header';
import { useTranslation } from "react-i18next"; import { useState } from 'react';
import { AccountStatus, AllUser, AllUserResponse } from "@/types/user"; import ContentDrawer from '../components/ContentDrawer';
import Header from "@/components/Header"; import UserCreate from '../components/UserCreate';
import ContentDrawer from "@/components/ContentDrawer"; import { useTranslation } from 'react-i18next';
import UserCreate from "@/components/UserCreate";
import { Avatar, Table } from "antd";
import { TableProps } from "antd/lib";
import { UserService } from "@/services/userService";
import UserEdit from "@/components/UserEdit";
import { useSearchParams } from "react-router-dom";
export default function AccountsPage() { export default function AccountsPage() {
const { t } = useTranslation(); const { t } = useTranslation();
const [openCreate, setOpenCreate] = useState(false); const [open, setOpen] = useState(false);
const [searchParams, setSearchParams] = useSearchParams();
const [activeAccount, setActiveAccount] = useState< const showDrawer = () => setOpen(true);
{ login: string; id: number; name: string; email: string } | undefined const closeDrawer = () => setOpen(false);
>(undefined);
const showCreateDrawer = () => setOpenCreate(true);
const closeCreateDrawer = () => {
setActiveAccount(undefined);
setOpenCreate(false);
};
const [openEdit, setOpenEdit] = useState(false);
const showEditDrawer = () => setOpenEdit(true);
const closeEditDrawer = () => {
setActiveAccount(undefined);
setOpenEdit(false);
};
const [accounts, setAccounts] = useState<AllUserResponse>({
amountCount: 0,
amountPages: 0,
users: [],
currentPage: 1,
limit: 10,
});
async function getUsers() {
const page = Number(searchParams.get("page") || "1");
const limit = Number(searchParams.get("limit") || "10");
setSearchParams({
page: page.toString(),
limit: limit.toString(),
});
const data = await UserService.getUsers(page, limit);
console.log("searchParams", searchParams);
setAccounts(data);
}
useEffect(() => {
getUsers();
}, []);
const statusColor = {
ACTIVE: "#27AE60",
DISABLED: "#606060",
BLOCKED: "#FF0000",
DELETED: "#B30000",
};
const columns: TableProps<AllUser>["columns"] = [
{
title: "#",
dataIndex: "id",
key: "id",
},
{
title: t("nameLogin"),
dataIndex: "nameLogin",
key: "nameLogin",
render: (text, record) => (
<div
onClick={() => {
setActiveAccount({
login: record.login,
id: record.id,
name: record.name,
email: record.email || "",
});
showEditDrawer();
}}
style={{
display: "flex",
alignItems: "center",
gap: "16px",
cursor: "pointer",
}}
>
<div
style={{
height: "32px",
width: "32px",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<Avatar
size={32}
src={`https://gamma.heado.ru/go/ava?name=${record.login}`}
/>
</div>
<div style={{ display: "flex", flexDirection: "column" }}>
<div>{record.name}</div>
<div style={{ color: "#606060" }}>{record.login}</div>
</div>
</div>
),
},
{
title: "E-mail",
dataIndex: "email",
key: "email",
},
{
title: t("tenant"),
dataIndex: "bindTenantId",
key: "tenant",
},
{
title: t("role"),
dataIndex: "role",
key: "role",
render: (text) => <div>{t(text)}</div>,
},
{
title: t("createdAt"),
dataIndex: "createdAt",
key: "createdAt",
render: (text) => (
<div>
{new Date(text).toLocaleString("ru", {
year: "2-digit",
month: "2-digit",
day: "2-digit",
})}
</div>
),
},
{
title: t("status"),
dataIndex: "status",
key: "status",
render: (text) => (
<div style={{ color: statusColor[text as AccountStatus] }}>
{t(text)}
</div>
),
},
];
const onTableChange: TableProps<AllUser>["onChange"] = (pagination) => {
console.log(pagination);
UserService.getUsers(
pagination.current as number,
pagination.pageSize
).then((data) => {
setAccounts(data);
setSearchParams({
page: data.currentPage.toString(),
limit: data.limit.toString(),
});
});
};
return ( return (
<> <>
<Header <Header
title={t("accounts")} title={t('accounts')}
additionalContent={ additionalContent={
<img <img
src="./icons/header/add_2.svg" src="./icons/header/add_2.svg"
alt="add" alt="add"
style={{ style={{
height: "18px", height: '18px',
width: "18px", width: '18px',
cursor: "pointer", cursor: 'pointer',
}} }}
onClick={showCreateDrawer} onClick={showDrawer}
/> />
} }
/> />
<Table
size="small"
onChange={onTableChange}
columns={columns}
dataSource={accounts.users}
pagination={{
pageSize: accounts.limit,
current: accounts.currentPage,
total: accounts.amountCount,
}}
rowKey={"id"}
/>
<ContentDrawer <ContentDrawer open={open} closeDrawer={closeDrawer} type="create">
open={openCreate} <UserCreate />
closeDrawer={closeCreateDrawer}
type="create"
>
<UserCreate getUsers={getUsers} closeDrawer={closeCreateDrawer} />
</ContentDrawer>
<ContentDrawer
login={activeAccount?.login}
name={activeAccount?.name}
email={activeAccount?.email}
open={openEdit}
closeDrawer={closeEditDrawer}
type="edit"
>
<UserEdit userId={activeAccount?.id} closeDrawer={closeEditDrawer} />
</ContentDrawer> </ContentDrawer>
</> </>
); );

View File

@@ -1,5 +1,5 @@
import Header from '@/components/Header';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import Header from '../components/Header';
export default function ConfigurationPage() { export default function ConfigurationPage() {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@@ -1,5 +1,5 @@
import Header from '@/components/Header';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import Header from '../components/Header';
export default function EventsListPage() { export default function EventsListPage() {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@@ -1,13 +1,13 @@
import React from 'react'; import React from 'react';
import { Form, Input, Button, Typography, message } from 'antd'; import { Form, Input, Button, Typography } from 'antd';
import { import {
EyeInvisibleOutlined, EyeInvisibleOutlined,
EyeTwoTone, EyeTwoTone,
UserOutlined, UserOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { AuthService } from '../services/auth';
import { Auth } from '../types/auth';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { AuthService } from '@/services/authService';
import { Auth } from '@/types/auth';
const { Text, Link } = Typography; const { Text, Link } = Typography;
@@ -45,11 +45,7 @@ export default function LoginPage() {
/> />
</div> </div>
<Form <Form name="login" onFinish={onFinish} layout="vertical">
name="login"
onFinish={onFinish}
layout="vertical"
>
<Form.Item <Form.Item
name="login" name="login"
rules={[{ required: true, message: 'Введите login' }]} rules={[{ required: true, message: 'Введите login' }]}

View File

@@ -2,13 +2,15 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Layout } from 'antd'; import { Layout } from 'antd';
import Sider from 'antd/es/layout/Sider'; import Sider from 'antd/es/layout/Sider';
import SiderMenu from '../components/SiderMenu';
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom'; import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import SiderMenu from '@/components/SiderMenu';
import ProcessDiagramPage from './ProcessDiagramPage'; import ProcessDiagramPage from './ProcessDiagramPage';
import RunningProcessesPage from './RunningProcessesPage'; import RunningProcessesPage from './RunningProcessesPage';
import AccountsPage from './AccountsPage'; import AccountsPage from './AccountsPage';
import EventsListPage from './EventsListPage'; import EventsListPage from './EventsListPage';
import ConfigurationPage from './ConfigurationPage'; import ConfigurationPage from './ConfigurationPage';
import { useSetUserSelector } from '../store/user';
import { UserService } from '../services/user';
export default function MainLayout() { export default function MainLayout() {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -19,6 +21,8 @@ export default function MainLayout() {
const [width, setWidth] = useState<number | string>('15%'); const [width, setWidth] = useState<number | string>('15%');
const [collapsedWidth, setCollapsedWidth] = useState(50); const [collapsedWidth, setCollapsedWidth] = useState(50);
const setUser = useSetUserSelector()
const calculateWidths = () => { const calculateWidths = () => {
const windowWidth = window.innerWidth; const windowWidth = window.innerWidth;
const expanded = Math.min(Math.max(windowWidth * 0.15, 180), 240); const expanded = Math.min(Math.max(windowWidth * 0.15, 180), 240);
@@ -54,6 +58,21 @@ export default function MainLayout() {
navigate(key); navigate(key);
} }
useEffect(() => {
const token = localStorage.getItem('accessToken');
if (!token) {
navigate('/login');
} else {
if (localStorage.getItem('user')) {
setUser(JSON.parse(localStorage.getItem('user') as string))
} else {
UserService.getProfile().then((user) => {
setUser(user);
});
}
}
}, [])
return ( return (
<Layout style={{ minHeight: '100vh' }}> <Layout style={{ minHeight: '100vh' }}>
<Sider <Sider

View File

@@ -1,5 +1,5 @@
import Header from '@/components/Header';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import Header from '../components/Header';
export default function ProcessDiagramPage() { export default function ProcessDiagramPage() {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@@ -1,14 +1,15 @@
/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable react-hooks/exhaustive-deps */
// ProtectedRoute.js
import { Outlet, useNavigate } from 'react-router-dom'; import { Outlet, useNavigate } from 'react-router-dom';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { useUserSelector } from '@/store/userStore'; import { useUserSelector } from '../store/user';
const ProtectedRoute = (): React.JSX.Element => { const ProtectedRoute = (): React.JSX.Element => {
const navigate = useNavigate();
const user = useUserSelector(); const user = useUserSelector();
const navigate = useNavigate();
useEffect(() => { useEffect(() => {
if (!user?.id) { if (user.id === null) {
navigate('/login'); navigate('/login');
} }
}, [user]); }, [user]);

View File

@@ -1,5 +1,5 @@
import Header from '@/components/Header';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import Header from '../components/Header';
export default function RunningProcessesPage() { export default function RunningProcessesPage() {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@@ -0,0 +1,22 @@
import api from '../api/api';
import { useUserStore } from '../store/user';
import { Auth } from '../types/auth';
export class AuthService {
static async login(auth: Auth) {
const token = await api.login(auth);
console.log(token)
localStorage.setItem('accessToken', token.accessToken);
}
static async logout() {
useUserStore.getState().removeUser();
localStorage.removeItem('userInfo');
localStorage.removeItem('accessToken');
}
static async refresh() {
const token = await api.refreshToken();
localStorage.setItem('accessToken', token.accessToken);
}
}

View File

@@ -1,30 +0,0 @@
import api from "@/api/api";
import { useAuthStore } from "@/store/authStore";
import { Auth } from "@/types/auth";
import { UserService } from "./userService";
import { useUserStore } from "@/store/userStore";
export class AuthService {
static async login(auth: Auth) {
const token = await api.login(auth);
useAuthStore.getState().setAccessToken(token.accessToken);
localStorage.setItem('refreshToken', token.refreshToken as string);
await UserService.getProfile().then((user) => {
useUserStore.getState().setUser(user);
});
}
static async logout() {
console.log('logout');
useUserStore.getState().setUser(null);
useAuthStore.getState().setAccessToken(null);
localStorage.removeItem('userInfo');
localStorage.removeItem('refreshToken');
}
static async refresh() {
console.log('refresh');
const token = await api.refreshToken();
useAuthStore.getState().setAccessToken(token.accessToken);
}
}

View File

@@ -0,0 +1,10 @@
import api from '../api/api';
import { User } from '../types/user';
export class UserService {
static async getProfile(): Promise<User> {
const user = api.getProfile();
return user;
}
}

View File

@@ -1,38 +0,0 @@
import api from '@/api/api';
import { AllUserResponse, User, UserCreate, UserUpdate } from '@/types/user';
export class UserService {
static async getProfile(): Promise<User> {
console.log('getProfile');
const user = api.getProfile();
return user;
}
static async getUsers(
page: number = 1,
limit: number = 10
): Promise<AllUserResponse> {
console.log('getUsers');
const allUsers = api.getUsers(page, limit);
return allUsers;
}
static async getUserById(userId: number): Promise<User> {
console.log('getUserById');
const user = api.getUserById(userId);
return user;
}
static async createUser(user: UserCreate): Promise<User> {
console.log('createUser');
const createdUser = api.createUser(user);
return createdUser;
}
static async updateUser(userId: number, user: UserUpdate): Promise<User> {
console.log('updateUser');
const updatedUser = api.updateUser(userId, user);
return updatedUser;
}
}

View File

@@ -1,18 +0,0 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
type AuthState = {
accessToken: string | null;
setAccessToken: (token: string | null) => void;
};
export const useAuthStore = create<AuthState>()(
devtools((set) => ({
accessToken: null,
setAccessToken: (token) => set({ accessToken: token }),
}))
);
export const useAuthSelector = () => {
return useAuthStore((state) => state.accessToken);
};

View File

@@ -1,16 +1,17 @@
import { User } from '@/types/user';
import { create } from 'zustand'; import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware'; import { devtools, persist } from 'zustand/middleware';
import { User } from '../types/user';
const userInfo = localStorage.getItem('userInfo'); const userInfo = localStorage.getItem('userInfo');
type UserStoreState = { type UserStoreState = {
user: User | null; user: User;
loading: boolean; loading: boolean;
}; };
type UserStoreActions = { type UserStoreActions = {
setUser: (user: User | null) => void; setUser: (user: User) => void;
removeUser: () => void;
}; };
type UserStore = UserStoreState & UserStoreActions; type UserStore = UserStoreState & UserStoreActions;
@@ -21,7 +22,8 @@ export const useUserStore = create<UserStore>()(
(set, get) => ({ (set, get) => ({
user: userInfo != null ? JSON.parse(userInfo) : ({} as User), user: userInfo != null ? JSON.parse(userInfo) : ({} as User),
loading: false, loading: false,
setUser: (user: User | null) => set({ user }), setUser: (user: User) => set({ user }),
removeUser: () => set({ user: {} as User }),
}), }),
{ name: 'userInfo' } { name: 'userInfo' }
) )

View File

@@ -1,4 +1,4 @@
import { components } from './openapi-types'; import { components } from './openapi-types';
export type Auth = components['schemas']['Auth']; export type Auth = components['schemas']['Auth'];
export type Tokens = components['schemas']['Tokens']; export type Access = components['schemas']['Access'];

View File

@@ -120,6 +120,11 @@ export interface paths {
export type webhooks = Record<string, never>; export type webhooks = Record<string, never>;
export interface components { export interface components {
schemas: { schemas: {
/** Access */
Access: {
/** Accesstoken */
accessToken: string;
};
/** AccountKeyring */ /** AccountKeyring */
AccountKeyring: { AccountKeyring: {
/** Ownerid */ /** Ownerid */
@@ -191,10 +196,6 @@ export interface components {
amountCount: number; amountCount: number;
/** Amountpages */ /** Amountpages */
amountPages: number; amountPages: number;
/** Currentpage */
currentPage: number;
/** Limit */
limit: number;
}; };
/** Auth */ /** Auth */
Auth: { Auth: {
@@ -218,13 +219,6 @@ export interface components {
* @enum {string} * @enum {string}
*/ */
KeyType: "PASSWORD" | "ACCESS_TOKEN" | "REFRESH_TOKEN" | "API_KEY"; KeyType: "PASSWORD" | "ACCESS_TOKEN" | "REFRESH_TOKEN" | "API_KEY";
/** Tokens */
Tokens: {
/** Accesstoken */
accessToken: string;
/** Refreshtoken */
refreshToken?: string | null;
};
/** User */ /** User */
User: { User: {
/** Id */ /** Id */
@@ -251,25 +245,6 @@ export interface components {
createdAt: string; createdAt: string;
status: components["schemas"]["AccountStatus"]; status: components["schemas"]["AccountStatus"];
}; };
/** UserCreate */
UserCreate: {
/** Name */
name?: string | null;
/** Login */
login?: string | null;
/** Email */
email?: string | null;
/** Password */
password?: string | null;
/** Bindtenantid */
bindTenantId?: string | null;
role?: components["schemas"]["AccountRole"] | null;
/** Meta */
meta?: {
[key: string]: unknown;
} | null;
status?: components["schemas"]["AccountStatus"] | null;
};
/** UserUpdate */ /** UserUpdate */
UserUpdate: { UserUpdate: {
/** Id */ /** Id */
@@ -280,8 +255,6 @@ export interface components {
login?: string | null; login?: string | null;
/** Email */ /** Email */
email?: string | null; email?: string | null;
/** Password */
password?: string | null;
/** Bindtenantid */ /** Bindtenantid */
bindTenantId?: string | null; bindTenantId?: string | null;
role?: components["schemas"]["AccountRole"] | null; role?: components["schemas"]["AccountRole"] | null;
@@ -332,7 +305,7 @@ export interface operations {
[name: string]: unknown; [name: string]: unknown;
}; };
content: { content: {
"application/json": components["schemas"]["Tokens"]; "application/json": components["schemas"]["Access"];
}; };
}; };
/** @description Validation Error */ /** @description Validation Error */
@@ -361,7 +334,7 @@ export interface operations {
[name: string]: unknown; [name: string]: unknown;
}; };
content: { content: {
"application/json": components["schemas"]["Tokens"]; "application/json": components["schemas"]["Access"];
}; };
}; };
}; };
@@ -460,7 +433,7 @@ export interface operations {
}; };
requestBody: { requestBody: {
content: { content: {
"application/json": components["schemas"]["UserCreate"]; "application/json": components["schemas"]["UserUpdate"];
}; };
}; };
responses: { responses: {
@@ -470,7 +443,7 @@ export interface operations {
[name: string]: unknown; [name: string]: unknown;
}; };
content: { content: {
"application/json": components["schemas"]["AllUser"]; "application/json": components["schemas"]["User"];
}; };
}; };
/** @description Validation Error */ /** @description Validation Error */
@@ -501,7 +474,7 @@ export interface operations {
[name: string]: unknown; [name: string]: unknown;
}; };
content: { content: {
"application/json": components["schemas"]["UserUpdate"]; "application/json": components["schemas"]["User"];
}; };
}; };
/** @description Validation Error */ /** @description Validation Error */
@@ -536,7 +509,7 @@ export interface operations {
[name: string]: unknown; [name: string]: unknown;
}; };
content: { content: {
"application/json": components["schemas"]["UserUpdate"]; "application/json": components["schemas"]["User"];
}; };
}; };
/** @description Validation Error */ /** @description Validation Error */

View File

@@ -1,9 +1,3 @@
import { components } from './openapi-types'; import { components } from "./openapi-types"
export type User = components['schemas']['User']; export type User = components["schemas"]["User"];
export type AllUserResponse = components['schemas']['AllUserResponse'];
export type AllUser = components['schemas']['AllUser'];
export type AccountStatus = components['schemas']['AccountStatus'];
export type AccountRole = components['schemas']['AccountRole'];
export type UserUpdate = components['schemas']['UserUpdate'];
export type UserCreate = components['schemas']['UserCreate'];

View File

@@ -1,7 +1,11 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": ["dom", "dom.iterable", "esnext"], "lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "esModuleInterop": true,
@@ -14,11 +18,9 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "react-jsx", "jsx": "react-jsx"
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}, },
"include": ["src"] "include": [
"src"
]
} }

View File

@@ -1,23 +0,0 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
open: false,
},
build: {
outDir: 'build',
},
preview: {
port: 3000,
open: false,
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
});

6
package-lock.json generated Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "connect",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}

1
package.json Normal file
View File

@@ -0,0 +1 @@
{}

View File

@@ -32,11 +32,11 @@ startretries=5
[program:client] [program:client]
environment= environment=
VITE_APP_WEBSOCKET_PROTOCOL=ws, REACT_APP_WEBSOCKET_PROTOCOL=ws,
VITE_APP_HTTP_PROTOCOL=http, REACT_APP_HTTP_PROTOCOL=http,
VITE_APP_API_URL=localhost:8000, REACT_APP_API_URL=localhost:8000,
VITE_APP_URL=localhost:3000 REACT_APP_URL=localhost:3000
command=bash -c 'cd client; npm run build; npm run preview' command=bash -c 'cd client; npm run build; serve -s build'
numprocs=1 numprocs=1
process_name=node-%(process_num)d process_name=node-%(process_num)d
stdout_logfile=client.out.log stdout_logfile=client.out.log