feat: 添加排序相关API
This commit is contained in:
@@ -70,6 +70,16 @@ async def delete_queue(queue: QueueDeleteIn = Body(...)) -> OutBase:
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post("/order", summary="重新排序", response_model=OutBase, status_code=200)
|
||||
async def reorder_queue(script: QueueReorderIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.reorder_queue(script.indexList)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/time/add", summary="添加定时项", response_model=TimeSetCreateOut, status_code=200
|
||||
)
|
||||
@@ -103,6 +113,18 @@ async def delete_time_set(time: TimeSetDeleteIn = Body(...)) -> OutBase:
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/time/order", summary="重新排序时间设置", response_model=OutBase, status_code=200
|
||||
)
|
||||
async def reorder_time_set(time: TimeSetReorderIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.reorder_time_set(time.queueId, time.indexList)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/item/add",
|
||||
summary="添加队列项",
|
||||
@@ -137,3 +159,15 @@ async def delete_item(item: QueueItemDeleteIn = Body(...)) -> OutBase:
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/item/order", summary="重新排序队列项", response_model=OutBase, status_code=200
|
||||
)
|
||||
async def reorder_item(item: QueueItemReorderIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.reorder_queue_item(item.queueId, item.indexList)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
@@ -70,6 +70,16 @@ async def delete_script(script: ScriptDeleteIn = Body(...)) -> OutBase:
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post("/order", summary="重新排序脚本", response_model=OutBase, status_code=200)
|
||||
async def reorder_script(script: ScriptReorderIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.reorder_script(script.indexList)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/user/add", summary="添加用户", response_model=UserCreateOut, status_code=200
|
||||
)
|
||||
@@ -101,3 +111,15 @@ async def delete_user(user: UserDeleteIn = Body(...)) -> OutBase:
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/user/order", summary="重新排序用户", response_model=OutBase, status_code=200
|
||||
)
|
||||
async def reorder_user(user: UserReorderIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.reorder_user(user.scriptId, user.indexList)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
@@ -653,6 +653,13 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
await self.ScriptConfig.remove(uuid.UUID(script_id))
|
||||
|
||||
async def reorder_script(self, index_list: list[str]) -> None:
|
||||
"""重新排序脚本"""
|
||||
|
||||
self.logger.info(f"重新排序脚本:{index_list}")
|
||||
|
||||
await self.ScriptConfig.setOrder([uuid.UUID(_) for _ in index_list])
|
||||
|
||||
async def add_user(self, script_id: str) -> tuple[uuid.UUID, ConfigBase]:
|
||||
"""添加用户配置"""
|
||||
|
||||
@@ -702,6 +709,17 @@ class AppConfig(GlobalConfig):
|
||||
await script_config.UserData.remove(uid)
|
||||
await self.ScriptConfig.save()
|
||||
|
||||
async def reorder_user(self, script_id: str, index_list: list[str]) -> None:
|
||||
"""重新排序用户"""
|
||||
|
||||
self.logger.info(f"{script_id} 重新排序用户:{index_list}")
|
||||
|
||||
script_config = self.ScriptConfig[uuid.UUID(script_id)]
|
||||
|
||||
if isinstance(script_config, (MaaConfig | GeneralConfig)):
|
||||
await script_config.UserData.setOrder([uuid.UUID(_) for _ in index_list])
|
||||
await self.ScriptConfig.save()
|
||||
|
||||
async def add_queue(self) -> tuple[uuid.UUID, ConfigBase]:
|
||||
"""添加调度队列"""
|
||||
|
||||
@@ -748,6 +766,13 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
await self.QueueConfig.remove(uuid.UUID(queue_id))
|
||||
|
||||
async def reorder_queue(self, index_list: list[str]) -> None:
|
||||
"""重新排序调度队列"""
|
||||
|
||||
self.logger.info(f"重新排序调度队列:{index_list}")
|
||||
|
||||
await self.QueueConfig.setOrder([uuid.UUID(_) for _ in index_list])
|
||||
|
||||
async def add_time_set(self, queue_id: str) -> tuple[uuid.UUID, ConfigBase]:
|
||||
"""添加时间设置配置"""
|
||||
|
||||
@@ -795,6 +820,17 @@ class AppConfig(GlobalConfig):
|
||||
await queue_config.TimeSet.remove(uid)
|
||||
await self.QueueConfig.save()
|
||||
|
||||
async def reorder_time_set(self, queue_id: str, index_list: list[str]) -> None:
|
||||
"""重新排序时间设置"""
|
||||
|
||||
self.logger.info(f"{queue_id} 重新排序时间设置:{index_list}")
|
||||
|
||||
queue_config = self.QueueConfig[uuid.UUID(queue_id)]
|
||||
|
||||
if isinstance(queue_config, QueueConfig):
|
||||
await queue_config.TimeSet.setOrder([uuid.UUID(_) for _ in index_list])
|
||||
await self.QueueConfig.save()
|
||||
|
||||
async def add_queue_item(self, queue_id: str) -> tuple[uuid.UUID, ConfigBase]:
|
||||
"""添加队列项配置"""
|
||||
|
||||
@@ -844,6 +880,17 @@ class AppConfig(GlobalConfig):
|
||||
await queue_config.QueueItem.remove(uid)
|
||||
await self.QueueConfig.save()
|
||||
|
||||
async def reorder_queue_item(self, queue_id: str, index_list: list[str]) -> None:
|
||||
"""重新排序队列项"""
|
||||
|
||||
self.logger.info(f"{queue_id} 重新排序队列项:{index_list}")
|
||||
|
||||
queue_config = self.QueueConfig[uuid.UUID(queue_id)]
|
||||
|
||||
if isinstance(queue_config, QueueConfig):
|
||||
await queue_config.QueueItem.setOrder([uuid.UUID(_) for _ in index_list])
|
||||
await self.QueueConfig.save()
|
||||
|
||||
async def get_setting(self) -> Dict[str, Any]:
|
||||
"""获取全局设置"""
|
||||
|
||||
|
||||
@@ -56,6 +56,10 @@ class ScriptDeleteIn(BaseModel):
|
||||
scriptId: str = Field(..., description="脚本ID")
|
||||
|
||||
|
||||
class ScriptReorderIn(BaseModel):
|
||||
indexList: List[str] = Field(..., description="脚本ID列表,按新顺序排列")
|
||||
|
||||
|
||||
class UserInBase(BaseModel):
|
||||
scriptId: str = Field(..., description="所属脚本ID")
|
||||
|
||||
@@ -74,6 +78,10 @@ class UserDeleteIn(UserInBase):
|
||||
userId: str = Field(..., description="用户ID")
|
||||
|
||||
|
||||
class UserReorderIn(UserInBase):
|
||||
indexList: List[str] = Field(..., description="用户ID列表,按新顺序排列")
|
||||
|
||||
|
||||
class QueueCreateOut(OutBase):
|
||||
queueId: str = Field(..., description="新创建的队列ID")
|
||||
data: Dict[str, Any] = Field(..., description="队列配置数据")
|
||||
@@ -97,6 +105,10 @@ class QueueDeleteIn(BaseModel):
|
||||
queueId: str = Field(..., description="队列ID")
|
||||
|
||||
|
||||
class QueueReorderIn(BaseModel):
|
||||
indexList: List[str] = Field(..., description="调度队列ID列表,按新顺序排列")
|
||||
|
||||
|
||||
class QueueSetInBase(BaseModel):
|
||||
queueId: str = Field(..., description="所属队列ID")
|
||||
|
||||
@@ -115,6 +127,10 @@ class TimeSetDeleteIn(QueueSetInBase):
|
||||
timeSetId: str = Field(..., description="时间设置ID")
|
||||
|
||||
|
||||
class TimeSetReorderIn(QueueSetInBase):
|
||||
indexList: List[str] = Field(..., description="时间设置ID列表,按新顺序排列")
|
||||
|
||||
|
||||
class QueueItemCreateOut(OutBase):
|
||||
queueItemId: str = Field(..., description="新创建的队列项ID")
|
||||
data: Dict[str, Any] = Field(..., description="队列项配置数据")
|
||||
@@ -129,6 +145,10 @@ class QueueItemDeleteIn(QueueSetInBase):
|
||||
queueItemId: str = Field(..., description="队列项ID")
|
||||
|
||||
|
||||
class QueueItemReorderIn(QueueSetInBase):
|
||||
indexList: List[str] = Field(..., description="队列项ID列表,按新顺序排列")
|
||||
|
||||
|
||||
class SettingGetOut(OutBase):
|
||||
data: Dict[str, Dict[str, Any]] = Field(..., description="全局设置数据")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user