Skip to content

Commit 8420ccf

Browse files
authored
Update the notice model and pagination (#792)
1 parent 1e38e19 commit 8420ccf

File tree

7 files changed

+42
-14
lines changed

7 files changed

+42
-14
lines changed

backend/plugin/notice/api/v1/sys/notice.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
from typing import Annotated
44

5-
from fastapi import APIRouter, Depends, Path
5+
from fastapi import APIRouter, Depends, Path, Query
66

77
from backend.common.pagination import DependsPagination, PageData, paging_data
88
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')]) ->
3030
DependsPagination,
3131
],
3232
)
33-
async def get_notices_paged(db: CurrentSession) -> ResponseSchemaModel[PageData[GetNoticeDetail]]:
34-
notice_select = await notice_service.get_select()
33+
async def get_notices_paged(
34+
db: CurrentSession,
35+
title: Annotated[str | None, Query(description='标题')] = None,
36+
type: Annotated[int | None, Query(description='类型')] = None,
37+
status: Annotated[int | None, Query(description='状态')] = None,
38+
) -> ResponseSchemaModel[PageData[GetNoticeDetail]]:
39+
notice_select = await notice_service.get_select(title=title, type=type, status=status)
3540
page_data = await paging_data(db, notice_select)
3641
return response_base.success(data=page_data)
3742

backend/plugin/notice/crud/crud_notice.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,25 @@ async def get(self, db: AsyncSession, pk: int) -> Notice | None:
2323
"""
2424
return await self.select_model(db, pk)
2525

26-
async def get_list(self) -> Select:
27-
"""获取通知公告列表"""
28-
return await self.select_order('created_time', 'desc')
26+
async def get_list(self, title: str, type: int | None, status: int | None) -> Select:
27+
"""
28+
获取通知公告列表
29+
30+
:param title: 通知公告标题
31+
:param type: 通知公告类型
32+
:param status: 通知公告状态
33+
:return:
34+
"""
35+
filters = {}
36+
37+
if title is not None:
38+
filters['title__like'] = f'%{title}%'
39+
if type is not None:
40+
filters['type'] = type
41+
if status is not None:
42+
filters['status'] = status
43+
44+
return await self.select_order('created_time', 'desc', **filters)
2945

3046
async def get_all(self, db: AsyncSession) -> Sequence[Notice]:
3147
"""

backend/plugin/notice/enums.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
from backend.common.enums import IntEnum
4+
5+
6+
class NoticeType(IntEnum):
7+
"""通知公告类型"""
8+
9+
NOTICE = 0
10+
ANNOUNCEMENT = 1

backend/plugin/notice/model/notice.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ class Notice(Base):
1515
id: Mapped[id_key] = mapped_column(init=False)
1616
title: Mapped[str] = mapped_column(String(50), comment='标题')
1717
type: Mapped[int] = mapped_column(comment='类型(0:通知、1:公告)')
18-
author: Mapped[str] = mapped_column(String(16), comment='作者')
19-
source: Mapped[str] = mapped_column(String(50), comment='信息来源')
2018
status: Mapped[int] = mapped_column(comment='状态(0:隐藏、1:显示)')
2119
content: Mapped[str] = mapped_column(LONGTEXT().with_variant(TEXT, 'postgresql'), comment='内容')

backend/plugin/notice/plugin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[plugin]
22
summary = '通知公告'
3-
version = '0.0.1'
3+
version = '0.0.2'
44
description = '发布系统内部通知、公告'
55
author = 'wu-clan'
66

backend/plugin/notice/schema/notice.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
from backend.common.enums import StatusType
88
from backend.common.schema import SchemaBase
9+
from backend.plugin.notice.enums import NoticeType
910

1011

1112
class NoticeSchemaBase(SchemaBase):
1213
"""通知公告基础模型"""
1314

1415
title: str = Field(description='标题')
15-
type: int = Field(description='类型(0:通知、1:公告)')
16-
author: str = Field(description='作者')
17-
source: str = Field(description='信息来源')
16+
type: NoticeType = Field(description='类型(0:通知、1:公告)')
1817
status: StatusType = Field(description='状态(0:隐藏、1:显示)')
1918
content: str = Field(description='内容')
2019

backend/plugin/notice/service/notice_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ async def get(*, pk: int) -> Notice:
2929
return notice
3030

3131
@staticmethod
32-
async def get_select() -> Select:
32+
async def get_select(title: str | None, type: int | None, status: int | None) -> Select:
3333
"""获取通知公告查询对象"""
34-
return await notice_dao.get_list()
34+
return await notice_dao.get_list(title, type, status)
3535

3636
@staticmethod
3737
async def get_all() -> Sequence[Notice]:

0 commit comments

Comments
 (0)