Add plugin system and notice plugin (#503)

* Update system notice to plugin

* Add plugin model alembic support

* update plugin conf

* add plugin route injection

* update plugin route inject

* fix and optimize plugin router inject
This commit is contained in:
Wu Clan
2025-02-13 21:19:49 +08:00
committed by GitHub
parent 1e0b04006b
commit d9985f9d4d
30 changed files with 274 additions and 62 deletions
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
@@ -0,0 +1,2 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Annotated
from fastapi import APIRouter, Depends, Path, Query
from backend.common.pagination import DependsPagination, PageData, paging_data
from backend.common.response.response_schema import ResponseModel, ResponseSchemaModel, response_base
from backend.common.security.jwt import DependsJwtAuth
from backend.common.security.permission import RequestPermission
from backend.common.security.rbac import DependsRBAC
from backend.database.db import CurrentSession
from backend.plugin.notice.schema.notice import CreateNoticeParam, GetNoticeDetail, UpdateNoticeParam
from backend.plugin.notice.service.notice_service import notice_service
router = APIRouter()
@router.get('/{pk}', summary='获取通知公告详情', dependencies=[DependsJwtAuth])
async def get_notice(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetNoticeDetail]:
notice = await notice_service.get(pk=pk)
return response_base.success(data=notice)
@router.get(
'',
summary='(模糊条件)分页获取所有通知公告',
dependencies=[
DependsJwtAuth,
DependsPagination,
],
)
async def get_pagination_notice(db: CurrentSession) -> ResponseSchemaModel[PageData[GetNoticeDetail]]:
notice_select = await notice_service.get_select()
page_data = await paging_data(db, notice_select)
return response_base.success(data=page_data)
@router.post(
'',
summary='创建通知公告',
dependencies=[
Depends(RequestPermission('sys:notice:add')),
DependsRBAC,
],
)
async def create_notice(obj: CreateNoticeParam) -> ResponseModel:
await notice_service.create(obj=obj)
return response_base.success()
@router.put(
'/{pk}',
summary='更新通知公告',
dependencies=[
Depends(RequestPermission('sys:notice:edit')),
DependsRBAC,
],
)
async def update_notice(pk: Annotated[int, Path(...)], obj: UpdateNoticeParam) -> ResponseModel:
count = await notice_service.update(pk=pk, obj=obj)
if count > 0:
return response_base.success()
return response_base.fail()
@router.delete(
'',
summary='(批量)删除通知公告',
dependencies=[
Depends(RequestPermission('sys:notice:del')),
DependsRBAC,
],
)
async def delete_notice(pk: Annotated[list[int], Query(...)]) -> ResponseModel:
count = await notice_service.delete(pk=pk)
if count > 0:
return response_base.success()
return response_base.fail()