Skip to content

Commit 1702945

Browse files
feat: Change user weight api
1 parent cac8dc8 commit 1702945

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

backend/apps/system/api/workspace.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlmodel import exists, or_, select
44
from apps.system.models.system_model import UserWsModel, WorkspaceBase, WorkspaceEditor, WorkspaceModel
55
from apps.system.models.user import UserModel
6-
from apps.system.schemas.system_schema import UserWsBase, UserWsDTO, UserWsOption, WorkspaceUser
6+
from apps.system.schemas.system_schema import UserWsBase, UserWsDTO, UserWsEditor, UserWsOption, WorkspaceUser
77
from common.core.deps import CurrentUser, SessionDep, Trans
88
from common.core.pagination import Paginator
99
from common.core.schemas import PaginatedResponse, PaginationParams
@@ -118,6 +118,20 @@ async def create(session: SessionDep, creator: UserWsDTO):
118118
session.add_all(db_model_list)
119119
session.commit()
120120

121+
@router.put("/uws")
122+
async def edit(session: SessionDep, editor: UserWsEditor):
123+
if not editor.oid or not editor.uid:
124+
raise RuntimeError("param [oid, uid] miss")
125+
db_model = session.exec(select(UserWsModel).where(UserWsModel.uid.in_(editor.uid), UserWsModel.oid == editor.oid)).first()
126+
if not db_model:
127+
raise RuntimeError("uws not exist")
128+
if editor.weight == db_model.weight:
129+
return
130+
131+
db_model.weight = editor.weight
132+
session.add(db_model)
133+
session.commit()
134+
121135
@router.delete("/uws")
122136
async def delete(session: SessionDep, dto: UserWsBase):
123137
db_model_list: list[UserWsModel] = session.exec(select(UserWsModel).where(UserWsModel.uid.in_(dto.uid_list), UserWsModel.oid == dto.oid)).all()

backend/apps/system/schemas/system_schema.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ class UserWsBase(BaseModel):
5050
oid: int
5151
class UserWsDTO(UserWsBase):
5252
weight: int = 0
53-
53+
54+
class UserWsEditor(BaseModel):
55+
uid: int
56+
oid: int
57+
weight: int = 0
5458

5559
class UserInfoDTO(UserEditor):
5660
language: str = "zh-CN"

0 commit comments

Comments
 (0)