49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
|
|
import api, { PageResponse, unwrap } from './request';
|
||
|
|
|
||
|
|
export interface NoticeRow extends Record<string, unknown> {
|
||
|
|
noticeId: number;
|
||
|
|
title: string;
|
||
|
|
content: string;
|
||
|
|
noticeType: string; // GENERAL / IMPORTANT / SYSTEM
|
||
|
|
isPinned: boolean;
|
||
|
|
authorId: number;
|
||
|
|
authorName: string;
|
||
|
|
viewCount: number;
|
||
|
|
publishedAt?: string;
|
||
|
|
expiresAt?: string;
|
||
|
|
status: string;
|
||
|
|
createdAt: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface NoticeSaveReq {
|
||
|
|
title: string;
|
||
|
|
content: string;
|
||
|
|
noticeType: string;
|
||
|
|
isPinned: boolean;
|
||
|
|
publishedAt?: string;
|
||
|
|
expiresAt?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface NoticeSearchParam {
|
||
|
|
title?: string;
|
||
|
|
noticeType?: string;
|
||
|
|
status?: string;
|
||
|
|
pageNum?: number;
|
||
|
|
pageSize?: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const noticeApi = {
|
||
|
|
list: (p?: NoticeSearchParam) =>
|
||
|
|
unwrap<PageResponse<NoticeRow>>(
|
||
|
|
api.get('/api/notices', { params: p }),
|
||
|
|
),
|
||
|
|
detail: (id: number) =>
|
||
|
|
unwrap<NoticeRow>(api.get(`/api/notices/${id}`)),
|
||
|
|
create: (body: NoticeSaveReq) =>
|
||
|
|
unwrap<NoticeRow>(api.post('/api/notices', body)),
|
||
|
|
update: (id: number, body: Partial<NoticeSaveReq>) =>
|
||
|
|
unwrap<NoticeRow>(api.put(`/api/notices/${id}`, body)),
|
||
|
|
delete: (id: number) =>
|
||
|
|
unwrap<void>(api.delete(`/api/notices/${id}`)),
|
||
|
|
};
|