diff --git a/backend/plugin/notice/api/v1/sys/notice.py b/backend/plugin/notice/api/v1/sys/notice.py index 436061a4..8f68cff7 100644 --- a/backend/plugin/notice/api/v1/sys/notice.py +++ b/backend/plugin/notice/api/v1/sys/notice.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from typing import Annotated -from fastapi import APIRouter, Depends, Path +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 @@ -30,8 +30,13 @@ async def get_notice(pk: Annotated[int, Path(description='通知公告 ID')]) -> DependsPagination, ], ) -async def get_notices_paged(db: CurrentSession) -> ResponseSchemaModel[PageData[GetNoticeDetail]]: - notice_select = await notice_service.get_select() +async def get_notices_paged( + db: CurrentSession, + title: Annotated[str | None, Query(description='标题')] = None, + type: Annotated[int | None, Query(description='类型')] = None, + status: Annotated[int | None, Query(description='状态')] = None, +) -> ResponseSchemaModel[PageData[GetNoticeDetail]]: + notice_select = await notice_service.get_select(title=title, type=type, status=status) page_data = await paging_data(db, notice_select) return response_base.success(data=page_data) diff --git a/backend/plugin/notice/crud/crud_notice.py b/backend/plugin/notice/crud/crud_notice.py index 9ef91ec1..4f7e7170 100644 --- a/backend/plugin/notice/crud/crud_notice.py +++ b/backend/plugin/notice/crud/crud_notice.py @@ -23,9 +23,25 @@ class CRUDNotice(CRUDPlus[Notice]): """ return await self.select_model(db, pk) - async def get_list(self) -> Select: - """获取通知公告列表""" - return await self.select_order('created_time', 'desc') + async def get_list(self, title: str, type: int | None, status: int | None) -> Select: + """ + 获取通知公告列表 + + :param title: 通知公告标题 + :param type: 通知公告类型 + :param status: 通知公告状态 + :return: + """ + filters = {} + + if title is not None: + filters['title__like'] = f'%{title}%' + if type is not None: + filters['type'] = type + if status is not None: + filters['status'] = status + + return await self.select_order('created_time', 'desc', **filters) async def get_all(self, db: AsyncSession) -> Sequence[Notice]: """ diff --git a/backend/plugin/notice/enums.py b/backend/plugin/notice/enums.py new file mode 100644 index 00000000..4c70c16c --- /dev/null +++ b/backend/plugin/notice/enums.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +from backend.common.enums import IntEnum + + +class NoticeType(IntEnum): + """通知公告类型""" + + NOTICE = 0 + ANNOUNCEMENT = 1 diff --git a/backend/plugin/notice/model/notice.py b/backend/plugin/notice/model/notice.py index 35519cb0..4f8e9bc4 100644 --- a/backend/plugin/notice/model/notice.py +++ b/backend/plugin/notice/model/notice.py @@ -15,7 +15,5 @@ class Notice(Base): id: Mapped[id_key] = mapped_column(init=False) title: Mapped[str] = mapped_column(String(50), comment='标题') type: Mapped[int] = mapped_column(comment='类型(0:通知、1:公告)') - author: Mapped[str] = mapped_column(String(16), comment='作者') - source: Mapped[str] = mapped_column(String(50), comment='信息来源') status: Mapped[int] = mapped_column(comment='状态(0:隐藏、1:显示)') content: Mapped[str] = mapped_column(LONGTEXT().with_variant(TEXT, 'postgresql'), comment='内容') diff --git a/backend/plugin/notice/plugin.toml b/backend/plugin/notice/plugin.toml index bcd52b08..bf672e1a 100644 --- a/backend/plugin/notice/plugin.toml +++ b/backend/plugin/notice/plugin.toml @@ -1,6 +1,6 @@ [plugin] summary = '通知公告' -version = '0.0.1' +version = '0.0.2' description = '发布系统内部通知、公告' author = 'wu-clan' diff --git a/backend/plugin/notice/schema/notice.py b/backend/plugin/notice/schema/notice.py index 586c64dd..261ed58f 100644 --- a/backend/plugin/notice/schema/notice.py +++ b/backend/plugin/notice/schema/notice.py @@ -6,15 +6,14 @@ from pydantic import ConfigDict, Field from backend.common.enums import StatusType from backend.common.schema import SchemaBase +from backend.plugin.notice.enums import NoticeType class NoticeSchemaBase(SchemaBase): """通知公告基础模型""" title: str = Field(description='标题') - type: int = Field(description='类型(0:通知、1:公告)') - author: str = Field(description='作者') - source: str = Field(description='信息来源') + type: NoticeType = Field(description='类型(0:通知、1:公告)') status: StatusType = Field(description='状态(0:隐藏、1:显示)') content: str = Field(description='内容') diff --git a/backend/plugin/notice/service/notice_service.py b/backend/plugin/notice/service/notice_service.py index fa6c8826..949421b9 100644 --- a/backend/plugin/notice/service/notice_service.py +++ b/backend/plugin/notice/service/notice_service.py @@ -29,9 +29,9 @@ class NoticeService: return notice @staticmethod - async def get_select() -> Select: + async def get_select(title: str | None, type: int | None, status: int | None) -> Select: """获取通知公告查询对象""" - return await notice_dao.get_list() + return await notice_dao.get_list(title, type, status) @staticmethod async def get_all() -> Sequence[Notice]: