From 1702945fcdba426ddd920e28502dafa3fe40a537 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 16 Jul 2025 14:59:43 +0800 Subject: [PATCH] feat: Change user weight api --- backend/apps/system/api/workspace.py | 16 +++++++++++++++- backend/apps/system/schemas/system_schema.py | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/apps/system/api/workspace.py b/backend/apps/system/api/workspace.py index 8ef6866b..ecedcca0 100644 --- a/backend/apps/system/api/workspace.py +++ b/backend/apps/system/api/workspace.py @@ -3,7 +3,7 @@ from fastapi import APIRouter, Query from sqlmodel import exists, or_, select from apps.system.models.system_model import UserWsModel, WorkspaceBase, WorkspaceEditor, WorkspaceModel from apps.system.models.user import UserModel -from apps.system.schemas.system_schema import UserWsBase, UserWsDTO, UserWsOption, WorkspaceUser +from apps.system.schemas.system_schema import UserWsBase, UserWsDTO, UserWsEditor, UserWsOption, WorkspaceUser from common.core.deps import CurrentUser, SessionDep, Trans from common.core.pagination import Paginator from common.core.schemas import PaginatedResponse, PaginationParams @@ -118,6 +118,20 @@ async def create(session: SessionDep, creator: UserWsDTO): session.add_all(db_model_list) session.commit() +@router.put("/uws") +async def edit(session: SessionDep, editor: UserWsEditor): + if not editor.oid or not editor.uid: + raise RuntimeError("param [oid, uid] miss") + db_model = session.exec(select(UserWsModel).where(UserWsModel.uid.in_(editor.uid), UserWsModel.oid == editor.oid)).first() + if not db_model: + raise RuntimeError("uws not exist") + if editor.weight == db_model.weight: + return + + db_model.weight = editor.weight + session.add(db_model) + session.commit() + @router.delete("/uws") async def delete(session: SessionDep, dto: UserWsBase): db_model_list: list[UserWsModel] = session.exec(select(UserWsModel).where(UserWsModel.uid.in_(dto.uid_list), UserWsModel.oid == dto.oid)).all() diff --git a/backend/apps/system/schemas/system_schema.py b/backend/apps/system/schemas/system_schema.py index 9ca08457..8b1f3b99 100644 --- a/backend/apps/system/schemas/system_schema.py +++ b/backend/apps/system/schemas/system_schema.py @@ -50,7 +50,11 @@ class UserWsBase(BaseModel): oid: int class UserWsDTO(UserWsBase): weight: int = 0 - + +class UserWsEditor(BaseModel): + uid: int + oid: int + weight: int = 0 class UserInfoDTO(UserEditor): language: str = "zh-CN"